Skip to content

Commit 93967ea

Browse files
committed
feat: Buat class model user_setting_response.dart
Sekalian dengan unit test-nya.
1 parent 2ff1a57 commit 93967ea

File tree

4 files changed

+123
-36
lines changed

4 files changed

+123
-36
lines changed
Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:dipantau_desktop_client/feature/data/model/user_setting/user_setting_response.dart';
12
import 'package:equatable/equatable.dart';
23
import 'package:json_annotation/json_annotation.dart';
34

@@ -6,7 +7,7 @@ part 'all_user_setting_response.g.dart';
67
@JsonSerializable()
78
class AllUserSettingResponse extends Equatable {
89
@JsonKey(name: 'data')
9-
final List<ItemAllUserSettingResponse>? data;
10+
final List<UserSettingResponse>? data;
1011

1112
AllUserSettingResponse({required this.data});
1213

@@ -25,39 +26,4 @@ class AllUserSettingResponse extends Equatable {
2526
}
2627
}
2728

28-
@JsonSerializable()
29-
class ItemAllUserSettingResponse extends Equatable {
30-
@JsonKey(name: 'id')
31-
final int? id;
32-
@JsonKey(name: 'is_enable_blur_screenshot')
33-
final bool? isEnableBlurScreenshot;
34-
@JsonKey(name: 'user_id')
35-
final int? userId;
36-
@JsonKey(name: 'name')
37-
final String? name;
38-
39-
ItemAllUserSettingResponse({
40-
required this.id,
41-
required this.isEnableBlurScreenshot,
42-
required this.userId,
43-
required this.name,
44-
});
45-
46-
factory ItemAllUserSettingResponse.fromJson(Map<String, dynamic> json) => _$ItemAllUserSettingResponseFromJson(json);
47-
48-
Map<String, dynamic> toJson() => _$ItemAllUserSettingResponseToJson(this);
49-
50-
@override
51-
List<Object?> get props => [
52-
id,
53-
isEnableBlurScreenshot,
54-
userId,
55-
name,
56-
];
5729

58-
@override
59-
String toString() {
60-
return 'ItemAllUserSettingResponse{id: $id, isEnableBlurScreenshot: $isEnableBlurScreenshot, userId: $userId, '
61-
'name: $name}';
62-
}
63-
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:json_annotation/json_annotation.dart';
3+
4+
part 'user_setting_response.g.dart';
5+
6+
@JsonSerializable()
7+
class UserSettingResponse extends Equatable {
8+
@JsonKey(name: 'id')
9+
final int? id;
10+
@JsonKey(name: 'is_enable_blur_screenshot')
11+
final bool? isEnableBlurScreenshot;
12+
@JsonKey(name: 'user_id')
13+
final int? userId;
14+
@JsonKey(name: 'name')
15+
final String? name;
16+
17+
UserSettingResponse({
18+
required this.id,
19+
required this.isEnableBlurScreenshot,
20+
required this.userId,
21+
required this.name,
22+
});
23+
24+
factory UserSettingResponse.fromJson(Map<String, dynamic> json) => _$UserSettingResponseFromJson(json);
25+
26+
Map<String, dynamic> toJson() => _$UserSettingResponseToJson(this);
27+
28+
@override
29+
List<Object?> get props => [
30+
id,
31+
isEnableBlurScreenshot,
32+
userId,
33+
name,
34+
];
35+
36+
@override
37+
String toString() {
38+
return 'UserSettingResponse{id: $id, isEnableBlurScreenshot: $isEnableBlurScreenshot, userId: $userId, name: $name}';
39+
}
40+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import 'dart:convert';
2+
3+
import 'package:dipantau_desktop_client/feature/data/model/user_setting/user_setting_response.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
6+
import '../../../../fixture/fixture_reader.dart';
7+
8+
void main() {
9+
const tPathJson = 'user_setting_response.json';
10+
final tModel = UserSettingResponse.fromJson(
11+
json.decode(
12+
fixture(tPathJson),
13+
),
14+
);
15+
16+
test(
17+
'pastikan output dari nilai props',
18+
() async {
19+
// assert
20+
expect(
21+
tModel.props,
22+
[
23+
tModel.id,
24+
tModel.isEnableBlurScreenshot,
25+
tModel.userId,
26+
tModel.name,
27+
],
28+
);
29+
},
30+
);
31+
32+
test(
33+
'pastikan output dari fungsi toString',
34+
() async {
35+
// assert
36+
expect(
37+
tModel.toString(),
38+
'UserSettingResponse{id: ${tModel.id}, isEnableBlurScreenshot: ${tModel.isEnableBlurScreenshot}, '
39+
'userId: ${tModel.userId}, name: ${tModel.name}}',
40+
);
41+
},
42+
);
43+
44+
test(
45+
'pastikan fungsi fromJson bisa mengembalikan objek class model',
46+
() async {
47+
// arrange
48+
final jsonData = json.decode(fixture(tPathJson));
49+
50+
// act
51+
final actualModel = UserSettingResponse.fromJson(jsonData);
52+
53+
// assert
54+
expect(actualModel, tModel);
55+
},
56+
);
57+
58+
test(
59+
'pastikan fungsi toJson bisa mengembalikan objek map',
60+
() async {
61+
// arrange
62+
final model = UserSettingResponse.fromJson(
63+
json.decode(
64+
fixture(tPathJson),
65+
),
66+
);
67+
68+
// act
69+
final actualMap = json.encode(model.toJson());
70+
71+
// assert
72+
expect(actualMap, json.encode(tModel.toJson()));
73+
},
74+
);
75+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": 1,
3+
"is_enable_blur_screenshot": false,
4+
"user_id": 1,
5+
"name": "name"
6+
}

0 commit comments

Comments
 (0)