From 138731c9729bea3143a3ef23240afe72563d7de1 Mon Sep 17 00:00:00 2001 From: Evan Sosenko <evan@getseam.com> Date: Tue, 3 Oct 2023 16:27:39 -0700 Subject: [PATCH] Add test for api key --- package-lock.json | 8 ++++---- package.json | 2 +- test/fixtures/seam/connect/api.ts | 26 ++++++++++++++++++++++++++ test/seam/connect/api-key.test.ts | 13 +++++++++++++ test/seam/connect/client.test.ts | 7 ------- tsconfig.json | 1 + 6 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/seam/connect/api.ts create mode 100644 test/seam/connect/api-key.test.ts delete mode 100644 test/seam/connect/client.test.ts diff --git a/package-lock.json b/package-lock.json index 9b6abf8f..59cae540 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,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", @@ -791,9 +791,9 @@ } }, "node_modules/@seamapi/fake-seam-connect": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/@seamapi/fake-seam-connect/-/fake-seam-connect-1.15.1.tgz", - "integrity": "sha512-IVsetgmIB42qCl9EJwSLnz8aHzq/IkG61TwRLgudlo0g2ObZfASvw6e4FM+lkRhRZ5XpGBtaK9CG7wz1Pw8iig==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/@seamapi/fake-seam-connect/-/fake-seam-connect-1.16.0.tgz", + "integrity": "sha512-FMnYhMDMLI8BQdmKYFoctekeh+JLAmY/Kn+8MJ+YoxDm5SODgwzu0AjBwcuc8zjqmX4pG9psvkXQ2ZDynwuUGQ==", "dev": true, "bin": { "fake-seam-connect": "dist/server.js" diff --git a/package.json b/package.json index 7be1cb4b..d58f7268 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fixtures/seam/connect/api.ts b/test/fixtures/seam/connect/api.ts new file mode 100644 index 00000000..6c3902d6 --- /dev/null +++ b/test/fixtures/seam/connect/api.ts @@ -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, + } +} diff --git a/test/seam/connect/api-key.test.ts b/test/seam/connect/api-key.test.ts new file mode 100644 index 00000000..ea4d58f1 --- /dev/null +++ b/test/seam/connect/api-key.test.ts @@ -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) +}) diff --git a/test/seam/connect/client.test.ts b/test/seam/connect/client.test.ts deleted file mode 100644 index 5403e751..00000000 --- a/test/seam/connect/client.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import test from 'ava' - -import { SeamHttp } from '@seamapi/http/connect' - -test('SeamHttp: fromApiKey', (t) => { - t.truthy(SeamHttp.fromApiKey('seam_some-api-key')) -}) diff --git a/tsconfig.json b/tsconfig.json index e851ac74..d58978ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,7 @@ "paths": { "@seamapi/http": ["./src/index.ts"], "@seamapi/http/connect": ["./src/connect.ts"], + "fixtures/*": ["./test/fixtures/*"], "lib/*": ["./src/lib/*"] } },