37 lines
2.2 KiB
TypeScript
37 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getCollection } from '../../src/lib/server/fleet/collections.js';
|
|
import { load as collectionLoad } from '../../src/routes/collections/launches/[id]/+page.server.js';
|
|
import { load as provisioningCollectionLoad } from '../../src/routes/provisioning/collections/[id]/+page.server.js';
|
|
import { load as deploymentsLoad } from '../../src/routes/deployments/[...path]/+page.server.js';
|
|
|
|
vi.mock('../../src/lib/server/fleet/collections.js', () => ({ getCollection: vi.fn() }));
|
|
|
|
beforeEach(() => vi.resetAllMocks());
|
|
|
|
describe('collection launch routes', () => {
|
|
it('loads an existing launch at its Collections location and preserves missing-launch errors', () => {
|
|
vi.mocked(getCollection).mockReturnValue({ collection: { id: 'launch-123' } } as ReturnType<typeof getCollection>);
|
|
expect(collectionLoad({ params: { id: 'launch-123' } })).toEqual({});
|
|
expect(getCollection).toHaveBeenCalledWith('launch-123');
|
|
|
|
vi.mocked(getCollection).mockReturnValue(null);
|
|
expect(() => collectionLoad({ params: { id: 'missing' } })).toThrow(expect.objectContaining({ status: 404, body: { message: 'Collection not found.' } }));
|
|
});
|
|
|
|
it('redirects Provisioning collection bookmarks with the same ID and query parameters', () => {
|
|
expect(() => provisioningCollectionLoad({
|
|
params: { id: 'launch-123' },
|
|
url: new URL('http://localhost/provisioning/collections/launch-123?view=history&limit=50')
|
|
})).toThrow(expect.objectContaining({ status: 308, location: '/collections/launches/launch-123?view=history&limit=50' }));
|
|
expect(getCollection).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each([
|
|
['/deployments/collections/launch-123?limit=50&from=old%20link', '/collections/launches/launch-123?limit=50&from=old%20link'],
|
|
['/deployments/operation-123?from=collection', '/provisioning/operation-123?from=collection'],
|
|
['/deployments?action=create&limit=50', '/provisioning?action=create&limit=50']
|
|
])('keeps legacy %s bookmarks compatible', (path, location) => {
|
|
expect(() => deploymentsLoad({ url: new URL(path, 'http://localhost') })).toThrow(expect.objectContaining({ status: 308, location }));
|
|
});
|
|
});
|