From 25bfc7846db5e7a6cd9f04f0cc6d1889bfbb9f0d Mon Sep 17 00:00:00 2001 From: Brett Morgan Date: Sat, 7 Nov 2020 12:23:48 +1100 Subject: [PATCH] Re-generate built_value classes (#587) --- .../lib/src/model/search.g.dart | 2 +- .../lib/src/unsplash/api_error.g.dart | 2 +- .../lib/src/unsplash/photo.g.dart | 4 +- .../unsplash/search_photos_response.g.dart | 2 +- .../desktop_photo_search/macos/Podfile.lock | 2 +- .../test/unsplash_test.dart | 193 +++++++++++++++++- 6 files changed, 197 insertions(+), 8 deletions(-) diff --git a/experimental/desktop_photo_search/lib/src/model/search.g.dart b/experimental/desktop_photo_search/lib/src/model/search.g.dart index 426b45307..43b2cd694 100644 --- a/experimental/desktop_photo_search/lib/src/model/search.g.dart +++ b/experimental/desktop_photo_search/lib/src/model/search.g.dart @@ -53,7 +53,7 @@ class _$SearchSerializer implements StructuredSerializer { result.results.replace(serializers.deserialize(value, specifiedType: const FullType(BuiltList, const [const FullType(Photo)])) - as BuiltList); + as BuiltList); break; } } diff --git a/experimental/desktop_photo_search/lib/src/unsplash/api_error.g.dart b/experimental/desktop_photo_search/lib/src/unsplash/api_error.g.dart index 186db17b9..fa4d0bb80 100644 --- a/experimental/desktop_photo_search/lib/src/unsplash/api_error.g.dart +++ b/experimental/desktop_photo_search/lib/src/unsplash/api_error.g.dart @@ -46,7 +46,7 @@ class _$ApiErrorSerializer implements StructuredSerializer { result.errors.replace(serializers.deserialize(value, specifiedType: const FullType(BuiltList, const [const FullType(String)])) - as BuiltList); + as BuiltList); break; } } diff --git a/experimental/desktop_photo_search/lib/src/unsplash/photo.g.dart b/experimental/desktop_photo_search/lib/src/unsplash/photo.g.dart index 3fc098dbb..277a171ce 100644 --- a/experimental/desktop_photo_search/lib/src/unsplash/photo.g.dart +++ b/experimental/desktop_photo_search/lib/src/unsplash/photo.g.dart @@ -189,13 +189,13 @@ class _$PhotoSerializer implements StructuredSerializer { result.tags.replace(serializers.deserialize(value, specifiedType: const FullType(BuiltList, const [const FullType(Tags)])) - as BuiltList); + as BuiltList); break; case 'current_user_collections': result.currentUserCollections.replace(serializers.deserialize(value, specifiedType: const FullType(BuiltList, const [ const FullType(CurrentUserCollections) - ])) as BuiltList); + ])) as BuiltList); break; case 'urls': result.urls.replace(serializers.deserialize(value, diff --git a/experimental/desktop_photo_search/lib/src/unsplash/search_photos_response.g.dart b/experimental/desktop_photo_search/lib/src/unsplash/search_photos_response.g.dart index 7878e6697..d1f968631 100644 --- a/experimental/desktop_photo_search/lib/src/unsplash/search_photos_response.g.dart +++ b/experimental/desktop_photo_search/lib/src/unsplash/search_photos_response.g.dart @@ -72,7 +72,7 @@ class _$SearchPhotosResponseSerializer result.results.replace(serializers.deserialize(value, specifiedType: const FullType(BuiltList, const [const FullType(Photo)])) - as BuiltList); + as BuiltList); break; } } diff --git a/experimental/desktop_photo_search/macos/Podfile.lock b/experimental/desktop_photo_search/macos/Podfile.lock index 6530ef94a..7b860e276 100644 --- a/experimental/desktop_photo_search/macos/Podfile.lock +++ b/experimental/desktop_photo_search/macos/Podfile.lock @@ -36,4 +36,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7 -COCOAPODS: 1.9.1 +COCOAPODS: 1.9.3 diff --git a/experimental/desktop_photo_search/test/unsplash_test.dart b/experimental/desktop_photo_search/test/unsplash_test.dart index c4102b02a..f9b056e3e 100644 --- a/experimental/desktop_photo_search/test/unsplash_test.dart +++ b/experimental/desktop_photo_search/test/unsplash_test.dart @@ -339,9 +339,198 @@ void main() { await unsplashClient.searchPhotos(query: 'red'); fail('UnsplashException should have been thrown'); } on UnsplashException catch (e) { - expect(e.toString(), - 'UnsplashException: Invalid JSON received'); + expect(e.toString(), 'UnsplashException: Invalid JSON received'); } }); }); + + test('handles utf8 content in JSON', () async { + const searchPhotosResponseBody = ''' +{ + "total": 22395, + "total_pages": 2240, + "results": [ + { + "id": "E4u_Zo9PET8", + "created_at": "2019-12-29T13:45:28-05:00", + "updated_at": "2020-11-05T17:12:18-05:00", + "promoted_at": null, + "width": 2598, + "height": 4618, + "color": "#A53E40", + "blur_hash": "LlO{8lL#XSbu*Jtla0jZOrb^ozjF", + "description": null, + "alt_description": "red apparel", + "urls": { + "raw": "https://images.unsplash.com/photo-1577645113639-32537a4a938b?ixlib=rb-1.2.1\u0026ixid=eyJhcHBfaWQiOjM5NTU5fQ", + "full": "https://images.unsplash.com/photo-1577645113639-32537a4a938b?ixlib=rb-1.2.1\u0026q=85\u0026fm=jpg\u0026crop=entropy\u0026cs=srgb\u0026ixid=eyJhcHBfaWQiOjM5NTU5fQ", + "regular": "https://images.unsplash.com/photo-1577645113639-32537a4a938b?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=1080\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjM5NTU5fQ", + "small": "https://images.unsplash.com/photo-1577645113639-32537a4a938b?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=400\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjM5NTU5fQ", + "thumb": "https://images.unsplash.com/photo-1577645113639-32537a4a938b?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=200\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjM5NTU5fQ" + }, + "links": { + "self": "https://api.unsplash.com/photos/E4u_Zo9PET8", + "html": "https://unsplash.com/photos/E4u_Zo9PET8", + "download": "https://unsplash.com/photos/E4u_Zo9PET8/download", + "download_location": "https://api.unsplash.com/photos/E4u_Zo9PET8/download" + }, + "categories": [], + "likes": 132, + "liked_by_user": false, + "current_user_collections": [], + "sponsorship": null, + "user": { + "id": "_2nQcPrbyuE", + "updated_at": "2020-11-06T01:37:51-05:00", + "username": "svalenas", + "name": "Sergiu Vălenaș", + "first_name": "Sergiu", + "last_name": "Vălenaș", + "twitter_username": null, + "portfolio_url": null, + "bio": "Gifted psychologist and enthusiast photographer", + "location": "Cluj-Napoca, Romania", + "links": { + "self": "https://api.unsplash.com/users/svalenas", + "html": "https://unsplash.com/@svalenas", + "photos": "https://api.unsplash.com/users/svalenas/photos", + "likes": "https://api.unsplash.com/users/svalenas/likes", + "portfolio": "https://api.unsplash.com/users/svalenas/portfolio", + "following": "https://api.unsplash.com/users/svalenas/following", + "followers": "https://api.unsplash.com/users/svalenas/followers" + }, + "profile_image": { + "small": "https://images.unsplash.com/profile-1597067601066-d43176d68553image?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=32\u0026w=32", + "medium": "https://images.unsplash.com/profile-1597067601066-d43176d68553image?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=64\u0026w=64", + "large": "https://images.unsplash.com/profile-1597067601066-d43176d68553image?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=128\u0026w=128" + }, + "instagram_username": "svalenas", + "total_collections": 0, + "total_likes": 413, + "total_photos": 129, + "accepted_tos": true + }, + "tags": [ + { + "type": "landing_page", + "title": "red", + "source": { + "ancestry": { + "type": { + "slug": "wallpapers", + "pretty_slug": "HD Wallpapers" + }, + "category": { + "slug": "colors", + "pretty_slug": "Color" + }, + "subcategory": { + "slug": "red", + "pretty_slug": "Red" + } + }, + "title": "HD Red Wallpapers", + "subtitle": "Download Free Red Wallpapers", + "description": "Choose from a curated selection of red wallpapers for your mobile and desktop screens. Always free on Unsplash.", + "meta_title": "Red Wallpapers: Free HD Download [500+ HQ] | Unsplash", + "meta_description": "Choose from hundreds of free red wallpapers. Download HD wallpapers for free on Unsplash.", + "cover_photo": { + "id": "HyBXy5PHQR8", + "created_at": "2018-02-17T13:44:58-05:00", + "updated_at": "2020-10-21T01:07:42-04:00", + "promoted_at": null, + "width": 3024, + "height": 4032, + "color": "#C51918", + "blur_hash": "L9Bmx_o1o1Jl|cwxWpWpN]\$5N]sU", + "description": null, + "alt_description": "red textile", + "urls": { + "raw": "https://images.unsplash.com/photo-1518893063132-36e46dbe2428?ixlib=rb-1.2.1", + "full": "https://images.unsplash.com/photo-1518893063132-36e46dbe2428?ixlib=rb-1.2.1\u0026q=85\u0026fm=jpg\u0026crop=entropy\u0026cs=srgb", + "regular": "https://images.unsplash.com/photo-1518893063132-36e46dbe2428?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=1080\u0026fit=max", + "small": "https://images.unsplash.com/photo-1518893063132-36e46dbe2428?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=400\u0026fit=max", + "thumb": "https://images.unsplash.com/photo-1518893063132-36e46dbe2428?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=200\u0026fit=max" + }, + "links": { + "self": "https://api.unsplash.com/photos/HyBXy5PHQR8", + "html": "https://unsplash.com/photos/HyBXy5PHQR8", + "download": "https://unsplash.com/photos/HyBXy5PHQR8/download", + "download_location": "https://api.unsplash.com/photos/HyBXy5PHQR8/download" + }, + "categories": [], + "likes": 1243, + "liked_by_user": false, + "current_user_collections": [], + "sponsorship": null, + "user": { + "id": "6nkkrwW9M-s", + "updated_at": "2020-10-22T20:44:54-04:00", + "username": "montylov", + "name": "MontyLov", + "first_name": "MontyLov", + "last_name": null, + "twitter_username": "MontyLov", + "portfolio_url": "http://montylov.com", + "bio": "Stay humble and innovate.", + "location": null, + "links": { + "self": "https://api.unsplash.com/users/montylov", + "html": "https://unsplash.com/@montylov", + "photos": "https://api.unsplash.com/users/montylov/photos", + "likes": "https://api.unsplash.com/users/montylov/likes", + "portfolio": "https://api.unsplash.com/users/montylov/portfolio", + "following": "https://api.unsplash.com/users/montylov/following", + "followers": "https://api.unsplash.com/users/montylov/followers" + }, + "profile_image": { + "small": "https://images.unsplash.com/profile-1588478301600-b5e5203a574aimage?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=32\u0026w=32", + "medium": "https://images.unsplash.com/profile-1588478301600-b5e5203a574aimage?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=64\u0026w=64", + "large": "https://images.unsplash.com/profile-1588478301600-b5e5203a574aimage?ixlib=rb-1.2.1\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=128\u0026w=128" + }, + "instagram_username": "montylov", + "total_collections": 1, + "total_likes": 0, + "total_photos": 79, + "accepted_tos": false + } + } + } + }, + { + "type": "search", + "title": "rug" + }, + { + "type": "search", + "title": "plant" + } + ] + } + ] +} + '''; + + final httpClient = MockClient((req) async { + return Response( + searchPhotosResponseBody, + 200, + request: req, + headers: {'content-type': 'application/json; charset=utf-8'}, + ); + }); + + final unsplashClient = Unsplash( + accessKey: 'not-an-access-key', + httpClient: httpClient, + ); + + final response = await unsplashClient.searchPhotos(query: 'red'); + + expect(response.total, 22395); + expect(response.totalPages, 2240); + expect(response.results[0].id, 'E4u_Zo9PET8'); + expect(response.results[0].user.id, '_2nQcPrbyuE'); + expect(response.results[0].user.name, 'Sergiu Vălenaș'); + }); }