Skip to content

Commit

Permalink
Merge pull request #2352 from nextcloud/fix/nextcloud/request-body
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Aug 6, 2024
2 parents 010f2ec + 52f868d commit 1496cdd
Show file tree
Hide file tree
Showing 81 changed files with 5,706 additions and 20,114 deletions.
14 changes: 4 additions & 10 deletions packages/neon/neon_dashboard/lib/src/blocs/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ class _DashboardBloc extends InteractiveBloc implements DashboardBloc {
account: account,
subject: itemsV1,
getRequest: () => account.client.dashboard.dashboardApi.$getWidgetItems_Request(
$body: dashboard.DashboardApiGetWidgetItemsRequestApplicationJson(
(b) => b
..widgets.replace(v1WidgetIDs.build())
..limit = maxItems,
),
widgets: BuiltList(v1WidgetIDs.build()),
limit: maxItems,
),
converter: ResponseConverter(account.client.dashboard.dashboardApi.$getWidgetItems_Serializer()),
unwrap: (response) => response.body.ocs.data,
Expand All @@ -115,11 +112,8 @@ class _DashboardBloc extends InteractiveBloc implements DashboardBloc {
account: account,
subject: itemsV2,
getRequest: () => account.client.dashboard.dashboardApi.$getWidgetItemsV2_Request(
$body: dashboard.DashboardApiGetWidgetItemsV2RequestApplicationJson(
(b) => b
..widgets.replace(v2WidgetIDs.build())
..limit = maxItems,
),
widgets: BuiltList(v2WidgetIDs.build()),
limit: maxItems,
),
converter: ResponseConverter(account.client.dashboard.dashboardApi.$getWidgetItemsV2_Serializer()),
unwrap: (response) => response.body.ocs.data,
Expand Down
14 changes: 5 additions & 9 deletions packages/neon/neon_dashboard/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:neon_framework/testing.dart';

Account mockDashboardAccount() => mockServer({
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v1/widgets'): {
'get': (match, bodyBytes) => Response(
'get': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand Down Expand Up @@ -39,15 +39,13 @@ Account mockDashboardAccount() => mockServer({
),
},
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v1/widget-items'): {
'get': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

'get': (match, request) {
return Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in (data['widgets'] as List).cast<String>())
for (final key in request.url.queryParametersAll['widgets[]']!)
key: [
{
'subtitle': '',
Expand Down Expand Up @@ -78,15 +76,13 @@ Account mockDashboardAccount() => mockServer({
},
},
RegExp(r'/ocs/v2\.php/apps/dashboard/api/v2/widget-items'): {
'get': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

'get': (match, request) {
return Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
'data': {
for (final key in (data['widgets'] as List).cast<String>())
for (final key in request.url.queryParametersAll['widgets[]']!)
key: {
'items': [
{
Expand Down
9 changes: 3 additions & 6 deletions packages/neon/neon_files/lib/src/widgets/file_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ class FilePreviewImage extends NeonApiImage {
required super.account,
}) : super(
getRequest: (client) => client.core.preview.$getPreview_Request(
$body: PreviewGetPreviewRequestApplicationJson(
(b) => b
..file = file.uri.path
..x = width
..y = height,
),
file: file.uri.path,
x: width,
y: height,
),
etag: file.etag,
expires: null,
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_notifications/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Account mockNotificationsAccount() {

return mockServer({
RegExp(r'/ocs/v2\.php/apps/notifications/api/v2/notifications/([0-9]+)'): {
'delete': (match, bodyBytes) {
'delete': (match, request) {
final id = int.parse(match.group(1)!);
notifications.removeWhere((n) => n['notification_id'] == id);

Expand All @@ -43,7 +43,7 @@ Account mockNotificationsAccount() {
},
},
RegExp(r'/ocs/v2\.php/apps/notifications/api/v2/notifications'): {
'get': (match, bodyBytes) => Response(
'get': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand All @@ -53,7 +53,7 @@ Account mockNotificationsAccount() {
200,
headers: {'content-type': 'application/json'},
),
'delete': (match, bodyBytes) {
'delete': (match, request) {
notifications.clear();

return Response(
Expand Down
24 changes: 8 additions & 16 deletions packages/neon/neon_talk/lib/src/blocs/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,10 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
try {
final response = await account.client.spreed.chat.receiveMessages(
token: token,
$body: spreed.ChatReceiveMessagesRequestApplicationJson(
(b) => b
..lookIntoFuture = spreed.ChatReceiveMessagesRequestApplicationJson_LookIntoFuture.$1
..includeLastKnown = spreed.ChatReceiveMessagesRequestApplicationJson_IncludeLastKnown.$0
..lastKnownMessageId = lastKnownMessageId
..limit = 100,
),
lookIntoFuture: spreed.ChatReceiveMessagesLookIntoFuture.$1,
includeLastKnown: spreed.ChatReceiveMessagesIncludeLastKnown.$0,
lastKnownMessageId: lastKnownMessageId,
limit: 100,
);

updateLastCommonRead(response.headers.xChatLastCommonRead);
Expand Down Expand Up @@ -225,12 +222,9 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
subject: messages,
getRequest: () => account.client.spreed.chat.$receiveMessages_Request(
token: token,
$body: spreed.ChatReceiveMessagesRequestApplicationJson(
(b) => b
..lookIntoFuture = spreed.ChatReceiveMessagesRequestApplicationJson_LookIntoFuture.$0
..includeLastKnown = spreed.ChatReceiveMessagesRequestApplicationJson_IncludeLastKnown.$0
..limit = 100,
),
lookIntoFuture: spreed.ChatReceiveMessagesLookIntoFuture.$0,
includeLastKnown: spreed.ChatReceiveMessagesIncludeLastKnown.$0,
limit: 100,
),
converter: ResponseConverter(account.client.spreed.chat.$receiveMessages_Serializer()),
unwrap: (response) {
Expand Down Expand Up @@ -324,9 +318,7 @@ class _TalkRoomBloc extends InteractiveBloc implements TalkRoomBloc {
final response = await account.client.spreed.reaction.delete(
token: token,
messageId: message.id,
$body: spreed.ReactionDeleteRequestApplicationJson(
(b) => b..reaction = reaction,
),
reaction: reaction,
);

updateReactions(
Expand Down
7 changes: 2 additions & 5 deletions packages/neon/neon_talk/lib/src/widgets/message_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,8 @@ class _TalkMessageInputState extends State<TalkMessageInput> {
final account = NeonProvider.of<Account>(context);
final response = await account.client.spreed.chat.mentions(
token: bloc.room.value.requireData.token,
$body: spreed.ChatMentionsRequestApplicationJson(
(b) => b
..search = matchingPart.substring(1)
..limit = 5,
),
search: matchingPart.substring(1),
limit: 5,
);

return response.body.ocs.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:nextcloud/core.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/spreed.dart' as spreed;

/// Displays a file preview from a rich object.
Expand Down Expand Up @@ -62,13 +62,10 @@ class TalkRichObjectFilePreview extends StatelessWidget {
etag: parameter.etag,
expires: null,
getRequest: (client) => client.core.preview.$getPreviewByFileId_Request(
$body: PreviewGetPreviewByFileIdRequestApplicationJson(
(b) => b
..fileId = int.parse(parameter.id)
..x = deviceSize.width.toInt()
..y = deviceSize.height.toInt()
..a = true,
),
fileId: int.parse(parameter.id),
x: deviceSize.width.toInt(),
y: deviceSize.height.toInt(),
a: core.PreviewGetPreviewByFileIdA.$1,
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_talk/test/bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Account mockTalkAccount() {

return mockServer({
RegExp(r'/ocs/v2\.php/apps/spreed/api/v4/room'): {
'get': (match, bodyBytes) => Response(
'get': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand All @@ -34,7 +34,7 @@ Account mockTalkAccount() {
200,
headers: {'content-type': 'application/json'},
),
'post': (match, bodyBytes) {
'post': (match, request) {
roomCount++;

return Response(
Expand Down
8 changes: 3 additions & 5 deletions packages/neon/neon_talk/test/create_room_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import 'package:rxdart/subjects.dart';
Account mockAutocompleteAccount() {
return mockServer({
RegExp(r'/ocs/v2\.php/core/autocomplete/get'): {
'get': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

final source = ((data['shareTypes'] as List)[0] as int) == 0 ? 'users' : 'groups';
'get': (match, request) {
final source = request.url.queryParametersAll['shareTypes[]']!.single == '0' ? 'users' : 'groups';
return Response(
json.encode(
{
Expand All @@ -52,7 +50,7 @@ Account mockAutocompleteAccount() {
},
},
RegExp(r'/index\.php/avatar/.*'): {
'get': (match, bodyBytes) => Response('', 404),
'get': (match, request) => Response('', 404),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_talk/test/message_input_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import 'testing.dart';
Account mockTalkAccount() {
return mockServer({
RegExp(r'/ocs/v2\.php/apps/spreed/api/v1/chat/.*/mentions'): {
'get': (match, queryParameters) async {
'get': (match, request) async {
await Future<void>.delayed(const Duration(seconds: 1));

return Response(
Expand All @@ -58,7 +58,7 @@ Account mockTalkAccount() {
},
},
RegExp(r'/index\.php/avatar/.*'): {
'get': (match, bodyBytes) => Response('', 404),
'get': (match, request) => Response('', 404),
},
});
}
Expand Down
32 changes: 14 additions & 18 deletions packages/neon/neon_talk/test/room_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Account mockTalkAccount() {

return mockServer({
RegExp(r'/ocs/v2\.php/apps/spreed/api/v4/room/abcd/participants/active'): {
'post': (match, bodyBytes) => Response(
'post': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand All @@ -30,7 +30,7 @@ Account mockTalkAccount() {
200,
headers: {'content-type': 'application/json'},
),
'delete': (match, bodyBytes) => Response(
'delete': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand All @@ -42,7 +42,7 @@ Account mockTalkAccount() {
),
},
RegExp(r'/ocs/v2\.php/apps/spreed/api/v1/chat/abcd/([0-9]+)'): {
'delete': (match, bodyBytes) {
'delete': (match, request) {
final id = int.parse(match.group(1)!);

return Response(
Expand All @@ -66,9 +66,9 @@ Account mockTalkAccount() {
},
);
},
'put': (match, bodyBytes) {
'put': (match, request) {
final id = int.parse(match.group(1)!);
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;
final data = json.decode(request.body) as Map<String, dynamic>;
final message = data['message'] as String;

return Response(
Expand All @@ -94,10 +94,8 @@ Account mockTalkAccount() {
},
},
RegExp(r'/ocs/v2\.php/apps/spreed/api/v1/chat/abcd'): {
'get': (match, bodyBytes) async {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

final lookIntoFuture = (data['lookIntoFuture'] as int) == 1;
'get': (match, request) async {
final lookIntoFuture = request.url.queryParameters['lookIntoFuture'] == '1';
if (lookIntoFuture) {
// Simulate a new message received after some time
await Future<void>.delayed(const Duration(milliseconds: 1));
Expand Down Expand Up @@ -165,8 +163,8 @@ Account mockTalkAccount() {
);
}
},
'post': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;
'post': (match, request) {
final data = json.decode(request.body) as Map<String, dynamic>;
final replyTo = data['replyTo'] as int?;

return Response(
Expand All @@ -192,8 +190,8 @@ Account mockTalkAccount() {
},
},
RegExp(r'/ocs/v2\.php/apps/spreed/api/v1/reaction/abcd/[0-9]+'): {
'post': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;
'post': (match, request) {
final data = json.decode(request.body) as Map<String, dynamic>;

final reaction = data['reaction'] as String;

Expand Down Expand Up @@ -225,10 +223,8 @@ Account mockTalkAccount() {
},
);
},
'delete': (match, bodyBytes) {
final data = json.decode(utf8.decode(bodyBytes)) as Map<String, dynamic>;

final reaction = data['reaction'] as String;
'delete': (match, request) {
final reaction = request.url.queryParameters['reaction']!;

return Response(
json.encode({
Expand Down Expand Up @@ -258,7 +254,7 @@ Account mockTalkAccount() {
},
);
},
'get': (match, bodyBytes) => Response(
'get': (match, request) => Response(
json.encode({
'ocs': {
'meta': {'status': '', 'statuscode': 0},
Expand Down
4 changes: 1 addition & 3 deletions packages/neon_framework/lib/src/blocs/unified_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ class _UnifiedSearchBloc extends InteractiveBloc implements UnifiedSearchBloc {
try {
final response = await account.client.core.unifiedSearch.search(
providerId: providerID,
$body: core.UnifiedSearchSearchRequestApplicationJson(
(b) => b..term = term,
),
term: term,
);
updateResults(providerID, Result.success(response.body.ocs.data));
} on http.ClientException catch (error, stackTrace) {
Expand Down
5 changes: 2 additions & 3 deletions packages/neon_framework/lib/src/testing/mock_server.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:http/http.dart';
import 'package:http/testing.dart';
Expand All @@ -9,7 +8,7 @@ import 'package:neon_framework/src/models/account.dart';
///
/// To be used for end-to-end testing `Bloc`s.
Account mockServer(
Map<RegExp, Map<String, FutureOr<Response> Function(RegExpMatch match, Uint8List bodyBytes)>> requests,
Map<RegExp, Map<String, FutureOr<Response> Function(RegExpMatch match, Request)>> requests,
) =>
Account(
(b) => b
Expand All @@ -22,7 +21,7 @@ Account mockServer(
if (match != null) {
final call = entry.value[request.method];
if (call != null) {
return call(match, request.bodyBytes);
return call(match, request);
}
}
}
Expand Down
Loading

0 comments on commit 1496cdd

Please sign in to comment.