Skip to content

Commit

Permalink
Use consoleSessionToken in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Aug 5, 2024
1 parent 10234f8 commit 836e00f
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 74 deletions.
127 changes: 124 additions & 3 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
},
"dependencies": {
"@seamapi/url-search-params-serializer": "^1.1.0",
"@types/jsonwebtoken": "^9.0.6",
"axios": "^1.5.0",
"axios-better-stacktrace": "^2.1.7",
"axios-retry": "^4.4.2"
Expand All @@ -115,6 +116,7 @@
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"execa": "^9.2.0",
"jsonwebtoken": "^9.0.2",
"landlubber": "^2.0.0",
"nock": "^13.4.0",
"node-fetch": "^3.3.2",
Expand Down
144 changes: 81 additions & 63 deletions test/seam/connect/console-session-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
import test from 'ava'
import { getTestServer } from 'fixtures/seam/connect/api.js'
import jwt from 'jsonwebtoken'

import {
SeamHttp,
SeamHttpInvalidTokenError,
SeamHttpMultiWorkspace,
} from '@seamapi/http/connect'

// UPSTREAM: Fake does not support JWT.
// https://github.com/seamapi/fake-seam-connect/issues/124
test.failing(
'SeamHttp: fromConsoleSessionToken returns instance authorized with consoleSessionToken',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromConsoleSessionToken(
'ey_TODO',
seed.seed_workspace_1,
{
endpoint,
},
)
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
},
)
test('SeamHttp: fromConsoleSessionToken returns instance authorized with consoleSessionToken', async (t) => {
const { seed, endpoint } = await getTestServer(t)

// UPSTREAM: Fake does not support JWT.
// https://github.com/seamapi/fake-seam-connect/issues/124
test.failing(
'SeamHttp: constructor returns instance authorized with consoleSessionToken',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = new SeamHttp({
consoleSessionToken: 'ey_TODO',
workspaceId: seed.seed_workspace_1,
const consoleSessionToken = jwt.sign(
{
user_id: seed.john_user_id,
key: seed.john_user_key,
},
'secret',
)

const seam = SeamHttp.fromConsoleSessionToken(
consoleSessionToken,
seed.seed_workspace_1,
{
endpoint,
})
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
},
)
},
)
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
})

test('SeamHttp: constructor returns instance authorized with consoleSessionToken', async (t) => {
const { seed, endpoint } = await getTestServer(t)

const consoleSessionToken = jwt.sign(
{
user_id: seed.john_user_id,
key: seed.john_user_key,
},
'secret',
)

const seam = new SeamHttp({
consoleSessionToken,
workspaceId: seed.seed_workspace_1,
endpoint,
})
const device = await seam.devices.get({
device_id: seed.august_device_1,
})
t.is(device.workspace_id, seed.seed_workspace_1)
t.is(device.device_id, seed.august_device_1)
})

test('SeamHttp: checks consoleSessionToken format', (t) => {
const workspaceId = 'e4203e37-e569-4a5a-bfb7-e3e8de66161d'
Expand Down Expand Up @@ -74,34 +83,43 @@ test('SeamHttp: checks consoleSessionToken format', (t) => {
})
})

// UPSTREAM: Fake does not support JWT.
// https://github.com/seamapi/fake-seam-connect/issues/124
test.failing(
'SeamHttpMultiWorkspace: fromConsoleSessionToken returns instance authorized with consoleSessionToken',
async (t) => {
const { endpoint } = await getTestServer(t)
const seam = SeamHttpMultiWorkspace.fromConsoleSessionToken('ey_TODO', {
endpoint,
})
const workspaces = await seam.workspaces.list()
t.true(workspaces.length > 0)
},
)
test('SeamHttpMultiWorkspace: fromConsoleSessionToken returns instance authorized with consoleSessionToken', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const consoleSessionToken = jwt.sign(
{
user_id: seed.john_user_id,
key: seed.john_user_key,
},
'secret',
)

// UPSTREAM: Fake does not support JWT.
// https://github.com/seamapi/fake-seam-connect/issues/124
test.failing(
'SeamHttpMultiWorkspace: constructor returns instance authorized with consoleSessionToken',
async (t) => {
const { endpoint } = await getTestServer(t)
const seam = new SeamHttpMultiWorkspace({
consoleSessionToken: 'ey_TODO',
const seam = SeamHttpMultiWorkspace.fromConsoleSessionToken(
consoleSessionToken,
{
endpoint,
})
const workspaces = await seam.workspaces.list()
t.true(workspaces.length > 0)
},
)
},
)
const workspaces = await seam.workspaces.list()
t.true(workspaces.length > 0)
})

test('SeamHttpMultiWorkspace: constructor returns instance authorized with consoleSessionToken', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const consoleSessionToken = jwt.sign(
{
user_id: seed.john_user_id,
key: seed.john_user_key,
},
'secret',
)

const seam = new SeamHttpMultiWorkspace({
consoleSessionToken,
endpoint,
})
const workspaces = await seam.workspaces.list()
t.true(workspaces.length > 0)
})

test('SeamHttpMultiWorkspace: checks consoleSessionToken format', (t) => {
t.throws(
Expand Down
Loading

0 comments on commit 836e00f

Please sign in to comment.