Skip to content

Commit

Permalink
Add test for api key
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Oct 3, 2023
1 parent ed5c6aa commit 138731c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"axios": "^1.5.0"
},
"devDependencies": {
"@seamapi/fake-seam-connect": "^1.15.1",
"@seamapi/fake-seam-connect": "^1.16.0",
"@seamapi/types": "^1.14.0",
"@types/eslint": "^8.44.2",
"@types/node": "^18.11.18",
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/seam/connect/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createFake, type Seed } from '@seamapi/fake-seam-connect'
import type { ExecutionContext } from 'ava'

export const getTestServer = async (
t: ExecutionContext,
): Promise<{ endpoint: string; seed: Seed }> => {
const fake = await createFake()

await fake.startServer()

t.teardown(async () => {
await fake.stopServer()
})

const seed = await fake.seed()
const endpoint = fake.serverUrl

if (endpoint == null) throw new Error('Fake endpoint is null')
const res = await fetch(`${endpoint}/health`)
if (!res.ok) throw new Error('Fake Seam Connect unhealthy')

return {
endpoint,
seed,
}
}
13 changes: 13 additions & 0 deletions test/seam/connect/api-key.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import test from 'ava'
import { getTestServer } from 'fixtures/seam/connect/api.js'

import { SeamHttp } from '@seamapi/http/connect'

test('SeamHttp: fromApiKey', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const client = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const workspace = await client.devices.get({
device_id: seed.august_device_1,
})
t.is(workspace.workspace_id, seed.seed_workspace_1)
})
7 changes: 0 additions & 7 deletions test/seam/connect/client.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"paths": {
"@seamapi/http": ["./src/index.ts"],
"@seamapi/http/connect": ["./src/connect.ts"],
"fixtures/*": ["./test/fixtures/*"],
"lib/*": ["./src/lib/*"]
}
},
Expand Down

0 comments on commit 138731c

Please sign in to comment.