Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aidaiym committed Aug 13, 2024
1 parent e8ce9af commit 5b8b7cb
Showing 1 changed file with 16 additions and 49 deletions.
65 changes: 16 additions & 49 deletions packages/mq_remote_client/test/mq_remote_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ void main() {

group('MqRemoteClient `post`, `postType`, `postListOfType`', () {
test('Post', () async {
TestModel? mapValue;
Map<String, dynamic>? mapValue;
final mapResponse = await client.post<Map<String, dynamic>>(
postList,
body: requestBody,
);

final mapResponse = await client.post<TestModel>(postDatas, body: requestBody);
mapResponse.fold((l) => null, (r) => mapValue = r);

expect(mapValue, isNotNull);
Expand All @@ -97,28 +100,14 @@ void main() {
test('Post Type', () async {
TestModel? testModel;
final response = await client.postType<TestModel>(
postDatas,
postList,
body: requestBody,
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModel = r);

expect(testModel, isA<TestModel>());
});

test('Post List Of Type', () async {
List<TestModel>? testModelList;
final response = await client.postListOfType<TestModel>(
postList,
body: requestBody,
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModelList = r);

expect(testModelList, isList);
expect(testModelList, isA<List<TestModel>>());
expect(testModelList?[0], isA<TestModel>());
});
});

group('MqRemoteClient `put`, `putType`, `putListOfType`', () {
Expand All @@ -127,6 +116,7 @@ void main() {

final mapResponse = await client.put<Map<String, dynamic>>(postDatas, body: requestBody);
mapResponse.fold((l) => null, (r) => mapValue = r);
expect(mapValue, isNotNull);

expect(mapValue, isA<Map<String, dynamic>>());
});
Expand All @@ -139,35 +129,25 @@ void main() {
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModel = r);
expect(testModel, isA<TestModel>());
});

test('Put List Of Type', () async {
List<TestModel>? testModelList;
final response = await client.putListOfType<TestModel>(
postList,
body: requestBody,
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModelList = r);
expect(testModelList, isList);
expect(testModelList, isA<List<TestModel>>());
expect(testModelList?[0], isA<TestModel>());
expect(testModel, isA<TestModel>());
});
});

group('MqRemoteClient `patch`, `patchType`, `patchListOfType`', () {
test('Patch', () async {
TestModel? testModel;
Map<String, dynamic>? mapValue;

final mapResponse = await client.patch<TestModel>(
final mapResponse = await client.patch<Map<String, dynamic>>(
postDatas,
fromJson: (json) => json,
body: requestBody,
fromJson: TestModel.fromJson,
);
mapResponse.fold((l) => null, (r) => testModel = r);

expect(testModel, isA<Map<String, dynamic>>());
mapResponse.fold((l) => null, (r) => mapValue = r);
expect(mapValue, isNotNull);

expect(mapValue, isA<Map<String, dynamic>>());
});

test('Patch Type', () async {
Expand All @@ -178,21 +158,8 @@ void main() {
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModel = r);
expect(testModel, isA<TestModel>());
});

test('Patch List Of Type', () async {
List<TestModel>? testModelList;
final response = await client.patchListOfType<TestModel>(
postList,
body: requestBody,
fromJson: TestModel.fromJson,
);
response.fold((l) => null, (r) => testModelList = r);

expect(testModelList, isList);
expect(testModelList, isA<List<TestModel>>());
expect(testModelList?[0], isA<TestModel>());
expect(testModel, isA<TestModel>());
});
});
}

0 comments on commit 5b8b7cb

Please sign in to comment.