From 8cecf0933d7a0905fb5d69a7356f900cbb19cc08 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:39:29 +0200 Subject: [PATCH] feat(lib): update video class member nullability --- lib/src/types/video.dart | 53 ++++++++++++++-------------- lib/src/types/video.g.dart | 43 +++++++++------------- test/video_uploader_mobile_test.dart | 33 +++++++++++++---- 3 files changed, 69 insertions(+), 60 deletions(-) diff --git a/lib/src/types/video.dart b/lib/src/types/video.dart index cd9b65a..6d17716 100644 --- a/lib/src/types/video.dart +++ b/lib/src/types/video.dart @@ -41,19 +41,19 @@ class Video { final String videoId; /// When a video was created, presented in ISO-8601 format. - final DateTime? createdAt; + final DateTime createdAt; /// The title of the video content. - final String? title; + final String title; /// The description for the video content. - final String? description; + final String description; /// The date and time the API created the video. Date and time are provided using ISO-8601 UTC format. - final String? publishedAt; + final String publishedAt; /// The date and time the video was updated. Date and time are provided using ISO-8601 UTC format. - final DateTime? updatedAt; + final DateTime updatedAt; /// The date and time the video was discarded. final DateTime? discardedAt; @@ -62,7 +62,7 @@ class Video { final DateTime? deletesAt; /// Returns `true` for videos you discarded. - final bool? discarded; + final bool discarded; /// Returns the language of a video in [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. @_JsonLocaleConverter() @@ -72,50 +72,49 @@ class Video { final LanguageOrigin? languageOrigin; /// One array of tags (each tag is a string) in order to categorize a video. Tags may include spaces. - final List? tags; + final List tags; /// Metadata you can use to categorise and filter videos. Metadata is a list of dictionaries, where each dictionary represents a key value pair for categorising a video. [Dynamic Metadata](https://api.video/blog/endpoints/dynamic-metadata) allows you to define a key that allows any value pair. - final List? metadata; + final List metadata; /// The source information about the video. - final VideoSource? source; + final VideoSource source; /// The details about the video object that you can use to work with the video object. - final VideoAssets? assets; + final VideoAssets assets; /// The id of the player that will be applied on the video. final String? playerId; /// Defines if the content is publicly reachable or if a unique token is needed for each play session. Default is true. Tutorials on [private videos](https://api.video/blog/endpoints/private-videos). - @JsonKey(name: '_public') - final bool? public; + final bool public; /// Defines if video is panoramic. - final bool? panoramic; + final bool panoramic; /// This lets you know whether mp4 is supported. If enabled, an mp4 URL will be provided in the response for the video. - final bool? mp4Support; + final bool mp4Support; /// Creates a [Video]. const Video(this.videoId, - {this.createdAt, - this.title, - this.description, - this.publishedAt, - this.updatedAt, + {required this.createdAt, + required this.title, + required this.description, + required this.publishedAt, + required this.updatedAt, this.discardedAt, this.deletesAt, - this.discarded, + required this.discarded, this.language, this.languageOrigin, - this.tags, - this.metadata, - this.source, - this.assets, + required this.tags, + required this.metadata, + required this.source, + required this.assets, this.playerId, - this.public, - this.panoramic, - this.mp4Support}); + required this.public, + required this.panoramic, + required this.mp4Support}); /// Creates a [Video] from a [json] map. factory Video.fromJson(Map json) => _$VideoFromJson(json); diff --git a/lib/src/types/video.g.dart b/lib/src/types/video.g.dart index 7ed1d64..7c2ebe6 100644 --- a/lib/src/types/video.g.dart +++ b/lib/src/types/video.g.dart @@ -7,50 +7,41 @@ part of 'video.dart'; // ************************************************************************** Video _$VideoFromJson(Map json) => Video( - json['videoId'] as String, - createdAt: json['createdAt'] == null - ? null - : DateTime.parse(json['createdAt'] as String), - title: json['title'] as String?, - description: json['description'] as String?, - publishedAt: json['publishedAt'] as String?, - updatedAt: json['updatedAt'] == null - ? null - : DateTime.parse(json['updatedAt'] as String), + json['videoId'] as String, createdAt: DateTime.parse(json['createdAt'] as String), + title: json['title'] as String, + description: json['description'] as String, + publishedAt: json['publishedAt'] as String, + updatedAt: DateTime.parse(json['updatedAt'] as String), discardedAt: json['discardedAt'] == null ? null : DateTime.parse(json['discardedAt'] as String), deletesAt: json['deletesAt'] == null ? null : DateTime.parse(json['deletesAt'] as String), - discarded: json['discarded'] as bool?, + discarded: json['discarded'] as bool, language: _$JsonConverterFromJson( json['language'], const _JsonLocaleConverter().fromJson), languageOrigin: $enumDecodeNullable(_$LanguageOriginEnumMap, json['languageOrigin']), - tags: (json['tags'] as List?)?.map((e) => e as String).toList(), - metadata: (json['metadata'] as List?) - ?.map((e) => Metadata.fromJson(e as Map)) + tags: (json['tags'] as List).map((e) => e as String).toList(), + metadata: (json['metadata'] as List) + .map((e) => Metadata.fromJson(e as Map)) .toList(), - source: json['source'] == null - ? null - : VideoSource.fromJson(json['source'] as Map), - assets: json['assets'] == null - ? null - : VideoAssets.fromJson(json['assets'] as Map), + source: VideoSource.fromJson(json['source'] as Map), + assets: VideoAssets.fromJson(json['assets'] as Map), playerId: json['playerId'] as String?, - public: json['_public'] as bool?, - panoramic: json['panoramic'] as bool?, - mp4Support: json['mp4Support'] as bool?, + public: json['public'] as bool, + panoramic: json['panoramic'] as bool, + mp4Support: json['mp4Support'] as bool, ); Map _$VideoToJson(Video instance) => { 'videoId': instance.videoId, - 'createdAt': instance.createdAt?.toIso8601String(), + 'createdAt': instance.createdAt.toIso8601String(), 'title': instance.title, 'description': instance.description, 'publishedAt': instance.publishedAt, - 'updatedAt': instance.updatedAt?.toIso8601String(), + 'updatedAt': instance.updatedAt.toIso8601String(), 'discardedAt': instance.discardedAt?.toIso8601String(), 'deletesAt': instance.deletesAt?.toIso8601String(), 'discarded': instance.discarded, @@ -62,7 +53,7 @@ Map _$VideoToJson(Video instance) => { 'source': instance.source, 'assets': instance.assets, 'playerId': instance.playerId, - '_public': instance.public, + 'public': instance.public, 'panoramic': instance.panoramic, 'mp4Support': instance.mp4Support, }; diff --git a/test/video_uploader_mobile_test.dart b/test/video_uploader_mobile_test.dart index 903f0d9..86956cb 100644 --- a/test/video_uploader_mobile_test.dart +++ b/test/video_uploader_mobile_test.dart @@ -12,6 +12,24 @@ void main() { const MethodChannel channel = const MethodChannel('video.api.uploader'); ApiVideoUploaderPlatform.instance = ApiVideoMobileUploaderPlugin(); + Video _createDummyVideo(String videoId) { + return Video(videoId, + createdAt: DateTime.now(), + title: "Title", + description: "Description", + publishedAt: DateTime.now(), + updatedAt: DateTime.now(), + discarded: false, + tags: [], + metadata: [], + source: VideoSource(), + assets: VideoAssets(), + public: false, + panoramic: false, + mp4Support: false, + ); + } + test('setEnvironment', () async { final environment = Environment.sandbox; TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger @@ -57,7 +75,7 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["videoId"], videoId); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -78,7 +96,7 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["token"], token); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -96,7 +114,7 @@ void main() { return null; } else if (methodCall.method == "uploadWithUploadToken") { expect(null, isNot(methodCall.arguments["uploadId"])); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -131,7 +149,7 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["sessionId"], sessionId); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -148,7 +166,7 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["sessionId"], sessionId); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -184,7 +202,7 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["sessionId"], sessionId); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } @@ -201,11 +219,12 @@ void main() { expect(null, isNot(methodCall.arguments["uploadId"])); expect(methodCall.arguments["sessionId"], sessionId); expect(methodCall.arguments["filePath"], filePath); - return jsonEncode(Video(videoId).toJson()); + return jsonEncode(_createDummyVideo(videoId).toJson()); } else { fail("Method not expected: ${methodCall.method}"); } }); expect((await session.uploadLastPart(filePath)).videoId, videoId); }); + }