-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/instances/:id looks up instance and redirects to project instance route
- Loading branch information
1 parent
cfda163
commit 17149ab
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { redirect, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
||
import { apiQueryClient } from '@oxide/api' | ||
|
||
import { trigger404 } from 'app/components/ErrorBoundary' | ||
import { pb } from 'app/util/path-builder' | ||
|
||
export async function instanceLookupLoader({ params }: LoaderFunctionArgs) { | ||
try { | ||
const instance = await apiQueryClient.fetchQuery('instanceView', { | ||
path: { instance: params.instance! }, | ||
}) | ||
const project = await apiQueryClient.fetchQuery('projectView', { | ||
path: { project: instance.projectId }, | ||
}) | ||
return redirect(pb.instance({ project: project.name, instance: instance.name })) | ||
} catch (_e) { | ||
throw trigger404 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { expect, test } from '@playwright/test' | ||
|
||
test.describe('/lookup/i', () => { | ||
test('404s on existing name', async ({ page }) => { | ||
await page.goto('/lookup/i/db1') | ||
await expect(page.getByText('Page not found')).toBeVisible() | ||
}) | ||
|
||
test('404s on empty ID', async ({ page }) => { | ||
await page.goto('/lookup/i/') | ||
await expect(page.getByText('Page not found')).toBeVisible() | ||
}) | ||
|
||
test('looks up instance by ID', async ({ page }) => { | ||
await page.goto('/lookup/i/935499b3-fd96-432a-9c21-83a3dc1eece4') | ||
await expect(page).toHaveURL('/projects/mock-project/instances/db1/storage') | ||
}) | ||
}) | ||
|
||
test.describe('/lookup/instances', () => { | ||
test('404s on existing name', async ({ page }) => { | ||
await page.goto('/lookup/instances/db1') | ||
await expect(page.getByText('Page not found')).toBeVisible() | ||
}) | ||
|
||
test('404s on empty ID', async ({ page }) => { | ||
await page.goto('/lookup/instances/') | ||
await expect(page.getByText('Page not found')).toBeVisible() | ||
}) | ||
|
||
test('looks up instance by ID', async ({ page }) => { | ||
await page.goto('/lookup/instances/935499b3-fd96-432a-9c21-83a3dc1eece4') | ||
await expect(page).toHaveURL('/projects/mock-project/instances/db1/storage') | ||
}) | ||
}) |