Skip to content

Commit 784ef62

Browse files
committed
Test clientSessionToken option parsing
1 parent a632dfc commit 784ef62

File tree

5 files changed

+77
-6
lines changed

5 files changed

+77
-6
lines changed

ava.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import { env } from 'node:process'
2+
13
export default () => {
4+
delete env.SEAM_API_KEY
5+
delete env.SEAM_ENDPOINT
6+
delete env.SEAM_API_URL
7+
28
return {
39
ignoredByWatcher: ['tmp/**/*'],
410
files: ['**/*.test.ts', '!package/**/*'],

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"axios": "^1.5.0"
8888
},
8989
"devDependencies": {
90-
"@seamapi/fake-seam-connect": "^1.17.0",
90+
"@seamapi/fake-seam-connect": "^1.18.0",
9191
"@seamapi/types": "^1.14.0",
9292
"@types/eslint": "^8.44.2",
9393
"@types/node": "^18.11.18",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import test from 'ava'
2+
import { getTestServer } from 'fixtures/seam/connect/api.js'
3+
4+
import { SeamHttp } from '@seamapi/http/connect'
5+
6+
import { SeamHttpInvalidTokenError } from 'lib/seam/connect/auth.js'
7+
8+
test('SeamHttp: fromClientSessionToken returns instance authorized with clientSessionToken', async (t) => {
9+
const { seed, endpoint } = await getTestServer(t)
10+
const client = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, {
11+
endpoint,
12+
})
13+
const device = await client.devices.get({
14+
device_id: seed.august_device_1,
15+
})
16+
t.is(device.workspace_id, seed.seed_workspace_1)
17+
t.is(device.device_id, seed.august_device_1)
18+
})
19+
20+
test('SeamHttp: constructor returns instance authorized with clientSessionToken', async (t) => {
21+
const { seed, endpoint } = await getTestServer(t)
22+
const client = new SeamHttp({
23+
clientSessionToken: seed.seam_cst1_token,
24+
endpoint,
25+
})
26+
const device = await client.devices.get({
27+
device_id: seed.august_device_1,
28+
})
29+
t.is(device.workspace_id, seed.seed_workspace_1)
30+
t.is(device.device_id, seed.august_device_1)
31+
})
32+
33+
test('SeamHttp: checks clientSessionToken format', (t) => {
34+
t.throws(() => SeamHttp.fromClientSessionToken('some-invalid-key-format'), {
35+
instanceOf: SeamHttpInvalidTokenError,
36+
message: /Unknown/,
37+
})
38+
t.throws(() => SeamHttp.fromClientSessionToken('seam_apikey_token'), {
39+
instanceOf: SeamHttpInvalidTokenError,
40+
message: /Unknown/,
41+
})
42+
t.throws(() => SeamHttp.fromClientSessionToken('ey'), {
43+
instanceOf: SeamHttpInvalidTokenError,
44+
message: /JWT/,
45+
})
46+
t.throws(() => SeamHttp.fromClientSessionToken('seam_at'), {
47+
instanceOf: SeamHttpInvalidTokenError,
48+
message: /Access Token/,
49+
})
50+
})

test/seam/connect/env.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test.serial(
7676
'SeamHttp: constructor throws if SEAM_API_KEY environment variable is used with clientSessionToken',
7777
(t) => {
7878
env.SEAM_API_KEY = 'seam_apikey_token'
79-
t.throws(() => new SeamHttp({ clientSessionToken: 'seam_cst_token' }), {
79+
t.throws(() => new SeamHttp({ clientSessionToken: 'seam_cst1_token' }), {
8080
instanceOf: SeamHttpInvalidOptionsError,
8181
message: /apiKey/,
8282
})
@@ -141,3 +141,18 @@ test.serial(
141141
t.is(device.device_id, seed.august_device_1)
142142
},
143143
)
144+
145+
test.serial(
146+
'SeamHttp: SEAM_ENDPOINT environment variable is used with fromClientSessionToken',
147+
async (t) => {
148+
const { seed, endpoint } = await getTestServer(t)
149+
env.SEAM_API_URL = 'https://example.com'
150+
env.SEAM_ENDPOINT = endpoint
151+
const client = SeamHttp.fromClientSessionToken(seed.seam_cst1_token)
152+
const device = await client.devices.get({
153+
device_id: seed.august_device_1,
154+
})
155+
t.is(device.workspace_id, seed.seed_workspace_1)
156+
t.is(device.device_id, seed.august_device_1)
157+
},
158+
)

0 commit comments

Comments
 (0)