mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
44 lines
2.1 KiB
TypeScript
44 lines
2.1 KiB
TypeScript
import {
|
|
collectionDeleteManyRequestSchema,
|
|
collectionPlaceUpdateRequestSchema,
|
|
collectionReorderRequestSchema,
|
|
} from './collection.schema';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
describe('collectionPlaceUpdateRequestSchema', () => {
|
|
// Regression for #1437: an update that omits `status` must NOT inject a default
|
|
// of 'idea', otherwise the server overwrites the stored status on every edit-save.
|
|
it('does not inject a status when the field is absent', () => {
|
|
const parsed = collectionPlaceUpdateRequestSchema.parse({ name: 'Trevi Fountain' });
|
|
expect('status' in parsed).toBe(false);
|
|
expect(parsed.status).toBeUndefined();
|
|
});
|
|
|
|
it('passes through an explicitly provided status', () => {
|
|
expect(collectionPlaceUpdateRequestSchema.parse({ status: 'want' }).status).toBe('want');
|
|
expect(collectionPlaceUpdateRequestSchema.parse({ status: 'visited' }).status).toBe('visited');
|
|
});
|
|
|
|
it('catches an invalid status back to idea rather than throwing', () => {
|
|
expect(collectionPlaceUpdateRequestSchema.parse({ status: 'bogus' as never }).status).toBe('idea');
|
|
});
|
|
});
|
|
|
|
// The two ratchet schemas replace hand-rolled "array of numbers" checks — they
|
|
// must stay exactly that permissive (empty arrays included, no int/positive).
|
|
describe('collectionReorderRequestSchema / collectionDeleteManyRequestSchema', () => {
|
|
it('accepts any array of numbers, empty included', () => {
|
|
expect(collectionReorderRequestSchema.parse({ orderedIds: [] }).orderedIds).toEqual([]);
|
|
expect(collectionReorderRequestSchema.parse({ orderedIds: [3, 1, 2] }).orderedIds).toEqual([3, 1, 2]);
|
|
expect(collectionDeleteManyRequestSchema.parse({ ids: [] }).ids).toEqual([]);
|
|
expect(collectionDeleteManyRequestSchema.parse({ ids: [7] }).ids).toEqual([7]);
|
|
});
|
|
|
|
it('rejects non-arrays and non-numeric members', () => {
|
|
expect(() => collectionReorderRequestSchema.parse({ orderedIds: 'nope' })).toThrow();
|
|
expect(() => collectionReorderRequestSchema.parse({})).toThrow();
|
|
expect(() => collectionDeleteManyRequestSchema.parse({ ids: ['a'] })).toThrow();
|
|
});
|
|
});
|