@@ -8,11 +8,13 @@ import { SeamHttp, SeamHttpInvalidOptionsError } from '@seamapi/http/connect'
88/*
99 * Tests in this file must run serially to ensure a clean environment for each test.
1010 */
11- test . afterEach ( ( ) => {
11+ const cleanupEnv = ( ) : void => {
1212 delete env . SEAM_API_KEY
1313 delete env . SEAM_ENDPOINT
1414 delete env . SEAM_API_URL
15- } )
15+ }
16+ test . afterEach ( cleanupEnv )
17+ test . beforeEach ( cleanupEnv )
1618
1719test . serial (
1820 'SeamHttp: constructor uses SEAM_API_KEY environment variable' ,
@@ -32,7 +34,7 @@ test.serial(
3234 'SeamHttp: apiKey option overrides environment variables' ,
3335 async ( t ) => {
3436 const { seed, endpoint } = await getTestServer ( t )
35- env . SEAM_API_KEY = 'some-invalid-api-key'
37+ env . SEAM_API_KEY = 'some-invalid-api-key-1 '
3638 const seam = new SeamHttp ( { apiKey : seed . seam_apikey1_token , endpoint } )
3739 const device = await seam . devices . get ( {
3840 device_id : seed . august_device_1 ,
@@ -45,7 +47,7 @@ test.serial(
4547test . serial (
4648 'SeamHttp: apiKey option as first argument overrides environment variables' ,
4749 ( t ) => {
48- env . SEAM_API_KEY = 'some-invalid-api-key'
50+ env . SEAM_API_KEY = 'some-invalid-api-key-2 '
4951 const seam = new SeamHttp ( 'seam_apikey_token' )
5052 t . truthy ( seam )
5153 } ,
@@ -70,17 +72,6 @@ test.serial(
7072 } ,
7173)
7274
73- test . serial (
74- 'SeamHttp: constructor throws if SEAM_API_KEY environment variable is used with clientSessionToken' ,
75- ( t ) => {
76- env . SEAM_API_KEY = 'seam_apikey_token'
77- t . throws ( ( ) => new SeamHttp ( { clientSessionToken : 'seam_cst1_token' } ) , {
78- instanceOf : SeamHttpInvalidOptionsError ,
79- message : / a p i K e y / ,
80- } )
81- } ,
82- )
83-
8475test . serial (
8576 'SeamHttp: SEAM_ENDPOINT environment variable is used first' ,
8677 async ( t ) => {
@@ -140,6 +131,39 @@ test.serial(
140131 } ,
141132)
142133
134+ test . serial (
135+ 'SeamHttp: constructor ignores SEAM_API_KEY environment variable if used with clientSessionToken' ,
136+ async ( t ) => {
137+ const { seed, endpoint } = await getTestServer ( t )
138+ env . SEAM_API_KEY = 'some-invalid-api-key-3'
139+ const seam = new SeamHttp ( {
140+ clientSessionToken : seed . seam_cst1_token ,
141+ endpoint,
142+ } )
143+ const device = await seam . devices . get ( {
144+ device_id : seed . august_device_1 ,
145+ } )
146+ t . is ( device . workspace_id , seed . seed_workspace_1 )
147+ t . is ( device . device_id , seed . august_device_1 )
148+ } ,
149+ )
150+
151+ test . serial (
152+ 'SeamHttp: SEAM_API_KEY environment variable is ignored with fromClientSessionToken' ,
153+ async ( t ) => {
154+ const { seed, endpoint } = await getTestServer ( t )
155+ env . SEAM_API_KEY = 'some-invalid-api-key-4'
156+ const seam = SeamHttp . fromClientSessionToken ( seed . seam_cst1_token , {
157+ endpoint,
158+ } )
159+ const device = await seam . devices . get ( {
160+ device_id : seed . august_device_1 ,
161+ } )
162+ t . is ( device . workspace_id , seed . seed_workspace_1 )
163+ t . is ( device . device_id , seed . august_device_1 )
164+ } ,
165+ )
166+
143167test . serial (
144168 'SeamHttp: SEAM_ENDPOINT environment variable is used with fromClientSessionToken' ,
145169 async ( t ) => {
0 commit comments