Skip to content

Commit 0d2858f

Browse files
Tests should use /_fake endpoints instead of fake db instance (#139)
* Convert test/seam/connect/client-session-token.test.ts * Convert test/seam/connect/http-error.test.ts * Convert test/seam/connect/retry.test.ts * Convert test/seam/connect/serialization.test.ts * Convert test/seam/connect/wait-for-action-attempt.test.ts * Format * Update test/seam/connect/serialization.test.ts Co-authored-by: Evan Sosenko <[email protected]> * Update test/seam/connect/serialization.test.ts Co-authored-by: Evan Sosenko <[email protected]> --------- Co-authored-by: Evan Sosenko <[email protected]>
1 parent b27d73d commit 0d2858f

File tree

7 files changed

+38
-31
lines changed

7 files changed

+38
-31
lines changed

package-lock.json

Lines changed: 5 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
@@ -98,7 +98,7 @@
9898
"axios-retry": "^4.0.0"
9999
},
100100
"devDependencies": {
101-
"@seamapi/fake-seam-connect": "^1.44.2",
101+
"@seamapi/fake-seam-connect": "^1.71.0",
102102
"@seamapi/types": "1.187.0",
103103
"@types/eslint": "^8.44.2",
104104
"@types/node": "^20.8.10",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ test('SeamHttp: checks clientSessionToken format', (t) => {
5252
})
5353

5454
test('SeamHttp: updateClientSessionToken returns instance authorized with a new clientSessionToken', async (t) => {
55-
const { seed, endpoint, db } = await getTestServer(t)
55+
const { seed, endpoint } = await getTestServer(t)
5656
const seam = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, {
5757
endpoint,
5858
})
59-
const { token } = db.addClientSession({
60-
workspace_id: seed.seed_workspace_1,
59+
const { token } = await seam.clientSessions.create({
6160
user_identifier_key: 'some-new-user-identifier-key',
6261
})
62+
6363
await seam.updateClientSessionToken(token)
6464
const devices = await seam.devices.list()
6565
t.is(devices.length, 0)

test/seam/connect/http-error.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
} from '@seamapi/http/connect'
1111

1212
test('SeamHttp: throws AxiosError on non-standard response', async (t) => {
13-
const { seed, endpoint, db } = await getTestServer(t)
14-
15-
db.simulateWorkspaceOutage(seed.seed_workspace_1, {
16-
routes: ['/devices/list'],
17-
})
13+
const { seed, endpoint } = await getTestServer(t)
1814

1915
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
2016
endpoint,
@@ -23,6 +19,11 @@ test('SeamHttp: throws AxiosError on non-standard response', async (t) => {
2319
},
2420
})
2521

22+
await seam.client.post('/_fake/simulate_workspace_outage', {
23+
workspace_id: seed.seed_workspace_1,
24+
routes: ['/devices/list'],
25+
})
26+
2627
const err = await t.throwsAsync(async () => await seam.devices.list(), {
2728
instanceOf: AxiosError,
2829
})

test/seam/connect/retry.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ import { getTestServer } from 'fixtures/seam/connect/api.js'
55
import { SeamHttp } from '@seamapi/http/connect'
66

77
test('SeamHttp: retries 503 status errors twice by default ', async (t) => {
8-
const { seed, endpoint, db } = await getTestServer(t)
8+
const { seed, endpoint } = await getTestServer(t)
99
const expectedRetryCount = 2
1010

11-
db.simulateWorkspaceOutage(seed.seed_workspace_1, {
12-
routes: ['/devices/list'],
13-
})
14-
1511
t.plan(expectedRetryCount + 2)
1612

1713
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
@@ -23,6 +19,11 @@ test('SeamHttp: retries 503 status errors twice by default ', async (t) => {
2319
},
2420
})
2521

22+
await seam.client.post('/_fake/simulate_workspace_outage', {
23+
workspace_id: seed.seed_workspace_1,
24+
routes: ['/devices/list'],
25+
})
26+
2627
const err = await t.throwsAsync(
2728
// UPSTREAM: This test should use seam.devices.list().
2829
// Only idempotent methods, e.g., GET not POST, are retried by default.

test/seam/connect/serialization.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { getTestServer } from 'fixtures/seam/connect/api.js'
44
import { type DevicesListResponse, SeamHttp } from '@seamapi/http/connect'
55

66
test('serializes array params when undefined', async (t) => {
7-
const { seed, endpoint, db } = await getTestServer(t)
7+
const { seed, endpoint } = await getTestServer(t)
88
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
99
const devices = await seam.devices.list({
1010
device_ids: undefined,
1111
})
12+
const { data: db } = await seam.client.get('/_fake/database')
13+
1214
t.is(devices.length, db.devices.length)
1315
})
1416

@@ -33,14 +35,16 @@ test('serializes array params when non-empty', async (t) => {
3335
})
3436

3537
test('serializes array params when undefined and explicitly using get', async (t) => {
36-
const { seed, endpoint, db } = await getTestServer(t)
38+
const { seed, endpoint } = await getTestServer(t)
3739
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
3840
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
3941
params: {
4042
device_ids: undefined,
4143
},
4244
})
4345
const devices = data?.devices
46+
const { data: db } = await seam.client.get('/_fake/database')
47+
4448
t.is(devices.length, db.devices.length)
4549
})
4650

test/seam/connect/wait-for-action-attempt.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@seamapi/http/connect'
99

1010
test('waitForActionAttempt: waits for pending action attempt', async (t) => {
11-
const { seed, endpoint, db } = await getTestServer(t)
11+
const { seed, endpoint } = await getTestServer(t)
1212

1313
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
1414
endpoint,
@@ -21,13 +21,13 @@ test('waitForActionAttempt: waits for pending action attempt', async (t) => {
2121

2222
t.is(actionAttempt.status, 'pending')
2323

24-
db.updateActionAttempt({
24+
await seam.client.post('/_fake/update_action_attempt', {
2525
action_attempt_id: actionAttempt.action_attempt_id,
2626
status: 'pending',
2727
})
2828

2929
setTimeout(() => {
30-
db.updateActionAttempt({
30+
void seam.client.post('/_fake/update_action_attempt', {
3131
action_attempt_id: actionAttempt.action_attempt_id,
3232
status: 'success',
3333
})
@@ -45,7 +45,7 @@ test('waitForActionAttempt: waits for pending action attempt', async (t) => {
4545
})
4646

4747
test('waitForActionAttempt: returns successful action attempt', async (t) => {
48-
const { seed, endpoint, db } = await getTestServer(t)
48+
const { seed, endpoint } = await getTestServer(t)
4949

5050
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
5151
endpoint,
@@ -58,7 +58,7 @@ test('waitForActionAttempt: returns successful action attempt', async (t) => {
5858

5959
t.is(actionAttempt.status, 'pending')
6060

61-
db.updateActionAttempt({
61+
await seam.client.post('/_fake/update_action_attempt', {
6262
action_attempt_id: actionAttempt.action_attempt_id,
6363
status: 'success',
6464
})
@@ -85,7 +85,7 @@ test('waitForActionAttempt: returns successful action attempt', async (t) => {
8585
})
8686

8787
test('waitForActionAttempt: times out while waiting for action attempt', async (t) => {
88-
const { seed, endpoint, db } = await getTestServer(t)
88+
const { seed, endpoint } = await getTestServer(t)
8989

9090
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
9191
endpoint,
@@ -98,7 +98,7 @@ test('waitForActionAttempt: times out while waiting for action attempt', async (
9898

9999
t.is(actionAttempt.status, 'pending')
100100

101-
db.updateActionAttempt({
101+
await seam.client.post('/_fake/update_action_attempt', {
102102
action_attempt_id: actionAttempt.action_attempt_id,
103103
status: 'pending',
104104
})
@@ -122,7 +122,7 @@ test('waitForActionAttempt: times out while waiting for action attempt', async (
122122
})
123123

124124
test('waitForActionAttempt: rejects when action attempt fails', async (t) => {
125-
const { seed, endpoint, db } = await getTestServer(t)
125+
const { seed, endpoint } = await getTestServer(t)
126126

127127
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
128128
endpoint,
@@ -135,7 +135,7 @@ test('waitForActionAttempt: rejects when action attempt fails', async (t) => {
135135

136136
t.deepEqual(actionAttempt.status, 'pending')
137137

138-
db.updateActionAttempt({
138+
await seam.client.post('/_fake/update_action_attempt', {
139139
action_attempt_id: actionAttempt.action_attempt_id,
140140
status: 'error',
141141
error: {
@@ -163,7 +163,7 @@ test('waitForActionAttempt: rejects when action attempt fails', async (t) => {
163163
})
164164

165165
test('waitForActionAttempt: times out if waiting for polling interval', async (t) => {
166-
const { seed, endpoint, db } = await getTestServer(t)
166+
const { seed, endpoint } = await getTestServer(t)
167167

168168
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
169169
endpoint,
@@ -176,7 +176,7 @@ test('waitForActionAttempt: times out if waiting for polling interval', async (t
176176

177177
t.is(actionAttempt.status, 'pending')
178178

179-
db.updateActionAttempt({
179+
await seam.client.post('/_fake/update_action_attempt', {
180180
action_attempt_id: actionAttempt.action_attempt_id,
181181
status: 'pending',
182182
})

0 commit comments

Comments
 (0)