mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(packing): accept weight, bag and quantity on create across REST, MCP and plugin RPC (#2154)
This commit is contained in:
@@ -19,6 +19,28 @@ describe('packingCreateItemRequestSchema', () => {
|
||||
).toBe(true);
|
||||
expect(packingCreateItemRequestSchema.safeParse({ name: '' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('carries weight_grams, bag_id and quantity like the update schema (#2154)', () => {
|
||||
const parsed = packingCreateItemRequestSchema.safeParse({
|
||||
name: 'Tent',
|
||||
weight_grams: 300,
|
||||
bag_id: 19,
|
||||
quantity: 3,
|
||||
});
|
||||
expect(parsed.success).toBe(true);
|
||||
expect(parsed.success && parsed.data).toEqual({ name: 'Tent', weight_grams: 300, bag_id: 19, quantity: 3 });
|
||||
// Nullable, mirroring the update contract.
|
||||
expect(packingCreateItemRequestSchema.safeParse({ name: 'Tent', weight_grams: null, bag_id: null }).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(packingCreateItemRequestSchema.safeParse({ name: 'Tent', bag_id: 'carry-on' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('still strips unknown keys — camelCase was never part of the contract', () => {
|
||||
const parsed = packingCreateItemRequestSchema.safeParse({ name: 'Tent', weightGrams: 300, bagId: 19 });
|
||||
expect(parsed.success).toBe(true);
|
||||
expect(parsed.success && parsed.data).toEqual({ name: 'Tent' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('packingImportRequestSchema', () => {
|
||||
@@ -36,6 +58,16 @@ describe('packingCreateBagRequestSchema', () => {
|
||||
expect(packingCreateBagRequestSchema.safeParse({ name: 'Carry-on' }).success).toBe(true);
|
||||
expect(packingCreateBagRequestSchema.safeParse({}).success).toBe(false);
|
||||
});
|
||||
|
||||
it('carries weight_limit_grams like the update schema (#2154)', () => {
|
||||
const parsed = packingCreateBagRequestSchema.safeParse({ name: 'Backpack', weight_limit_grams: 8000 });
|
||||
expect(parsed.success).toBe(true);
|
||||
expect(parsed.success && parsed.data).toEqual({ name: 'Backpack', weight_limit_grams: 8000 });
|
||||
expect(packingCreateBagRequestSchema.safeParse({ name: 'Backpack', weight_limit_grams: null }).success).toBe(true);
|
||||
expect(packingCreateBagRequestSchema.safeParse({ name: 'Backpack', weight_limit_grams: 'heavy' }).success).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('packingSaveTemplateRequestSchema', () => {
|
||||
|
||||
@@ -86,6 +86,11 @@ export const packingCreateItemRequestSchema = z.object({
|
||||
category: z.string().optional(),
|
||||
// The legacy route accepted both boolean and 0/1 for checked — both stay valid.
|
||||
checked: z.union([z.boolean(), z.number().int().min(0).max(1)]).optional(),
|
||||
// Same shapes as the update schema below (#2154) — the create route used to
|
||||
// strip these three silently, forcing a second write to set them.
|
||||
weight_grams: z.number().nullable().optional(),
|
||||
bag_id: z.number().nullable().optional(),
|
||||
quantity: z.number().optional(),
|
||||
// Mark the new item private to its creator (#858, legacy flag).
|
||||
is_private: z.boolean().optional(),
|
||||
// Three-tier sharing (#858): which list the item belongs to, and — for 'shared' —
|
||||
@@ -128,6 +133,8 @@ export type PackingReorderRequest = z.infer<typeof packingReorderRequestSchema>;
|
||||
export const packingCreateBagRequestSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
color: z.string().optional(),
|
||||
// Same shape as the update schema below (#2154) — POST used to strip it.
|
||||
weight_limit_grams: z.number().nullable().optional(),
|
||||
});
|
||||
export type PackingCreateBagRequest = z.infer<typeof packingCreateBagRequestSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user