Skip to content

Commit

Permalink
feat: adiciona método PUT à interface IApiProvider e à classe ApiProv…
Browse files Browse the repository at this point in the history
…ider
  • Loading branch information
shonorio committed Jan 15, 2025
1 parent 7463f51 commit 9293e57
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/app/core/network/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ abstract class IApiProvider {
String? body,
});

Future<String> put({
required String path,
Map<String, String> headers,
Map<String, String?> parameters,
ApiContentType? contentType,
String? body,
});

Future<String> delete({
required String path,
Map<String, String?> parameters,
Expand Down Expand Up @@ -134,6 +142,27 @@ class ApiProvider implements IApiProvider {
return response.body;
}

@override
Future<String> put({
required String path,
Map<String, String> headers = const {},
Map<String, String?> parameters = const {},
ApiContentType? contentType,
String? body,
}) async {
final streamedResponse = await _execute(
method: ApiHttpRequestMethod.put,
path: path,
body: body ?? '',
headers: headers,
parameters: parameters,
contentType: contentType,
);

final response = await _parseStreamedResponse(streamedResponse);
return response.body;
}

@override
Future<String> delete({
required String path,
Expand Down
30 changes: 30 additions & 0 deletions test/app/core/network/api_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,36 @@ void main() {
});
});

group('put', () {
test('return response', () async {
// arrange
const String path = 'some_path';
final headers = <String, String>{'key1': 'value1'};
final parameters = <String, String>{'param1': 'value1'};
const expected = '{"key": "value"}';
when(() => apiClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
http.ByteStream.fromBytes(utf8.encode(expected)),
HttpStatus.ok,
),
);
final sut = ApiProvider(
serverConfiguration: serverConfiguration,
apiClient: apiClient,
);
// act
final actual = await sut.put(
path: path,
headers: headers,
parameters: parameters,
);
// assert
expect(actual, expected);
final captured = verify(() => apiClient.send(captureAny())).captured;
expect(captured.first.method, 'PUT');
});
});

group('delete', () {
test('return response', () async {
// arrange
Expand Down

0 comments on commit 9293e57

Please sign in to comment.