Skip to content

Commit a6bb1bc

Browse files
committed
Add test for retries
1 parent de7184d commit a6bb1bc

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

package-lock.json

Lines changed: 4 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
@@ -88,7 +88,7 @@
8888
"axios-retry": "^3.8.0"
8989
},
9090
"devDependencies": {
91-
"@seamapi/fake-seam-connect": "^1.21.0",
91+
"@seamapi/fake-seam-connect": "^1.22.0",
9292
"@seamapi/types": "^1.24.0",
9393
"@types/eslint": "^8.44.2",
9494
"@types/node": "^18.11.18",

test/fixtures/seam/connect/api.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import { createFake, type Seed } from '@seamapi/fake-seam-connect'
1+
import {
2+
createFake,
3+
type Database,
4+
type Seed,
5+
} from '@seamapi/fake-seam-connect'
26
import type { ExecutionContext } from 'ava'
37
import fetch from 'node-fetch' // TODO: Remove node-fetch when Node v16 support is dropped.
48

59
export const getTestServer = async (
610
t: ExecutionContext,
7-
): Promise<{ endpoint: string; seed: Seed }> => {
11+
): Promise<{
12+
endpoint: string
13+
seed: Seed
14+
db: Database
15+
}> => {
816
const fake = await createFake()
917
const seed = await fake.seed()
1018

@@ -21,5 +29,6 @@ export const getTestServer = async (
2129
return {
2230
endpoint,
2331
seed,
32+
db: fake.database,
2433
}
2534
}

test/seam/connect/retry.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import test from 'ava'
2+
import { AxiosError } from 'axios'
3+
import { getTestServer } from 'fixtures/seam/connect/api.js'
4+
5+
import { SeamHttp } from '@seamapi/http/connect'
6+
7+
test('SeamHttp: retries 503 status errors twice by default ', async (t) => {
8+
const { seed, endpoint, db } = await getTestServer(t)
9+
10+
db.simulateWorkspaceOutage(seed.seed_workspace_1, {
11+
routes: ['/devices/get'],
12+
})
13+
14+
t.plan(4)
15+
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {
16+
endpoint,
17+
axiosRetryOptions: {
18+
onRetry: (retryCount) => {
19+
t.true(retryCount < 3)
20+
},
21+
},
22+
})
23+
24+
const err = await t.throwsAsync(
25+
async () =>
26+
// UPSTREAM: This test should use seam.devices.get({ device_id: '...' }).
27+
// Only idempotent methods, e.g., GET not POST, are retried by default.
28+
// The SDK should use GET over POST once that method is supported upstream.
29+
// https://github.com/seamapi/nextlove/issues/117
30+
await seam.client.get('/devices/get', {
31+
params: {
32+
device_id: seed.august_device_1,
33+
},
34+
}),
35+
{ instanceOf: AxiosError },
36+
)
37+
38+
t.is(err?.response?.status, 503)
39+
})

0 commit comments

Comments
 (0)