Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent untested Neon APIs #868

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/neon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Neon
on:
push:
branches:
- main
pull_request:

concurrency:
group: neon-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
untested-apis:
name: Untested APIs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4

- name: Find untested Neon APIs
run: ./tool/find-untested-neon-apis.sh
15 changes: 15 additions & 0 deletions packages/nextcloud/test/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ void main() {
expect(response.body.ocs.data.entries.single.rounded, isFalse);
expect(response.body.ocs.data.entries.single.attributes, isEmpty);
});

test('Client login flow V2', () async {
final response = await client.core.clientFlowLoginV2.init();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.login, startsWith('http://localhost'));
expect(response.body.poll.endpoint, startsWith('http://localhost'));
expect(response.body.poll.token, isNotEmpty);

expect(
() => client.core.clientFlowLoginV2.poll(token: response.body.poll.token),
throwsA(predicate<DynamiteApiException>((final e) => e.statusCode == 404)),
);
});
},
retry: retryCount,
timeout: timeout,
Expand Down
58 changes: 58 additions & 0 deletions packages/nextcloud/test/news_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ void main() {
expect(response.body.feeds[0].url, 'http://host.docker.internal:${rssServer.port}/wikipedia.xml');
});

test('Delete feed', () async {
var response = await addWikipediaFeed();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.feeds, hasLength(1));

final deleteResponse = await client.news.deleteFeed(feedId: response.body.feeds.single.id);
expect(deleteResponse.statusCode, 200);
expect(() => deleteResponse.body, isA<void>());
expect(() => deleteResponse.headers, isA<void>());

response = await client.news.listFeeds();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.feeds, hasLength(0));
});

test('Rename feed', () async {
var response = await addWikipediaFeed();
expect(response.statusCode, 200);
Expand Down Expand Up @@ -307,6 +326,45 @@ void main() {
expect(response.body.folders[0].feeds, hasLength(0));
});

test('Delete folder', () async {
var response = await client.news.createFolder(name: 'test1');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.folders, hasLength(1));

final deleteResponse = await client.news.deleteFolder(folderId: response.body.folders.single.id);
expect(deleteResponse.statusCode, 200);
expect(() => deleteResponse.body, isA<void>());
expect(() => deleteResponse.headers, isA<void>());

response = await client.news.listFolders();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.folders, hasLength(0));
});

test('Rename folder', () async {
var response = await client.news.createFolder(name: 'test1');
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.folders, hasLength(1));

final deleteResponse = await client.news.renameFolder(folderId: response.body.folders.single.id, name: 'test2');
expect(deleteResponse.statusCode, 200);
expect(() => deleteResponse.body, isA<void>());
expect(() => deleteResponse.headers, isA<void>());

response = await client.news.listFolders();
expect(response.statusCode, 200);
expect(() => response.headers, isA<void>());

expect(response.body.folders, hasLength(1));
expect(response.body.folders.single.name, 'test2');
});

test('List folders', () async {
var response = await client.news.listFolders();
expect(response.statusCode, 200);
Expand Down
33 changes: 33 additions & 0 deletions tool/find-untested-neon-apis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."

function find_apis() {
path="$1"
grep -r "$path" --include "*\.dart" -e "client\.[^.]*.[^(]*(" -oh | sed "s/^client\.//" | sed "s/($//" | sed "s/Raw$//" | sort | uniq
}

used_apis=("$(find_apis "packages/neon")")
tested_apis=("$(find_apis "packages/nextcloud")")

untested_apis=()

for used_api in ${used_apis[*]}; do
tested=0

for tested_api in ${tested_apis[*]}; do
if [[ "$tested_api" == "$used_api" ]]; then
tested=1
break
fi
done

if [[ "$tested" == 0 ]]; then
untested_apis+=("$used_api")
fi
done

if [[ -n "${untested_apis[*]}" ]]; then
printf "%s\n" "${untested_apis[@]}"
exit 1
fi