Skip to content

Commit a636089

Browse files
committed
clean up mock handlers
1 parent 1dbd08c commit a636089

File tree

5 files changed

+16
-27
lines changed

5 files changed

+16
-27
lines changed

app/pages/settings/AccessTokensPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function AccessTokensPage() {
5858
doDelete: () => deleteToken({ path: { tokenId: token.id } }),
5959
label: token.id,
6060
extraContent:
61-
'This cannot be undone. Any application or instances of the Oxide CLI that depends on this token will need a new one.',
61+
'This cannot be undone. Any application or instance of the Oxide CLI that depends on this token will need a new one.',
6262
}),
6363
},
6464
],

mock-api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './sled'
2424
export * from './snapshot'
2525
export * from './sshKeys'
2626
export * from './switch'
27+
export * from './token'
2728
export * from './user'
2829
export * from './user-group'
2930
export * from './vpc'

mock-api/msw/db.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { commaSeries } from '~/util/str'
1919

2020
import type { Json } from '../json-type'
2121
import { siloSettings } from '../silo'
22-
import { deviceTokens } from '../token'
2322
import { internalError } from './util'
2423

2524
export const notFoundErr = (msg: string) => {
@@ -478,7 +477,7 @@ const initDb = {
478477
affinityGroupMemberLists: [...mock.affinityGroupMemberLists],
479478
antiAffinityGroups: [...mock.antiAffinityGroups],
480479
antiAffinityGroupMemberLists: [...mock.antiAffinityGroupMemberLists],
481-
deviceTokens: [...deviceTokens],
480+
deviceTokens: [...mock.deviceTokens],
482481
disks: [...mock.disks],
483482
diskBulkImportState: new Map<string, DiskBulkImport>(),
484483
floatingIps: [...mock.floatingIps],

mock-api/msw/handlers.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,15 @@ export const handlers = makeHandlers({
14191419

14201420
return body
14211421
},
1422+
// assume every silo has a settings entry in both of these
1423+
authSettingsUpdate({ body }) {
1424+
const settings = db.siloSettings.find((s) => s.silo_id === defaultSilo.id)!
1425+
settings.device_token_max_ttl_seconds = body.device_token_max_ttl_seconds
1426+
return settings
1427+
},
1428+
authSettingsView() {
1429+
return db.siloSettings.find((s) => s.silo_id === defaultSilo.id)!
1430+
},
14221431
rackList: ({ query, cookies }) => {
14231432
requireFleetViewer(cookies)
14241433
return paginated(query, db.racks)
@@ -1458,14 +1467,10 @@ export const handlers = makeHandlers({
14581467
return 204
14591468
},
14601469
currentUserAccessTokenDelete({ path }) {
1461-
// Mock delete token - find and remove from mock tokens
14621470
db.deviceTokens = db.deviceTokens.filter((token) => token.id !== path.tokenId)
14631471
return 204
14641472
},
1465-
currentUserAccessTokenList({ query }) {
1466-
// Mock token list - return dummy tokens for current user
1467-
return paginated(query, db.deviceTokens)
1468-
},
1473+
currentUserAccessTokenList: ({ query }) => paginated(query, db.deviceTokens),
14691474
sledView({ path, cookies }) {
14701475
requireFleetViewer(cookies)
14711476
return lookup.sled(path)
@@ -1873,22 +1878,6 @@ export const handlers = makeHandlers({
18731878
rackView: NotImplemented,
18741879
roleList: NotImplemented,
18751880
roleView: NotImplemented,
1876-
authSettingsUpdate({ body }) {
1877-
// Find settings for default silo (assume it exists)
1878-
const settingsIndex = db.siloSettings.findIndex((s) => s.silo_id === defaultSilo.id)
1879-
1880-
// Update existing settings
1881-
db.siloSettings[settingsIndex] = {
1882-
...db.siloSettings[settingsIndex],
1883-
device_token_max_ttl_seconds: body.device_token_max_ttl_seconds,
1884-
}
1885-
return db.siloSettings[settingsIndex]
1886-
},
1887-
authSettingsView() {
1888-
// Find settings for default silo (assume it exists)
1889-
const settings = db.siloSettings.find((s) => s.silo_id === defaultSilo.id)!
1890-
return settings
1891-
},
18921881
siloPolicyUpdate: NotImplemented,
18931882
siloPolicyView: NotImplemented,
18941883
siloUserList: NotImplemented,

mock-api/token.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import type { Json } from './json-type'
1111

1212
export const deviceTokens: Json<DeviceAccessToken>[] = [
1313
{
14-
id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
14+
id: '6e762538-dd89-454e-b6e7-82a199b6e51a',
1515
time_created: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), // 7 days ago
1616
time_expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(), // 30 days from now
1717
},
1818
{
19-
id: 'b2c3d4e5-f6g7-8901-bcde-f23456789012',
19+
id: '9c858b30-bb11-4596-8c5e-c2bf1a26843e',
2020
time_created: new Date(Date.now() - 14 * 24 * 60 * 60 * 1000).toISOString(), // 14 days ago
2121
time_expires: new Date(Date.now() + 60 * 24 * 60 * 60 * 1000).toISOString(), // 60 days from now
2222
},
2323
{
24-
id: 'c3d4e5f6-g7h8-9012-cdef-345678901234',
24+
id: '29b1d980-e0d3-4318-b714-4a1f3e7b191f',
2525
time_created: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString(), // 3 days ago
2626
time_expires: null, // Never expires
2727
},

0 commit comments

Comments
 (0)