diff --git a/packages/nextcloud/test/helper.dart b/packages/nextcloud/test/helper.dart index b2abb531..102bde84 100644 --- a/packages/nextcloud/test/helper.dart +++ b/packages/nextcloud/test/helper.dart @@ -286,14 +286,24 @@ class TestDockerHelper { 'RUN ./occ app:install $appName'; } -Future validateResponse(final ApiInstance api, final Future input) async { +/// Validates that the response matches the schema +/// +/// [cleanResponse] can be used for compatibility reasons, because some APIs are very inconsistent in their responses and don't populate all fields +Future validateResponse( + final ApiInstance api, + final Future input, { + final bool cleanResponse = false, +}) async { final response = await input; if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, await decodeBodyBytes(response)); } if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) { - final body = removeNulls(json.decode(await decodeBodyBytes(response))); + var body = json.decode(await decodeBodyBytes(response)); + if (cleanResponse) { + body = removeNulls(body); + } var output = await api.apiClient.deserializeAsync( json.encode(body), T.toString(), @@ -303,7 +313,10 @@ Future validateResponse(final ApiInstance api, final Future } output = output as T; - final parsedBody = removeNulls(json.decode(json.encode(output))); + var parsedBody = json.decode(json.encode(output)); + if (cleanResponse) { + parsedBody = removeNulls(parsedBody); + } expect(parsedBody, body); return output; diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index b146a2dc..47575747 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -24,6 +24,7 @@ Future main() async { folderId: folderID, ), ), + cleanResponse: true, ))!; Future addNasaFeed() async => (await validateResponse( @@ -31,6 +32,7 @@ Future main() async { client.news.addFeedWithHttpInfo( NewsAddFeed(url: nasaFeedURL), ), + cleanResponse: true, ))!; test('Add feed', () async { @@ -51,6 +53,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listFeedsWithHttpInfo(), + cleanResponse: true, ))!; expect(response.starredCount, 0); expect(response.newestItemId, isNotNull); @@ -64,6 +67,7 @@ Future main() async { var articlesResponse = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(articlesResponse.items.length, greaterThan(0)); @@ -77,6 +81,7 @@ Future main() async { articlesResponse = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(articlesResponse.items, hasLength(0)); }); @@ -85,6 +90,7 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; expect(response.items, hasLength(0)); @@ -93,6 +99,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; expect(response.items.length, greaterThan(0)); expect(response.items[0].body, isNotNull); @@ -112,6 +119,7 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; final wikipediaArticles = response.items.length; expect(wikipediaArticles, greaterThan(0)); @@ -121,6 +129,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; final nasaArticles = response.items.length - wikipediaArticles; expect(nasaArticles, greaterThan(0)); @@ -130,6 +139,7 @@ Future main() async { client.news.listUpdatedArticlesWithHttpInfo( lastModified: response.items[response.items.length - 1 - nasaArticles].lastModified, ), + cleanResponse: true, ))!; expect(response.items, hasLength(nasaArticles)); }); @@ -140,6 +150,7 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; final unreadArticles = response.items.length; expect(unreadArticles, greaterThan(0)); @@ -148,6 +159,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(response.items, hasLength(unreadArticles - 1)); }); @@ -158,12 +170,14 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; final readArticle = response.items[0]; await client.news.markArticleAsRead(readArticle.id!); response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; final unreadArticles = response.items.length; expect(unreadArticles, greaterThan(0)); @@ -172,6 +186,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(response.items, hasLength(unreadArticles + 1)); }); @@ -182,6 +197,7 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 2), + cleanResponse: true, ))!; final starredArticles = response.items.length; expect(starredArticles, 0); @@ -189,11 +205,13 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; await client.news.starArticle(response.items[0].feedId!, response.items[0].guidHash!); response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 2), + cleanResponse: true, ))!; expect(response.items, hasLength(1)); }); @@ -204,6 +222,7 @@ Future main() async { var response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(), + cleanResponse: true, ))!; final item = response.items[0]; @@ -211,6 +230,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 2), + cleanResponse: true, ))!; expect(response.items, hasLength(1)); @@ -218,6 +238,7 @@ Future main() async { response = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 2), + cleanResponse: true, ))!; expect(response.items, hasLength(0)); }); @@ -295,6 +316,7 @@ Future main() async { var articlesResponse = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(articlesResponse.items.length, greaterThan(0)); @@ -308,6 +330,7 @@ Future main() async { articlesResponse = (await validateResponse( client.news, client.news.listArticlesWithHttpInfo(type: 6), + cleanResponse: true, ))!; expect(articlesResponse.items, hasLength(0)); }); diff --git a/packages/nextcloud/test/provisioning_api_test.dart b/packages/nextcloud/test/provisioning_api_test.dart index 3352a633..d0d7522d 100644 --- a/packages/nextcloud/test/provisioning_api_test.dart +++ b/packages/nextcloud/test/provisioning_api_test.dart @@ -17,6 +17,7 @@ Future main() async { final user = (await validateResponse( client.provisioningApi, client.provisioningApi.getCurrentUserWithHttpInfo(), + cleanResponse: true, ))!; expect(user.ocs!.data!.id, 'test'); expect(user.ocs!.data!.getDisplayName(), 'Test'); @@ -28,6 +29,7 @@ Future main() async { final user = (await validateResponse( client.provisioningApi, client.provisioningApi.getUserWithHttpInfo('test'), + cleanResponse: true, ))!; expect(user.ocs!.data!.id, 'test'); expect(user.ocs!.data!.getDisplayName(), 'Test'); diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index 23142d11..ced5cc1c 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/packages/nextcloud/test/user_status_test.dart @@ -18,6 +18,7 @@ Future main() async { final response = (await validateResponse( client.userStatus, client.userStatus.findAllPredefinedStatusesWithHttpInfo(), + cleanResponse: true, ))!; expect(response.ocs!.data, hasLength(5)); @@ -55,6 +56,7 @@ Future main() async { final response = (await validateResponse( client.userStatus, client.userStatus.setStatusWithHttpInfo(UserStatusSetUserStatus(statusType: UserStatusTypeEnum.online)), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); @@ -74,10 +76,12 @@ Future main() async { await validateResponse( client.userStatus, client.userStatus.setStatusWithHttpInfo(UserStatusSetUserStatus(statusType: UserStatusTypeEnum.online)), + cleanResponse: true, ); final response = (await validateResponse( client.userStatus, client.userStatus.getStatusWithHttpInfo(), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); @@ -100,11 +104,13 @@ Future main() async { await validateResponse( client.userStatus, client.userStatus.setStatusWithHttpInfo(UserStatusSetUserStatus(statusType: UserStatusTypeEnum.online)), + cleanResponse: true, ); response = (await validateResponse( client.userStatus, client.userStatus.findAllStatusesWithHttpInfo(), + cleanResponse: true, ))!; expect(response.ocs!.data, hasLength(1)); expect(response.ocs!.data[0].userId, 'test'); @@ -119,11 +125,13 @@ Future main() async { await validateResponse( client.userStatus, client.userStatus.setStatusWithHttpInfo(UserStatusSetUserStatus(statusType: UserStatusTypeEnum.online)), + cleanResponse: true, ); final response = (await validateResponse( client.userStatus, client.userStatus.findStatusWithHttpInfo('test'), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); expect(response.ocs!.data!.message, null); @@ -142,6 +150,7 @@ Future main() async { clearAt: clearAt, ), ), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); @@ -165,6 +174,7 @@ Future main() async { clearAt: clearAt, ), ), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); @@ -188,12 +198,14 @@ Future main() async { clearAt: clearAt, ), ), + cleanResponse: true, ); await client.userStatus.clearMessage(); final response = (await validateResponse( client.userStatus, client.userStatus.getStatusWithHttpInfo(), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test'); expect(response.ocs!.data!.message, null); @@ -210,6 +222,7 @@ Future main() async { final response = (await validateResponse( client.userStatus, client.userStatus.getStatusWithHttpInfo(), + cleanResponse: true, ))!; expect(response.ocs!.data!.userId, 'test');