forked from eatvio/eatvio_app
feat(post_creation): added multiple image posts creation and validation
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"title": "Complete Test Title",
|
||||
"description_md": "Complete Test Description",
|
||||
"video_url": "https://youtube.com/watch?v=complete",
|
||||
"video_url": "https://rutube.ru/video/12345/",
|
||||
"image_name": null
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
"id": 1,
|
||||
"title": "Updated Title",
|
||||
"description_md": "Updated Description",
|
||||
"video_url": "https://youtube.com/watch?v=updated",
|
||||
"old_image_url": "original_image.jpg",
|
||||
"video_url": "https://vk.com/video-1_1",
|
||||
"existing_media_ids": [2, 1],
|
||||
"image_name": null
|
||||
}
|
||||
|
||||
|
||||
43
test/fixtures/doubles/blog_post_doubles.dart
vendored
43
test/fixtures/doubles/blog_post_doubles.dart
vendored
@@ -4,12 +4,12 @@ import 'package:eatvio_app/features/blog_post_create/services/blog_post_service.
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
|
||||
class FixtureBlogPostRepository extends BlogPostRepository {
|
||||
FixtureBlogPostRepository()
|
||||
: super(blogPostService: _NoopBlogPostService());
|
||||
FixtureBlogPostRepository() : super(blogPostService: _NoopBlogPostService());
|
||||
|
||||
final List<BlogPostCreatePayload> createPayloads = <BlogPostCreatePayload>[];
|
||||
final List<BlogPostUpdatePayload> updatePayloads = <BlogPostUpdatePayload>[];
|
||||
final List<int> deleteCalls = <int>[];
|
||||
final List<({int postId, int mediaId})> deleteMediaCalls = <({int postId, int mediaId})>[];
|
||||
|
||||
Duration createDelay = Duration.zero;
|
||||
Duration updateDelay = Duration.zero;
|
||||
@@ -18,15 +18,21 @@ class FixtureBlogPostRepository extends BlogPostRepository {
|
||||
Object? createError;
|
||||
Object? updateError;
|
||||
Object? deleteError;
|
||||
Object? deleteMediaError;
|
||||
|
||||
@override
|
||||
Future<void> createBlogPost(String? title, String? videoUrl, String? description, XFile? image) async {
|
||||
Future<void> createBlogPost({
|
||||
String? title,
|
||||
String? videoUrl,
|
||||
String? description,
|
||||
List<XFile> images = const [],
|
||||
}) async {
|
||||
createPayloads.add(
|
||||
BlogPostCreatePayload(
|
||||
title: title,
|
||||
description: description,
|
||||
videoUrl: videoUrl,
|
||||
imageName: image?.name,
|
||||
imageName: images.isEmpty ? null : images.first.name,
|
||||
),
|
||||
);
|
||||
if (createDelay > Duration.zero) {
|
||||
@@ -38,15 +44,26 @@ class FixtureBlogPostRepository extends BlogPostRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateBlogPost(int id, String? title, String? videoUrl, String? description, XFile? image, String? oldImageUrl) async {
|
||||
Future<void> updateBlogPost({
|
||||
required int id,
|
||||
String? title,
|
||||
String? videoUrl,
|
||||
String? description,
|
||||
List<int> existingMediaIds = const [],
|
||||
List<XFile> newImages = const [],
|
||||
List<int> mediaIdsToDelete = const [],
|
||||
}) async {
|
||||
for (final mediaId in mediaIdsToDelete) {
|
||||
deleteMediaCalls.add((postId: id, mediaId: mediaId));
|
||||
}
|
||||
updatePayloads.add(
|
||||
BlogPostUpdatePayload(
|
||||
id: id,
|
||||
title: title,
|
||||
description: description,
|
||||
videoUrl: videoUrl,
|
||||
imageName: image?.name,
|
||||
oldImageUrl: oldImageUrl,
|
||||
imageName: newImages.isEmpty ? null : newImages.first.name,
|
||||
existingMediaIds: existingMediaIds,
|
||||
),
|
||||
);
|
||||
if (updateDelay > Duration.zero) {
|
||||
@@ -97,7 +114,7 @@ class BlogPostUpdatePayload {
|
||||
required this.description,
|
||||
required this.videoUrl,
|
||||
required this.imageName,
|
||||
required this.oldImageUrl,
|
||||
required this.existingMediaIds,
|
||||
});
|
||||
|
||||
final int id;
|
||||
@@ -105,15 +122,15 @@ class BlogPostUpdatePayload {
|
||||
final String? description;
|
||||
final String? videoUrl;
|
||||
final String? imageName;
|
||||
final String? oldImageUrl;
|
||||
final List<int> existingMediaIds;
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description_md': description,
|
||||
'video_url': videoUrl,
|
||||
'existing_media_ids': existingMediaIds,
|
||||
'image_name': imageName,
|
||||
'old_image_url': oldImageUrl,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -128,6 +145,11 @@ class _NoopBlogPostService implements BlogPostService {
|
||||
throw UnimplementedError('Fixture overrides repository methods directly.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteBlogPostMedia({required int postId, required int mediaId}) {
|
||||
throw UnimplementedError('Fixture overrides repository methods directly.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateBlogPost({required int id, required FormData formData}) {
|
||||
throw UnimplementedError('Fixture overrides repository methods directly.');
|
||||
@@ -141,4 +163,3 @@ class FeedReloadProbe {
|
||||
loadRequests += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user