From 9aec4683e2f1cfe6a0a985deff89f04f71b82100 Mon Sep 17 00:00:00 2001 From: Pedro Silva <9375141+pedrox-hs@users.noreply.github.com> Date: Mon, 1 Jan 2024 18:14:37 -0300 Subject: [PATCH] Add tests to Response extensions --- shic/test/src/ext/response_test.dart | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 shic/test/src/ext/response_test.dart diff --git a/shic/test/src/ext/response_test.dart b/shic/test/src/ext/response_test.dart new file mode 100644 index 0000000..ea0f6d2 --- /dev/null +++ b/shic/test/src/ext/response_test.dart @@ -0,0 +1,76 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart'; +import 'package:shic/shic.dart'; + +void main() { + group('ResponseExt', () { + test( + 'bodyJson should parse json correctly', + () { + // arrange + final expected = {'foo': 'bar'}; + final response = Response('{"foo": "bar"}', 200); + + // act + final actual = response.bodyJson; + + // assert + expect(actual, expected); + }, + ); + }); + + group('StreamedResponseExt', () { + test('body should return body as string', () async { + // arrange + final expected = 'Hello, world!'; + final response = StreamedResponse( + Stream.value(expected.codeUnits), + 200, + ); + + // act + final actual = await response.body; + + // assert + expect(actual, expected); + }); + + test( + 'bodyJson should parse json correctly', + () async { + // arrange + final expected = {'foo': 'bar'}; + final response = StreamedResponse( + Stream.value('{"foo": "bar"}'.codeUnits), + 200, + ); + + // act + final actual = await response.bodyJson; + + // assert + expect(actual, expected); + }, + ); + }); + + group('FutureResponseExt', () { + test( + 'mapJsonWith should map json correctly', + () async { + // arrange + final expected = {'foo': 'bar', 'baz': 'qux'}; + final response = Future.value(Response('{"foo": "bar"}', 200)); + + // act + final actual = await response.mapJsonWith( + (Map json) => {...json, 'baz': 'qux'}, + ); + + // assert + expect(actual, expected); + }, + ); + }); +}