88} from "../src/index.js" ;
99import { MOCK_START_TIME , MOCK_END_TIME , TWELVE_HOURS } from "./test-utils.js" ;
1010import fetchMock from "fetch-mock" ;
11- import { Emitter } from "mitt" ;
11+ import { ApiKeyManager } from "@esri/arcgis-rest-request" ;
12+
13+ const MOCK_AUTH = ApiKeyManager . fromKey ( "fake-token" ) ;
1214
1315function createMockSession ( ) {
1416 return new BasemapStyleSession ( {
@@ -18,7 +20,7 @@ function createMockSession() {
1820 startTime : MOCK_START_TIME ,
1921 endTime : MOCK_END_TIME ,
2022 expires : new Date ( MOCK_END_TIME . getTime ( ) - DEFAULT_SAFETY_MARGIN * 1000 ) ,
21- authentication : "token"
23+ authentication : MOCK_AUTH
2224 } ) ;
2325}
2426
@@ -41,7 +43,7 @@ async function startMockSession(
4143 const session = await BasemapStyleSession . start ( {
4244 ...{
4345 styleFamily : "arcgis" ,
44- authentication : "token"
46+ authentication : MOCK_AUTH
4547 } ,
4648 ...sessionParams
4749 } ) ;
@@ -83,7 +85,7 @@ describe("BasemapStyleSession", () => {
8385 startTime : MOCK_START_TIME ,
8486 endTime : MOCK_END_TIME ,
8587 expires : new Date ( MOCK_END_TIME . getTime ( ) - DEFAULT_SAFETY_MARGIN * 1000 ) ,
86- authentication : "token"
88+ authentication : MOCK_AUTH
8789 } ) ;
8890
8991 expect ( session ) . toBeDefined ( ) ;
@@ -94,7 +96,7 @@ describe("BasemapStyleSession", () => {
9496 try {
9597 await BasemapStyleSession . start ( {
9698 duration : 9 ,
97- authentication : "token"
99+ authentication : MOCK_AUTH
98100 } ) ;
99101 } catch ( error ) {
100102 expect ( error ) . toEqual (
@@ -107,7 +109,7 @@ describe("BasemapStyleSession", () => {
107109 try {
108110 await BasemapStyleSession . start ( {
109111 duration : 43201 ,
110- authentication : "token"
112+ authentication : MOCK_AUTH
111113 } ) ;
112114 } catch ( error ) {
113115 expect ( error ) . toEqual (
@@ -157,7 +159,7 @@ describe("BasemapStyleSession", () => {
157159 expect ( session . safetyMargin ) . toBe ( DEFAULT_SAFETY_MARGIN ) ;
158160 expect ( ( session as any ) . expirationCheckInterval ) . toBe ( 10000 ) ; // 10 seconds
159161 expect ( session . styleFamily ) . toBe ( "arcgis" ) ;
160- expect ( session . authentication ) . toBe ( "token" ) ;
162+ expect ( session . authentication ) . toBe ( MOCK_AUTH ) ;
161163 expect ( session . canRefresh ) . toBe ( true ) ;
162164 expect ( await session . getToken ( ) ) . toBe ( "fake-token" ) ;
163165 expect ( session . autoRefresh ) . toBe ( false ) ;
@@ -170,15 +172,15 @@ describe("BasemapStyleSession", () => {
170172
171173 expect ( url . startsWith ( DEFAULT_START_BASEMAP_STYLE_SESSION_URL ) ) . toBe ( true ) ;
172174 expect ( url ) . toContain ( "styleFamily=arcgis" ) ;
173- expect ( url ) . toContain ( "token=token" ) ;
175+ expect ( url ) . toContain ( "token=fake- token" ) ;
174176 expect ( url ) . toContain ( "durationSeconds=43200" ) ;
175177 expect ( url ) . toContain ( "f=json" ) ;
176178 } ) ;
177179
178180 test ( "should start a new BasemapStyleSession with a custom duration" , async ( ) => {
179181 const session = await startMockSession ( {
180182 duration : 60 ,
181- authentication : "token"
183+ authentication : MOCK_AUTH
182184 } ) ;
183185
184186 // Validate the session object
@@ -198,7 +200,7 @@ describe("BasemapStyleSession", () => {
198200 ) ;
199201 expect ( ( session as any ) . expirationCheckInterval ) . toBe ( 600 ) ;
200202 expect ( session . styleFamily ) . toBe ( "arcgis" ) ;
201- expect ( session . authentication ) . toBe ( "token" ) ;
203+ expect ( session . authentication ) . toBe ( MOCK_AUTH ) ;
202204 expect ( session . canRefresh ) . toBe ( true ) ;
203205 expect ( await session . getToken ( ) ) . toBe ( "fake-token" ) ;
204206 expect ( session . autoRefresh ) . toBe ( false ) ;
@@ -211,14 +213,14 @@ describe("BasemapStyleSession", () => {
211213
212214 expect ( url . startsWith ( DEFAULT_START_BASEMAP_STYLE_SESSION_URL ) ) . toBe ( true ) ;
213215 expect ( url ) . toContain ( "styleFamily=arcgis" ) ;
214- expect ( url ) . toContain ( "token=token" ) ;
216+ expect ( url ) . toContain ( "token=fake- token" ) ;
215217 expect ( url ) . toContain ( "durationSeconds=60" ) ;
216218 expect ( url ) . toContain ( "f=json" ) ;
217219 } ) ;
218220
219221 test ( "should start a new BasemapStyleSession with a custom safetyMargin" , async ( ) => {
220222 const session = await startMockSession ( {
221- authentication : "token" ,
223+ authentication : MOCK_AUTH ,
222224 safetyMargin : 600
223225 } ) ;
224226
@@ -239,7 +241,7 @@ describe("BasemapStyleSession", () => {
239241 ) ;
240242 expect ( ( session as any ) . expirationCheckInterval ) . toBe ( 10000 ) ;
241243 expect ( session . styleFamily ) . toBe ( "arcgis" ) ;
242- expect ( session . authentication ) . toBe ( "token" ) ;
244+ expect ( session . authentication ) . toBe ( MOCK_AUTH ) ;
243245 expect ( session . canRefresh ) . toBe ( true ) ;
244246 expect ( await session . getToken ( ) ) . toBe ( "fake-token" ) ;
245247 expect ( session . autoRefresh ) . toBe ( false ) ;
@@ -252,7 +254,7 @@ describe("BasemapStyleSession", () => {
252254
253255 expect ( url . startsWith ( DEFAULT_START_BASEMAP_STYLE_SESSION_URL ) ) . toBe ( true ) ;
254256 expect ( url ) . toContain ( "styleFamily=arcgis" ) ;
255- expect ( url ) . toContain ( "token=token" ) ;
257+ expect ( url ) . toContain ( "token=fake- token" ) ;
256258 expect ( url ) . toContain ( "durationSeconds=43200" ) ;
257259 expect ( url ) . toContain ( "f=json" ) ;
258260 } ) ;
@@ -266,7 +268,7 @@ describe("BasemapStyleSession", () => {
266268 } ) ;
267269
268270 const session = await BasemapStyleSession . start ( {
269- authentication : "token"
271+ authentication : MOCK_AUTH
270272 } ) ;
271273
272274 // Validate the session object
@@ -281,7 +283,7 @@ describe("BasemapStyleSession", () => {
281283 DEFAULT_START_BASEMAP_STYLE_SESSION_URL
282284 ) ;
283285 expect ( session . styleFamily ) . toBe ( "arcgis" ) ;
284- expect ( session . authentication ) . toBe ( "token" ) ;
286+ expect ( session . authentication ) . toBe ( MOCK_AUTH ) ;
285287 expect ( session . canRefresh ) . toBe ( true ) ;
286288 expect ( await session . getToken ( ) ) . toBe ( "fake-token" ) ;
287289 expect ( session . autoRefresh ) . toBe ( false ) ;
@@ -294,7 +296,7 @@ describe("BasemapStyleSession", () => {
294296
295297 expect ( url . startsWith ( DEFAULT_START_BASEMAP_STYLE_SESSION_URL ) ) . toBe ( true ) ;
296298 expect ( url ) . toContain ( "styleFamily=arcgis" ) ;
297- expect ( url ) . toContain ( "token=token" ) ;
299+ expect ( url ) . toContain ( "token=fake- token" ) ;
298300 expect ( url ) . toContain ( "durationSeconds=43200" ) ;
299301 expect ( url ) . toContain ( "f=json" ) ;
300302 } ) ;
0 commit comments