Skip to content

Commit 5c7135b

Browse files
razor-xseambotandrii-balitskyi
authored
test: Test other auth methods against fake-seam-connect (#150)
* Update fake-seam-connect * Test personal-access-token * Update tests to use seam_at1_token * Use consoleSessionToken in tests * Create client session with api key * Use correct token in test * ci: Generate code * Fix client-session-token authorized test * Update package.json * ci: Generate code * Bump fake-seam-connect to 1.74.0 * ci: Generate code * Update package.json * ci: Generate code --------- Co-authored-by: Seam Bot <[email protected]> Co-authored-by: Andrii Balitskyi <[email protected]> Co-authored-by: Seam Bot <[email protected]> Co-authored-by: Andrii Balitskyi <[email protected]>
1 parent e44cd01 commit 5c7135b

File tree

7 files changed

+322
-196
lines changed

7 files changed

+322
-196
lines changed

package-lock.json

Lines changed: 128 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@
9898
"axios-retry": "^4.4.2"
9999
},
100100
"devDependencies": {
101-
"@seamapi/fake-seam-connect": "1.71.0",
101+
"@seamapi/fake-seam-connect": "1.74.0",
102102
"@seamapi/types": "1.302.2",
103103
"@types/eslint": "^8.44.2",
104+
"@types/jsonwebtoken": "^9.0.6",
104105
"@types/node": "^20.8.10",
105106
"ava": "^5.0.1",
106107
"c8": "^10.1.2",
@@ -115,6 +116,7 @@
115116
"eslint-plugin-simple-import-sort": "^12.0.0",
116117
"eslint-plugin-unused-imports": "^3.0.0",
117118
"execa": "^9.2.0",
119+
"jsonwebtoken": "^9.0.2",
118120
"landlubber": "^2.0.0",
119121
"nock": "^13.4.0",
120122
"node-fetch": "^3.3.2",

test/seam/connect/client-session-token.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@ test('SeamHttp: updateClientSessionToken returns instance authorized with a new
5656
const seam = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, {
5757
endpoint,
5858
})
59-
const { token } = await seam.clientSessions.create({
59+
60+
const devices = await seam.devices.list()
61+
t.true(devices.length > 0)
62+
63+
const seamUsingApiKey = SeamHttp.fromApiKey(seed.seam_apikey2_token, {
64+
endpoint,
65+
})
66+
67+
const { token } = await seamUsingApiKey.clientSessions.create({
6068
user_identifier_key: 'some-new-user-identifier-key',
6169
})
6270

6371
await seam.updateClientSessionToken(token)
64-
const devices = await seam.devices.list()
65-
t.is(devices.length, 0)
72+
const devicesFromNewSession = await seam.devices.list()
73+
t.is(devicesFromNewSession.length, 0)
6674
})
6775

6876
test('SeamHttp: updateClientSessionToken fails if no existing clientSessionToken', async (t) => {
@@ -92,6 +100,5 @@ test('SeamHttp: updateClientSessionToken checks clientSessionToken is authorized
92100
instanceOf: SeamHttpApiError,
93101
},
94102
)
95-
t.is(err?.statusCode, 404)
96-
t.is(err?.code, 'client_session_token_not_found')
103+
t.is(err?.statusCode, 401)
97104
})

test/seam/connect/client.test.ts

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,54 +108,45 @@ test('SeamHttp: merges axios headers when creating client', async (t) => {
108108
t.is(device.device_id, seed.august_device_1)
109109
})
110110

111-
// UPSTREAM: Fake does not support personal access token.
112-
// https://github.com/seamapi/fake-seam-connect/issues/126
113-
test.failing(
114-
'SeamHttpMultiWorkspace: fromClient returns instance that uses client',
115-
async (t) => {
116-
const { endpoint } = await getTestServer(t)
117-
const seam = SeamHttpMultiWorkspace.fromClient(
118-
SeamHttpMultiWorkspace.fromPersonalAccessToken('seam_at_TODO', {
119-
endpoint,
120-
}).client,
121-
)
122-
const workspaces = await seam.workspaces.list()
123-
t.true(workspaces.length > 0)
124-
},
125-
)
111+
test('SeamHttpMultiWorkspace: fromClient returns instance that uses client', async (t) => {
112+
const { seed, endpoint } = await getTestServer(t)
113+
const seam = SeamHttpMultiWorkspace.fromClient(
114+
SeamHttpMultiWorkspace.fromPersonalAccessToken(seed.seam_at1_token, {
115+
endpoint,
116+
}).client,
117+
)
118+
const workspaces = await seam.workspaces.list()
119+
t.true(workspaces.length > 0)
120+
})
126121

127-
// UPSTREAM: Fake does not support personal access token.
128-
// https://github.com/seamapi/fake-seam-connect/issues/126
129-
test.failing(
130-
'SeamHttpMultiWorkspace: constructor returns instance that uses client',
131-
async (t) => {
132-
const { endpoint } = await getTestServer(t)
133-
const seam = new SeamHttpMultiWorkspace({
134-
client: SeamHttpMultiWorkspace.fromPersonalAccessToken('seam_at_TODO', {
122+
test('SeamHttpMultiWorkspace: constructor returns instance that uses client', async (t) => {
123+
const { seed, endpoint } = await getTestServer(t)
124+
const seam = new SeamHttpMultiWorkspace({
125+
client: SeamHttpMultiWorkspace.fromPersonalAccessToken(
126+
seed.seam_at1_token,
127+
{
135128
endpoint,
136-
}).client,
137-
})
138-
const workspaces = await seam.workspaces.list()
139-
t.true(workspaces.length > 0)
140-
},
141-
)
129+
},
130+
).client,
131+
})
132+
const workspaces = await seam.workspaces.list()
133+
t.true(workspaces.length > 0)
134+
})
142135

143-
// UPSTREAM: Fake does not support personal access token.
144-
// https://github.com/seamapi/fake-seam-connect/issues/126
145-
test.failing(
146-
'SeamHttpMultiWorkspace: can use client to make requests',
147-
async (t) => {
148-
const { endpoint } = await getTestServer(t)
149-
const seam = new SeamHttpMultiWorkspace({
150-
client: SeamHttpMultiWorkspace.fromPersonalAccessToken('seam_at_TODO', {
136+
test('SeamHttpMultiWorkspace: can use client to make requests', async (t) => {
137+
const { seed, endpoint } = await getTestServer(t)
138+
const seam = new SeamHttpMultiWorkspace({
139+
client: SeamHttpMultiWorkspace.fromPersonalAccessToken(
140+
seed.seam_at1_token,
141+
{
151142
endpoint,
152-
}).client,
153-
})
154-
const {
155-
data: { workspaces },
156-
status,
157-
} = await seam.client.get<WorkspacesListResponse>('/workspaces/list')
158-
t.is(status, 200)
159-
t.true(workspaces.length > 0)
160-
},
161-
)
143+
},
144+
).client,
145+
})
146+
const {
147+
data: { workspaces },
148+
status,
149+
} = await seam.client.get<WorkspacesListResponse>('/workspaces/list')
150+
t.is(status, 200)
151+
t.true(workspaces.length > 0)
152+
})

0 commit comments

Comments
 (0)