@@ -4,6 +4,7 @@ import 'package:account_repository/account_repository.dart';
4
4
import 'package:account_repository/src/testing/testing.dart' ;
5
5
import 'package:account_repository/src/utils/authentication_client.dart' ;
6
6
import 'package:built_collection/built_collection.dart' ;
7
+ import 'package:built_value/json_object.dart' ;
7
8
import 'package:built_value_test/matcher.dart' ;
8
9
import 'package:http/http.dart' as http;
9
10
import 'package:mocktail/mocktail.dart' ;
@@ -38,6 +39,14 @@ class _ClientFlowLoginV2ClientMock extends Mock implements core.$ClientFlowLogin
38
39
39
40
class _UsersClientMock extends Mock implements provisioning_api.$UsersClient {}
40
41
42
+ class _WipeClientMock extends Mock implements core.$WipeClient {}
43
+
44
+ class _WipeCheckResponseMock extends Mock implements core.WipeCheckWipeResponseApplicationJson {}
45
+
46
+ class _FakeWipeCheckRequest extends Fake implements core.WipeCheckWipeRequestApplicationJson {}
47
+
48
+ class _FakeWipeDoneRequest extends Fake implements core.WipeWipeDoneRequestApplicationJson {}
49
+
41
50
class _AccountStorageMock extends Mock implements AccountStorage {}
42
51
43
52
typedef _AccountStream = ({BuiltList <Account > accounts, Account ? active});
@@ -50,10 +59,13 @@ void main() {
50
59
late core.$AppPasswordClient appPassword;
51
60
late core.$ClientFlowLoginV2Client clientFlowLoginV2;
52
61
late provisioning_api.$UsersClient users;
62
+ late core.$WipeClient wipe;
53
63
54
64
setUpAll (() {
55
65
registerFallbackValue (_FakeUri ());
56
66
registerFallbackValue (_FakePollRequest ());
67
+ registerFallbackValue (_FakeWipeCheckRequest ());
68
+ registerFallbackValue (_FakeWipeDoneRequest ());
57
69
MockNeonStorage ();
58
70
});
59
71
@@ -62,12 +74,14 @@ void main() {
62
74
appPassword = _AppPasswordClientMock ();
63
75
clientFlowLoginV2 = _ClientFlowLoginV2ClientMock ();
64
76
users = _UsersClientMock ();
77
+ wipe = _WipeClientMock ();
65
78
66
79
mockedClient = AuthenticationClient (
67
80
core: coreClient,
68
81
appPassword: appPassword,
69
82
clientFlowLoginV2: clientFlowLoginV2,
70
83
users: users,
84
+ wipe: wipe,
71
85
);
72
86
73
87
storage = _AccountStorageMock ();
@@ -587,5 +601,127 @@ void main() {
587
601
verify (() => storage.saveLastAccount (credentialsList[1 ].id)).called (1 );
588
602
});
589
603
});
604
+
605
+ group ('getRemoteWipeStatus' , () {
606
+ group ('retrieves remote wipe status from server' , () {
607
+ test ('should wipe' , () async {
608
+ final wipeCheckResponse = _WipeCheckResponseMock ();
609
+ when (() => wipeCheckResponse.wipe).thenReturn (true );
610
+ final response = _DynamiteResponseMock <_WipeCheckResponseMock , void >();
611
+ when (() => response.body).thenReturn (wipeCheckResponse);
612
+
613
+ when (() => wipe.checkWipe ($body: any (named: r'$body' ))).thenAnswer ((_) async => response);
614
+
615
+ await expectLater (
616
+ repository.getRemoteWipeStatus (accountsList.first),
617
+ completion (true ),
618
+ );
619
+
620
+ verify (
621
+ () => wipe.checkWipe (
622
+ $body: any (
623
+ named: r'$body' ,
624
+ that: isA< core.WipeCheckWipeRequestApplicationJson > ().having (
625
+ (b) => b.token,
626
+ 'token' ,
627
+ 'appPassword' ,
628
+ ),
629
+ ),
630
+ ),
631
+ ).called (1 );
632
+ });
633
+
634
+ test ('should not wipe' , () async {
635
+ when (() => wipe.checkWipe ($body: any (named: r'$body' )))
636
+ .thenThrow (DynamiteStatusCodeException (http.Response ('' , 404 )));
637
+
638
+ await expectLater (
639
+ repository.getRemoteWipeStatus (accountsList.first),
640
+ completion (false ),
641
+ );
642
+
643
+ verify (
644
+ () => wipe.checkWipe (
645
+ $body: any (
646
+ named: r'$body' ,
647
+ that: isA< core.WipeCheckWipeRequestApplicationJson > ().having (
648
+ (b) => b.token,
649
+ 'token' ,
650
+ 'appPassword' ,
651
+ ),
652
+ ),
653
+ ),
654
+ ).called (1 );
655
+ });
656
+ });
657
+
658
+ test ('rethrows http exceptions as `GetRemoteWipeStatusFailure`' , () async {
659
+ when (() => wipe.checkWipe ($body: any (named: r'$body' ))).thenThrow (http.ClientException ('' ));
660
+
661
+ await expectLater (
662
+ repository.getRemoteWipeStatus (accountsList.first),
663
+ throwsA (isA <GetRemoteWipeStatusFailure >().having ((e) => e.error, 'error' , isA< http.ClientException > ())),
664
+ );
665
+
666
+ verify (
667
+ () => wipe.checkWipe (
668
+ $body: any (
669
+ named: r'$body' ,
670
+ that: isA< core.WipeCheckWipeRequestApplicationJson > ().having (
671
+ (b) => b.token,
672
+ 'token' ,
673
+ 'appPassword' ,
674
+ ),
675
+ ),
676
+ ),
677
+ ).called (1 );
678
+ });
679
+ });
680
+
681
+ group ('postRemoteWipeSuccess' , () {
682
+ test ('posts remote wipe success server' , () async {
683
+ final response = _DynamiteResponseMock <JsonObject , void >();
684
+ when (() => response.body).thenReturn (JsonObject ('' ));
685
+
686
+ when (() => wipe.wipeDone ($body: any (named: r'$body' ))).thenAnswer ((_) async => response);
687
+
688
+ await repository.postRemoteWipeSuccess (accountsList.first);
689
+
690
+ verify (
691
+ () => wipe.wipeDone (
692
+ $body: any (
693
+ named: r'$body' ,
694
+ that: isA< core.WipeWipeDoneRequestApplicationJson > ().having (
695
+ (b) => b.token,
696
+ 'token' ,
697
+ 'appPassword' ,
698
+ ),
699
+ ),
700
+ ),
701
+ ).called (1 );
702
+ });
703
+
704
+ test ('rethrows http exceptions as `PostRemoteWipeSuccessFailure`' , () async {
705
+ when (() => wipe.wipeDone ($body: any (named: r'$body' ))).thenThrow (http.ClientException ('' ));
706
+
707
+ await expectLater (
708
+ repository.postRemoteWipeSuccess (accountsList.first),
709
+ throwsA (isA <PostRemoteWipeSuccessFailure >().having ((e) => e.error, 'error' , isA< http.ClientException > ())),
710
+ );
711
+
712
+ verify (
713
+ () => wipe.wipeDone (
714
+ $body: any (
715
+ named: r'$body' ,
716
+ that: isA< core.WipeWipeDoneRequestApplicationJson > ().having (
717
+ (b) => b.token,
718
+ 'token' ,
719
+ 'appPassword' ,
720
+ ),
721
+ ),
722
+ ),
723
+ ).called (1 );
724
+ });
725
+ });
590
726
});
591
727
}
0 commit comments