@@ -13,7 +13,7 @@ describe('smartapp-context-spec', () => {
13
13
app = new SmartApp ( { logUnhandledRejections : false } )
14
14
} )
15
15
16
- it ( 'endpoint app with context store' , async ( ) => {
16
+ it ( 'endpoint app with unitialized context store' , async ( ) => {
17
17
const installData = {
18
18
authToken : 'xxx' ,
19
19
refreshToken : 'yyy' ,
@@ -51,6 +51,53 @@ describe('smartapp-context-spec', () => {
51
51
assert . equal ( installData . refreshToken , ctx . refreshToken )
52
52
} )
53
53
54
+ it ( 'endpoint app with populated context store' , async ( ) => {
55
+ const installData = {
56
+ authToken : 'xxx' ,
57
+ refreshToken : 'yyy' ,
58
+ installedApp : {
59
+ installedAppId : 'd692699d-e7a6-400d-a0b7-d5be96e7a564' ,
60
+ locationId : 'e675a3d9-2499-406c-86dc-8a492a886494' ,
61
+ config : { }
62
+ }
63
+ }
64
+
65
+ const contextStore = new ContextStore ( {
66
+ 'd692699d-e7a6-400d-a0b7-d5be96e7a564' : {
67
+ locationId : 'e675a3d9-2499-406c-86dc-8a492a886494' ,
68
+ installedAppId : 'd692699d-e7a6-400d-a0b7-d5be96e7a564' ,
69
+ state : {
70
+ accessToken : 'xxx'
71
+ }
72
+ }
73
+ } )
74
+ app . contextStore ( contextStore )
75
+
76
+ await app . handleMockCallback ( {
77
+ lifecycle : 'INSTALL' ,
78
+ executionId : 'e6903fe6-f88f-da69-4c12-e2802606ccbc' ,
79
+ locale : 'en' ,
80
+ version : '0.1.0' ,
81
+ client : {
82
+ os : 'ios' ,
83
+ version : '0.0.0' ,
84
+ language : 'en-US'
85
+ } ,
86
+ installData,
87
+ settings : { }
88
+ } )
89
+
90
+ const ctx = await app . withContext ( 'd692699d-e7a6-400d-a0b7-d5be96e7a564' )
91
+
92
+ expect ( ctx ) . toBeInstanceOf ( SmartAppContext )
93
+ expect ( ctx . api . config . authenticator ) . toBeInstanceOf ( SequentialRefreshTokenAuthenticator )
94
+ assert . equal ( installData . installedApp . installedAppId , ctx . installedAppId )
95
+ assert . equal ( installData . installedApp . locationId , ctx . locationId )
96
+ assert . equal ( installData . authToken , ctx . authToken )
97
+ assert . equal ( installData . refreshToken , ctx . refreshToken )
98
+ assert . equal ( await ctx . getItem ( 'accessToken' ) , 'xxx' )
99
+ } )
100
+
54
101
it ( 'endpoint app with context object' , async ( ) => {
55
102
const params = {
56
103
authToken : 'xxx' ,
0 commit comments