Skip to content

Commit a0921bd

Browse files
committed
move msw handlers out of mock-api barrel file
1 parent 6ab60b9 commit a0921bd

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

app/api/__tests__/safety.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,26 @@ const grepFiles = (s: string) =>
3232
.split('\n')
3333
.filter((f) => !/safety\.spec\.ts/.test(f)) // this file doesn't count
3434

35-
it('@oxide/api-mocks is only referenced in test files', () => {
35+
it('mock-api is only referenced in test files', () => {
3636
expect(grepFiles('api-mocks')).toMatchInlineSnapshot(`
3737
[
3838
"app/api/__tests__/hooks.spec.tsx",
39-
"app/msw-mock-api.ts",
4039
"mock-api/msw/db.ts",
4140
"test/e2e/instance-create.e2e.ts",
4241
"test/e2e/inventory.e2e.ts",
4342
"test/e2e/profile.e2e.ts",
4443
"test/e2e/project-access.e2e.ts",
4544
"test/e2e/silo-access.e2e.ts",
45+
"tsconfig.json",
46+
]
47+
`)
48+
expect(grepFiles('mock-api')).toMatchInlineSnapshot(`
49+
[
50+
"README.md",
51+
"app/main.tsx",
52+
"app/msw-mock-api.ts",
53+
"docs/mock-api-differences.md",
54+
"package.json",
4655
"test/e2e/utils.ts",
4756
"test/unit/server.ts",
4857
"test/unit/setup.ts",

app/msw-mock-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const sleep = async (ms: number) => new Promise((res) => setTimeout(res, ms))
5656

5757
export async function startMockAPI() {
5858
// dynamic imports to make extremely sure none of this code ends up in the prod bundle
59-
const { handlers } = await import('@oxide/api-mocks')
59+
const { handlers } = await import('../mock-api/msw/handlers')
6060
const { http, HttpResponse } = await import('msw')
6161
const { setupWorker } = await import('msw/browser')
6262

mock-api/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ export * from './user'
2525
export * from './user-group'
2626
export * from './user'
2727
export * from './vpc'
28-
29-
export { handlers } from './msw/handlers'
30-
export { json, MSW_USER_COOKIE } from './msw/util'
31-
export { resetDb } from './msw/db'

mock-api/msw/db.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { validate as isUuid } from 'uuid'
1111

1212
import type { ApiTypes as Api, PathParams as PP } from '@oxide/api'
1313
import * as mock from '@oxide/api-mocks'
14-
import { user1 } from '@oxide/api-mocks'
1514
import { pick } from '@oxide/util'
1615

1716
import type { Json } from '../json-type'
@@ -223,7 +222,7 @@ export const lookup = {
223222
},
224223
sshKey({ sshKey: id }: PP.SshKey): Json<Api.SshKey> {
225224
// we don't have a concept of mock session. assume the user is user1
226-
const userSshKeys = db.sshKeys.filter((key) => key.silo_user_id === user1.id)
225+
const userSshKeys = db.sshKeys.filter((key) => key.silo_user_id === mock.user1.id)
227226

228227
if (isUuid(id)) return lookupById(userSshKeys, id)
229228

test/e2e/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
import { expect, type Browser, type Locator, type Page } from '@playwright/test'
99

10-
import { MSW_USER_COOKIE } from '@oxide/api-mocks'
1110
import { MiB } from '@oxide/util'
1211

12+
import { MSW_USER_COOKIE } from '../../mock-api/msw/util'
13+
1314
export * from '@playwright/test'
1415

1516
export async function forEach(loc: Locator, fn: (loc0: Locator, i: number) => void) {

test/unit/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { http, HttpResponse } from 'msw'
99
import { setupServer } from 'msw/node'
1010

11-
import { handlers } from '@oxide/api-mocks'
11+
import { handlers } from '../../mock-api/msw/handlers'
1212

1313
export const server = setupServer(
1414
...handlers.map((h) => {

test/unit/setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import '@testing-library/jest-dom/vitest'
1515
import { cleanup } from '@testing-library/react'
1616
import { afterAll, afterEach, beforeAll } from 'vitest'
1717

18-
import { resetDb } from '@oxide/api-mocks'
19-
18+
import { resetDb } from '../../mock-api/msw/db'
2019
import { server } from './server'
2120

2221
beforeAll(() => server.listen())

tools/start_mock_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { createServer } from '@mswjs/http-middleware'
99

10-
import { handlers } from '@oxide/api-mocks'
10+
import { handlers } from '../mock-api/msw/handlers'
1111

1212
// TODO: take port argument
1313
createServer(...handlers).listen(12220)

0 commit comments

Comments
 (0)