From ff3fcec2fa1f4e9f0867be38ef8137e6fdb7c842 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 5 Oct 2022 14:18:50 +0200 Subject: [PATCH 1/2] nextcloud,neon: Use proper type for news list type --- .../lib/src/apps/news/blocs/articles.dart | 16 +++++----- packages/nextcloud/lib/src/helpers.dart | 22 ++++++++++--- packages/nextcloud/test/news_test.dart | 32 +++++++++---------- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/packages/neon/lib/src/apps/news/blocs/articles.dart b/packages/neon/lib/src/apps/news/blocs/articles.dart index aff0a0ec..3979ccdf 100644 --- a/packages/neon/lib/src/apps/news/blocs/articles.dart +++ b/packages/neon/lib/src/apps/news/blocs/articles.dart @@ -121,7 +121,7 @@ class NewsArticlesBloc extends $NewsArticlesBloc { // https://github.com/nextcloud/news/blob/master/docs/api/api-v1-2.md#get-items // https://github.com/nextcloud/news/blob/48ee5ce4d135da20079961a62ae37958d6a6b628/lib/Db/ListType.php#L21 - late final int type; + late final NewsListType type; bool? getRead; if (listType != null) { switch (_filterTypeSubject.value) { @@ -136,21 +136,21 @@ class NewsArticlesBloc extends $NewsArticlesBloc { } switch (listType) { case ListType.feed: - type = 0; + type = NewsListType.feed; break; case ListType.folder: - type = 1; + type = NewsListType.folder; break; case null: switch (_filterTypeSubject.value) { case FilterType.starred: - type = 2; + type = NewsListType.starred; break; case FilterType.all: - type = 3; + type = NewsListType.allItems; break; case FilterType.unread: - type = 6; + type = NewsListType.unread; break; } break; @@ -159,9 +159,9 @@ class NewsArticlesBloc extends $NewsArticlesBloc { newsBloc.requestManager .wrapNextcloud, NewsListArticles>( newsBloc.client.id, - 'news-articles-$type-$id-$getRead', + 'news-articles-${type.code}-$id-$getRead', () async => newsBloc.client.news.listArticles( - type: type, + type: type.code, id: id ?? 0, getRead: getRead ?? true ? 1 : 0, ), diff --git a/packages/nextcloud/lib/src/helpers.dart b/packages/nextcloud/lib/src/helpers.dart index d6634d85..cdd6d57b 100644 --- a/packages/nextcloud/lib/src/helpers.dart +++ b/packages/nextcloud/lib/src/helpers.dart @@ -1,23 +1,20 @@ +// ignore_for_file: public_member_api_docs + part of '../nextcloud.dart'; -// ignore: public_member_api_docs extension HttpClientResponseBody on HttpClientResponse { - // ignore: public_member_api_docs Future get bodyBytes async => Uint8List.fromList((await toList()).reduce((final value, final element) => [...value, ...element])); - // ignore: public_member_api_docs Future get body async => utf8.decode(await bodyBytes); } -// ignore: public_member_api_docs extension UserDetailsDisplayName on ProvisioningApiUserDetails { /// This is used to work around an API change that wasn't made for every endpoint /// See https://github.com/nextcloud/server/commit/5086335643b6181284ee50f57b95525002842992 String? getDisplayName() => displayname ?? displayName; } -// ignore: public_member_api_docs extension NextcloudNotificationsPushProxy on NotificationsClient { /// Registers a device at the push proxy server Future registerDeviceAtPushProxy( @@ -67,3 +64,18 @@ NotificationsPushNotificationDecryptedSubject decryptPushNotificationSubject( NotificationsPushNotificationDecryptedSubject.fromJson( json.decode(privateKey.decrypt(subject)) as Map, ); + +/// See https://github.com/nextcloud/news/blob/4a107b3d53c4fe651ac704251b99e04a53cd587f/lib/Db/ListType.php +enum NewsListType { + feed(0), + folder(1), + starred(2), + allItems(3), + shared(4), + explore(5), + unread(6); + + const NewsListType(this.code); + + final int code; +} diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index f8a65e52..7c153fe5 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -50,7 +50,7 @@ Future main() async { test('Mark feed as read', () async { final feedsResponse = await addWikipediaFeed(); - var articlesResponse = await client.news.listArticles(type: 6); + var articlesResponse = await client.news.listArticles(type: NewsListType.unread.code); expect(articlesResponse.items!.length, greaterThan(0)); await client.news.markFeedAsRead( @@ -58,7 +58,7 @@ Future main() async { newestItemId: feedsResponse.newestItemId!, ); - articlesResponse = await client.news.listArticles(type: 6); + articlesResponse = await client.news.listArticles(type: NewsListType.unread.code); expect(articlesResponse.items, hasLength(0)); }); @@ -103,36 +103,36 @@ Future main() async { test('Mark article as read', () async { await addWikipediaFeed(); - var response = await client.news.listArticles(type: 6); + var response = await client.news.listArticles(type: NewsListType.unread.code); final unreadArticles = response.items!.length; expect(unreadArticles, greaterThan(0)); await client.news.markArticleAsRead( itemId: response.items![0].id!, ); - response = await client.news.listArticles(type: 6); + response = await client.news.listArticles(type: NewsListType.unread.code); expect(response.items, hasLength(unreadArticles - 1)); }); test('Mark article as unread', () async { await addWikipediaFeed(); - var response = await client.news.listArticles(type: 6); + var response = await client.news.listArticles(type: NewsListType.unread.code); final readArticle = response.items![0]; await client.news.markArticleAsRead(itemId: readArticle.id!); - response = await client.news.listArticles(type: 6); + response = await client.news.listArticles(type: NewsListType.unread.code); final unreadArticles = response.items!.length; expect(unreadArticles, greaterThan(0)); await client.news.markArticleAsUnread(itemId: readArticle.id!); - response = await client.news.listArticles(type: 6); + response = await client.news.listArticles(type: NewsListType.unread.code); expect(response.items, hasLength(unreadArticles + 1)); }); test('Star article', () async { await addWikipediaFeed(); - var response = await client.news.listArticles(type: 2); + var response = await client.news.listArticles(type: NewsListType.starred.code); final starredArticles = response.items!.length; expect(starredArticles, 0); @@ -140,7 +140,7 @@ Future main() async { await client.news.starArticle( itemId: response.items![0].id!, ); - response = await client.news.listArticles(type: 2); + response = await client.news.listArticles(type: NewsListType.starred.code); expect(response.items, hasLength(1)); }); @@ -153,13 +153,13 @@ Future main() async { await client.news.starArticle( itemId: item.id!, ); - response = await client.news.listArticles(type: 2); + response = await client.news.listArticles(type: NewsListType.starred.code); expect(response.items, hasLength(1)); await client.news.unstarArticle( itemId: item.id!, ); - response = await client.news.listArticles(type: 2); + response = await client.news.listArticles(type: NewsListType.starred.code); expect(response.items, hasLength(0)); }); @@ -167,17 +167,17 @@ Future main() async { var response = await client.news.listFolders(); expect(response.folders, hasLength(0)); - response = await client.news.createFolder(name: 'test'); + response = await client.news.createFolder(name: 'test1'); expect(response.folders, hasLength(1)); expect(response.folders![0].id, 1); - expect(response.folders![0].name, 'test'); + expect(response.folders![0].name, 'test1'); expect(response.folders![0].opened, true); expect(response.folders![0].feeds, hasLength(0)); response = await client.news.listFolders(); expect(response.folders, hasLength(1)); expect(response.folders![0].id, 1); - expect(response.folders![0].name, 'test'); + expect(response.folders![0].name, 'test1'); expect(response.folders![0].opened, true); expect(response.folders![0].feeds, hasLength(0)); }); @@ -215,7 +215,7 @@ Future main() async { final foldersResponse = await client.news.createFolder(name: 'test1'); final feedsResponse = await addWikipediaFeed(1); - var articlesResponse = await client.news.listArticles(type: 6); + var articlesResponse = await client.news.listArticles(type: NewsListType.unread.code); expect(articlesResponse.items!.length, greaterThan(0)); await client.news.markFolderAsRead( @@ -223,7 +223,7 @@ Future main() async { newestItemId: feedsResponse.newestItemId!, ); - articlesResponse = await client.news.listArticles(type: 6); + articlesResponse = await client.news.listArticles(type: NewsListType.unread.code); expect(articlesResponse.items, hasLength(0)); }); }); From 5066f94ef0cd0bd15dcc0be78e8407796f3a57d9 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 5 Oct 2022 14:19:21 +0200 Subject: [PATCH 2/2] specs,nextcloud: Fix wrong http methods in news and add tests for them --- .../nextcloud/lib/src/nextcloud.openapi.dart | 4 +-- .../nextcloud/lib/src/nextcloud.openapi.json | 4 +-- packages/nextcloud/test/news_test.dart | 29 +++++++++++++++++++ specs/news.json | 4 +-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 61601a8c..459ac5ce 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -1870,7 +1870,7 @@ class NewsClient { queryParameters['folderId'] = folderId.toString(); } final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, @@ -1892,7 +1892,7 @@ class NewsClient { path = path.replaceAll('{feedId}', Uri.encodeQueryComponent(feedId.toString())); queryParameters['feedTitle'] = feedTitle.toString(); final response = await rootClient.doRequest( - 'put', + 'post', Uri(path: path, queryParameters: queryParameters).toString(), headers, body, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index fd44c979..d772ecdd 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -2064,7 +2064,7 @@ } } ], - "put": { + "post": { "operationId": "move-feed", "tags": [ "news" @@ -2097,7 +2097,7 @@ } } ], - "put": { + "post": { "operationId": "rename-feed", "tags": [ "news" diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index 7c153fe5..6e26efc0 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -47,6 +47,35 @@ Future main() async { expect(response.feeds![0].url, wikipediaFeedURL); }); + test('Rename feed', () async { + var response = await addWikipediaFeed(); + expect(response.feeds![0].title, 'Wikipedia featured articles feed'); + + await client.news.renameFeed( + feedId: 1, + feedTitle: 'test1', + ); + + response = await client.news.listFeeds(); + expect(response.feeds![0].title, 'test1'); + }); + + test('Move feed to folder', () async { + await client.news.createFolder(name: 'test1'); + await addWikipediaFeed(); + await client.news.moveFeed( + feedId: 1, + folderId: 1, + ); + + final response = await client.news.listFolders(); + expect(response.folders, hasLength(1)); + expect(response.folders![0].id, 1); + expect(response.folders![0].name, 'test1'); + expect(response.folders![0].opened, true); + expect(response.folders![0].feeds, hasLength(0)); + }); + test('Mark feed as read', () async { final feedsResponse = await addWikipediaFeed(); diff --git a/specs/news.json b/specs/news.json index 95eaca9f..65c912af 100644 --- a/specs/news.json +++ b/specs/news.json @@ -481,7 +481,7 @@ } } ], - "put": { + "post": { "operationId": "move-feed", "tags": [ "news" @@ -514,7 +514,7 @@ } } ], - "put": { + "post": { "operationId": "rename-feed", "tags": [ "news"