Skip to content

Commit 77c6408

Browse files
committed
Add test for api key
1 parent ed5c6aa commit 77c6408

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

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.15.1",
90+
"@seamapi/fake-seam-connect": "^1.16.0",
9191
"@seamapi/types": "^1.14.0",
9292
"@types/eslint": "^8.44.2",
9393
"@types/node": "^18.11.18",

test/fixtures/seam/connect/api.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createFake, type Seed } from '@seamapi/fake-seam-connect'
2+
import type { ExecutionContext } from 'ava'
3+
4+
export const getTestServer = async (
5+
t: ExecutionContext,
6+
): Promise<{ endpoint: string; seed: Seed }> => {
7+
const fake = await createFake()
8+
const seed = await fake.seed()
9+
10+
await fake.startServer()
11+
t.teardown(async () => {
12+
await fake.stopServer()
13+
})
14+
15+
const endpoint = fake.serverUrl
16+
if (endpoint == null) throw new Error('Fake endpoint is null')
17+
const res = await fetch(`${endpoint}/health`)
18+
if (!res.ok) throw new Error('Fake Seam Connect unhealthy')
19+
20+
return {
21+
endpoint,
22+
seed,
23+
}
24+
}

test/seam/connect/api-key.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test from 'ava'
2+
import { getTestServer } from 'fixtures/seam/connect/api.js'
3+
4+
import { SeamHttp } from '@seamapi/http/connect'
5+
6+
test('SeamHttp: fromApiKey', async (t) => {
7+
const { seed, endpoint } = await getTestServer(t)
8+
const client = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
9+
const device = await client.devices.get({
10+
device_id: seed.august_device_1,
11+
})
12+
t.is(device.workspace_id, seed.seed_workspace_1)
13+
t.is(device.device_id, seed.august_device_1)
14+
})

test/seam/connect/client.test.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"paths": {
2727
"@seamapi/http": ["./src/index.ts"],
2828
"@seamapi/http/connect": ["./src/connect.ts"],
29+
"fixtures/*": ["./test/fixtures/*"],
2930
"lib/*": ["./src/lib/*"]
3031
}
3132
},

0 commit comments

Comments
 (0)