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

feat(nextcloud_test): Add fixture recording and validation #1273

Merged
merged 2 commits into from
Dec 12, 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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.regexp]
insert_final_newline = false
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"packages/dynamite/dynamite_petstore_example/lib",
"packages/file_icons/lib/src/data.dart",
"packages/neon_lints/lib",
"packages/nextcloud/test/fixtures",
"packages/nextcloud_test/docker/static"
],
"dictionaries": [
Expand Down
13 changes: 9 additions & 4 deletions packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:meta/meta.dart';
import 'package:universal_io/io.dart';
import 'package:xml/xml.dart';
import 'package:xml/xml_events.dart';
Expand All @@ -11,9 +12,13 @@ import 'package:xml/xml_events.dart';
/// Usually a `Stream<Uint8List>`.
typedef BytesStream = Stream<List<int>>;

final _jsonBytesConverter = utf8.decoder.fuse(json.decoder);
/// Converter for UTF-8 encoded bytes to JSON.
@visibleForTesting
final jsonBytesConverter = utf8.decoder.fuse(json.decoder);

final _xmlBytesConverter =
/// Converter for UTF-8 encoded bytes to XML.
@visibleForTesting
final xmlBytesConverter =
utf8.decoder.fuse(XmlEventDecoder()).fuse(const XmlNormalizeEvents()).fuse(const XmlNodeDecoder());

/// Extension on byte streams that enable efficient transformations.
Expand All @@ -34,13 +39,13 @@ extension BytesStreamExtension on BytesStream {
Future<String> get string => transform(utf8.decoder).join();

/// Converts the stream into a JSON using the [utf8] encoding.
Future<Object?> get json => transform(_jsonBytesConverter).first;
Future<Object?> get json => transform(jsonBytesConverter).first;

/// Converts the stream into XML using the [utf8] encoding.
///
/// Returns the root element of this stream.
Future<XmlElement> get xml async {
final element = await transform(_xmlBytesConverter)
final element = await transform(xmlBytesConverter)
.expand((final events) => events)
.firstWhere((final element) => element is XmlElement);

Expand Down
14 changes: 14 additions & 0 deletions packages/nextcloud/test/fixtures/core/app_password/delete.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DELETE http://localhost/ocs/v2\.php/core/apppassword
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Bearer mock
ocs-apirequest: true
DELETE http://localhost/ocs/v2\.php/core/apppassword
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Bearer mock
ocs-apirequest: true
7 changes: 7 additions & 0 deletions packages/nextcloud/test/fixtures/core/autocomplete/get.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/core/autocomplete/get\?search&itemType=call&itemId=new&shareTypes%5B%5D=1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
6 changes: 6 additions & 0 deletions packages/nextcloud/test/fixtures/core/avatar/get.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET http://localhost/index\.php/avatar/admin/32
user-agent: Dart/3\.2 \(dart:io\)
accept: \*/\*
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
6 changes: 6 additions & 0 deletions packages/nextcloud/test/fixtures/core/avatar/get_dark.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET http://localhost/index\.php/avatar/admin/32/dark
user-agent: Dart/3\.2 \(dart:io\)
accept: \*/\*
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST http://localhost/index\.php/login/v2
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Bearer mock
POST http://localhost/index\.php/login/v2/poll\?token=[a-zA-Z0-9]{128}
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Bearer mock
5 changes: 5 additions & 0 deletions packages/nextcloud/test/fixtures/core/get_status.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GET http://localhost/status\.php
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/cloud/capabilities
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GET http://localhost/status\.php
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/core/navigation/apps
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/cloud/capabilities
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
6 changes: 6 additions & 0 deletions packages/nextcloud/test/fixtures/core/preview/get.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET http://localhost/index\.php/core/preview\.png\?file=Nextcloud\.png
user-agent: Dart/3\.2 \(dart:io\)
accept: \*/\*
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/search/providers
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/search/providers/settings/search\?term=Personal\+info
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/apps/dashboard/api/v1/widget-items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/apps/dashboard/api/v2/widget-items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
7 changes: 7 additions & 0 deletions packages/nextcloud/test/fixtures/dashboard/get_widgets.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost/ocs/v2\.php/apps/dashboard/api/v1/widgets
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Bearer mock
ocs-apirequest: true
18 changes: 18 additions & 0 deletions packages/nextcloud/test/fixtures/news/add_feed.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GET http://localhost/index\.php/apps/news/api/v1-3/feeds
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/feeds
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
12 changes: 12 additions & 0 deletions packages/nextcloud/test/fixtures/news/add_feed_to_folder.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml&folderId=1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
18 changes: 18 additions & 0 deletions packages/nextcloud/test/fixtures/news/create_folder.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GET http://localhost/index\.php/apps/news/api/v1-3/folders
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/folders
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
17 changes: 17 additions & 0 deletions packages/nextcloud/test/fixtures/news/delete_feed.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
DELETE http://localhost/index\.php/apps/news/api/v1-3/feeds/1
user-agent: Dart/3\.2 \(dart:io\)
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/feeds
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
17 changes: 17 additions & 0 deletions packages/nextcloud/test/fixtures/news/delete_folder.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
DELETE http://localhost/index\.php/apps/news/api/v1-3/folders/1
user-agent: Dart/3\.2 \(dart:io\)
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/folders
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
6 changes: 6 additions & 0 deletions packages/nextcloud/test/fixtures/news/is_supported.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GET http://localhost/index\.php/apps/news/api
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
18 changes: 18 additions & 0 deletions packages/nextcloud/test/fixtures/news/list_articles.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GET http://localhost/index\.php/apps/news/api/v1-3/items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
24 changes: 24 additions & 0 deletions packages/nextcloud/test/fixtures/news/list_folders.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GET http://localhost/index\.php/apps/news/api/v1-3/folders
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test1
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/folders\?name=test2
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/folders
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
30 changes: 30 additions & 0 deletions packages/nextcloud/test/fixtures/news/list_updated_articles.regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fwikipedia\.xml
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
POST http://localhost/index\.php/apps/news/api/v1-3/feeds\?url=http%3A%2F%2Flocalhost%2Fstatic%2Fnasa\.xml
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
transfer-encoding: chunked
accept-encoding: gzip
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
GET http://localhost/index\.php/apps/news/api/v1-3/items/updated\?lastModified=[0-9]+
user-agent: Dart/3\.2 \(dart:io\)
accept: application/json
accept-encoding: gzip
content-length: 0
authorization: Basic mock
Loading