@@ -6,9 +6,9 @@ describe('AzureAdB2CService', () => {
66 let service : AzureAdB2CService ;
77 const msalStub = {
88 loginPopup ( ) {
9- return { }
9+ return { } ;
1010 }
11- }
11+ } ;
1212
1313 beforeEach ( ( ) => {
1414 TestBed . configureTestingModule ( {
@@ -17,28 +17,28 @@ describe('AzureAdB2CService', () => {
1717 service = TestBed . inject ( AzureAdB2CService ) ;
1818 } ) ;
1919
20- it ( 'should create ' , inject ( [ AzureAdB2CService ] ,
20+ it ( 'should be created ' , inject ( [ AzureAdB2CService ] ,
2121 ( apiService : AzureAdB2CService ) => {
2222 expect ( apiService ) . toBeTruthy ( ) ;
2323 } ) ) ;
2424
25- it ( 'should call msal loginPopup' , ( ) => {
25+ it ( 'on signIn should call msal loginPopup' , ( ) => {
2626 spyOn ( UserAgentApplication . prototype , 'loginPopup' ) . and . returnValue ( (
2727 new Promise ( ( resolve ) => {
2828 resolve ( ) ;
2929 } )
30- ) )
31- service . signIn ( )
32- expect ( UserAgentApplication . prototype . loginPopup ) . toHaveBeenCalled ;
30+ ) ) ;
31+ service . signIn ( ) ;
32+ expect ( UserAgentApplication . prototype . loginPopup ) . toHaveBeenCalled ( ) ;
3333 } ) ;
3434
35- it ( 'should call msal logout' , ( ) => {
36- spyOn ( UserAgentApplication . prototype , 'logout' ) . and . returnValue ( )
37- service . logout ( )
38- expect ( UserAgentApplication . prototype . logout ) . toHaveBeenCalled ;
35+ it ( 'on logout should call msal logout' , ( ) => {
36+ spyOn ( UserAgentApplication . prototype , 'logout' ) . and . returnValue ( ) ;
37+ service . logout ( ) ;
38+ expect ( UserAgentApplication . prototype . logout ) . toHaveBeenCalled ( ) ;
3939 } ) ;
4040
41- it ( 'should get name Account ' , ( ) => {
41+ it ( 'should get Account name from UserAgentApplication ' , ( ) => {
4242 const account : Account = {
4343 accountIdentifier : 'abc' ,
4444 homeAccountIdentifier : 'abc' ,
@@ -47,15 +47,17 @@ describe('AzureAdB2CService', () => {
4747 idToken : { } ,
4848 idTokenClaims : { } ,
4949 sid : 'abc' ,
50- environment : "abc"
51- }
52- spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValues ( account )
53- const name = service . getName ( )
54- expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ;
55- expect ( name ) . toEqual ( account . name )
50+ environment : 'abc'
51+ } ;
52+ spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValues ( account ) ;
53+
54+ const name = service . getName ( ) ;
55+
56+ expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ( ) ;
57+ expect ( name ) . toEqual ( account . name ) ;
5658 } ) ;
5759
58- it ( 'should return true when user is login ' , ( ) => {
60+ it ( 'isLogin returns true if UserAgentApplication has a defined Account ' , ( ) => {
5961 const account : Account = {
6062 accountIdentifier : 'abc' ,
6163 homeAccountIdentifier : 'abc' ,
@@ -64,19 +66,21 @@ describe('AzureAdB2CService', () => {
6466 idToken : { } ,
6567 idTokenClaims : { } ,
6668 sid : 'abc' ,
67- environment : "abc"
68- }
69- spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValue ( account )
70- const isLogin = service . isLogin ( )
71- expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ;
72- expect ( isLogin ) . toEqual ( true )
69+ environment : 'abc'
70+ } ;
71+ spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValue ( account ) ;
72+
73+ const isLogin = service . isLogin ( ) ;
74+
75+ expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ( ) ;
76+ expect ( isLogin ) . toEqual ( true ) ;
7377 } ) ;
7478
75- it ( 'should return false when user is not login ' , ( ) => {
76- spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValue ( null )
77- const isLogin = service . isLogin ( )
78- expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ;
79- expect ( isLogin ) . toEqual ( false )
79+ it ( 'isLogin returns false if UserAgentApplication has a null value for Account ' , ( ) => {
80+ spyOn ( UserAgentApplication . prototype , 'getAccount' ) . and . returnValue ( null ) ;
81+ const isLogin = service . isLogin ( ) ;
82+ expect ( UserAgentApplication . prototype . getAccount ) . toHaveBeenCalled ( ) ;
83+ expect ( isLogin ) . toEqual ( false ) ;
8084 } ) ;
8185
8286} ) ;
0 commit comments