File tree Expand file tree Collapse file tree 3 files changed +140
-0
lines changed
lib/feature/data/model/user_setting
feature/data/model/user_setting Expand file tree Collapse file tree 3 files changed +140
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:equatable/equatable.dart' ;
2+ import 'package:json_annotation/json_annotation.dart' ;
3+
4+ part 'user_setting_body.g.dart' ;
5+
6+ @JsonSerializable ()
7+ class UserSettingBody extends Equatable {
8+ @JsonKey (name: 'data' )
9+ final List <ItemUserSettingBody > data;
10+
11+ UserSettingBody ({
12+ required this .data,
13+ });
14+
15+ factory UserSettingBody .fromJson (Map <String , dynamic > json) => _$UserSettingBodyFromJson (json);
16+
17+ Map <String , dynamic > toJson () => _$UserSettingBodyToJson (this );
18+
19+ @override
20+ List <Object ?> get props => [
21+ data,
22+ ];
23+
24+ @override
25+ String toString () {
26+ return 'UserSettingBody{data: $data }' ;
27+ }
28+ }
29+
30+ @JsonSerializable ()
31+ class ItemUserSettingBody extends Equatable {
32+ @JsonKey (name: 'id' )
33+ final int id;
34+ @JsonKey (name: 'is_enable_blur_screenshot' )
35+ final bool isEnableBlurScreenshot;
36+ @JsonKey (name: 'user_id' )
37+ final int userId;
38+
39+ ItemUserSettingBody ({
40+ required this .id,
41+ required this .isEnableBlurScreenshot,
42+ required this .userId,
43+ });
44+
45+ factory ItemUserSettingBody .fromJson (Map <String , dynamic > json) => _$ItemUserSettingBodyFromJson (json);
46+
47+ Map <String , dynamic > toJson () => _$ItemUserSettingBodyToJson (this );
48+
49+ @override
50+ List <Object ?> get props => [
51+ id,
52+ isEnableBlurScreenshot,
53+ userId,
54+ ];
55+
56+ @override
57+ String toString () {
58+ return 'ItemUserSettingBody{id: $id , isEnableBlurScreenshot: $isEnableBlurScreenshot , userId: $userId }' ;
59+ }
60+ }
Original file line number Diff line number Diff line change 1+ import 'dart:convert' ;
2+
3+ import 'package:dipantau_desktop_client/feature/data/model/user_setting/user_setting_body.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_body.json' ;
10+ final tModel = UserSettingBody .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.data,
24+ ],
25+ );
26+ },
27+ );
28+
29+ test (
30+ 'pastikan output dari fungsi toString' ,
31+ () async {
32+ // assert
33+ expect (
34+ tModel.toString (),
35+ 'UserSettingBody{data: ${tModel .data }}' ,
36+ );
37+ },
38+ );
39+
40+ test (
41+ 'pastikan fungsi fromJson bisa mengembalikan objek class model' ,
42+ () async {
43+ // arrange
44+ final jsonData = json.decode (fixture (tPathJson));
45+
46+ // act
47+ final actualModel = UserSettingBody .fromJson (jsonData);
48+
49+ // assert
50+ expect (actualModel, tModel);
51+ },
52+ );
53+
54+ test (
55+ 'pastikan fungsi toJson bisa mengembalikan objek map' ,
56+ () async {
57+ // arrange
58+ final model = UserSettingBody .fromJson (
59+ json.decode (
60+ fixture (tPathJson),
61+ ),
62+ );
63+
64+ // act
65+ final actualMap = json.encode (model.toJson ());
66+
67+ // assert
68+ expect (actualMap, json.encode (tModel.toJson ()));
69+ },
70+ );
71+ }
Original file line number Diff line number Diff line change 1+ {
2+ "data" : [
3+ {
4+ "id" : 1 ,
5+ "is_enable_blur_screenshot" : false ,
6+ "user_id" : 1
7+ }
8+ ]
9+ }
You can’t perform that action at this time.
0 commit comments