diff --git a/packages/mq_remote_client/test/mq_remote_client_test.dart b/packages/mq_remote_client/test/mq_remote_client_test.dart index 0a188757..46b9f3b5 100644 --- a/packages/mq_remote_client/test/mq_remote_client_test.dart +++ b/packages/mq_remote_client/test/mq_remote_client_test.dart @@ -8,9 +8,15 @@ import 'test_model.dart'; void main() { late MqRemoteClient client; - const getListUrl = 'https://encointer.github.io/feed/community_messages/en/cm.json'; - const getUrl = 'https://eldar2021.github.io/encointer/test_data.json'; const emptyList = 'https://eldar2021.github.io/encointer/test/empty_list.json'; + const postList = 'https://jsonplaceholder.typicode.com/posts'; + const postDatas = 'https://jsonplaceholder.typicode.com/posts/1'; + + final requestBody = { + 'title': 'foo', + 'body': 'bar', + 'userId': 1, + }; setUp( () => client = MqRemoteClient( @@ -24,14 +30,14 @@ void main() { Map? mapValue; List? listValue; - final mapResponse = await client.get>(getUrl); + final mapResponse = await client.get>(postDatas); mapResponse.fold((l) => null, (r) => mapValue = r); expect(mapValue, isNotNull); expect(mapValue, isMap); expect(mapValue, isA>()); - final listResponse = await client.get>(getListUrl); + final listResponse = await client.get>(postList); listResponse.fold((l) => null, (r) => listValue = r); expect(listValue, isNotNull); expect(listValue, isList); @@ -42,7 +48,7 @@ void main() { test('Get Type', () async { TestModel? testModel; final response = await client.getType( - getUrl, + postDatas, fromJson: TestModel.fromJson, ); response.fold((l) => null, (r) => testModel = r); @@ -53,7 +59,7 @@ void main() { test('Get List Of Type', () async { List? testModelList; final response = await client.getListOfType( - getListUrl, + postList, fromJson: TestModel.fromJson, ); response.fold((l) => null, (r) => testModelList = r); @@ -76,4 +82,117 @@ void main() { expect(testModelList?.isEmpty, true); }); }); + + group('MqRemoteClient `post`, `postType`, `postListOfType`', () { + test('Post', () async { + TestModel? mapValue; + + final mapResponse = await client.post(postDatas, body: requestBody); + mapResponse.fold((l) => null, (r) => mapValue = r); + + expect(mapValue, isNotNull); + expect(mapValue, isA>()); + }); + + test('Post Type', () async { + TestModel? testModel; + final response = await client.postType( + postDatas, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModel = r); + + expect(testModel, isA()); + }); + + test('Post List Of Type', () async { + List? testModelList; + final response = await client.postListOfType( + postList, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModelList = r); + + expect(testModelList, isList); + expect(testModelList, isA>()); + expect(testModelList?[0], isA()); + }); + }); + + group('MqRemoteClient `put`, `putType`, `putListOfType`', () { + test('Put', () async { + Map? mapValue; + + final mapResponse = await client.put>(postDatas, body: requestBody); + mapResponse.fold((l) => null, (r) => mapValue = r); + + expect(mapValue, isA>()); + }); + + test('Put Type', () async { + TestModel? testModel; + final response = await client.putType( + postDatas, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModel = r); + expect(testModel, isA()); + }); + + test('Put List Of Type', () async { + List? testModelList; + final response = await client.putListOfType( + postList, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModelList = r); + expect(testModelList, isList); + expect(testModelList, isA>()); + expect(testModelList?[0], isA()); + }); + }); + + group('MqRemoteClient `patch`, `patchType`, `patchListOfType`', () { + test('Patch', () async { + TestModel? testModel; + + final mapResponse = await client.patch( + postDatas, + body: requestBody, + fromJson: TestModel.fromJson, + ); + mapResponse.fold((l) => null, (r) => testModel = r); + + expect(testModel, isA>()); + }); + + test('Patch Type', () async { + TestModel? testModel; + final response = await client.patchType( + postDatas, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModel = r); + expect(testModel, isA()); + }); + + test('Patch List Of Type', () async { + List? testModelList; + final response = await client.patchListOfType( + postList, + body: requestBody, + fromJson: TestModel.fromJson, + ); + response.fold((l) => null, (r) => testModelList = r); + + expect(testModelList, isList); + expect(testModelList, isA>()); + expect(testModelList?[0], isA()); + }); + }); } diff --git a/packages/mq_remote_client/test/test_model.dart b/packages/mq_remote_client/test/test_model.dart index ee399298..76e3500f 100644 --- a/packages/mq_remote_client/test/test_model.dart +++ b/packages/mq_remote_client/test/test_model.dart @@ -1,31 +1,30 @@ final class TestModel { const TestModel({ + required this.userId, required this.id, required this.title, - required this.content, - required this.showAt, + required this.body, }); factory TestModel.fromJson(Map json) { return TestModel( - id: json['id'] as String, + userId: json['userId'] as int, + id: json['id'] as int, title: json['title'] as String, - content: json['content'] as String, - showAt: json['showAt'] as String, + body: json['body'] as String, ); } - - final String id; + final int userId; + final int id; final String title; - final String content; - final String showAt; + final String body; Map toJson() { return { + 'userId': userId, 'id': id, 'title': title, - 'content': content, - 'showAt': showAt, + 'body': body, }; } }