@@ -13,7 +13,7 @@ describe('smartapp-context-spec', () => {
1313 app = new SmartApp ( { logUnhandledRejections : false } )
1414 } )
1515
16- it ( 'endpoint app with context store' , async ( ) => {
16+ it ( 'endpoint app with unitialized context store' , async ( ) => {
1717 const installData = {
1818 authToken : 'xxx' ,
1919 refreshToken : 'yyy' ,
@@ -51,6 +51,53 @@ describe('smartapp-context-spec', () => {
5151 assert . equal ( installData . refreshToken , ctx . refreshToken )
5252 } )
5353
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+
54101 it ( 'endpoint app with context object' , async ( ) => {
55102 const params = {
56103 authToken : 'xxx' ,
0 commit comments