feat(recipes): send null instead of undefined for blank serves/cookTimeMin
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -72,8 +72,8 @@ export const actions: Actions = {
|
|||||||
params: { path: { id: params.id } },
|
params: { path: { id: params.id } },
|
||||||
body: {
|
body: {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
serves: serves ? Number(serves) || undefined : undefined,
|
serves: serves ? Number(serves) || null : null,
|
||||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || undefined : undefined,
|
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || null : null,
|
||||||
effort,
|
effort,
|
||||||
heroImageUrl,
|
heroImageUrl,
|
||||||
ingredients: (parsedIngredients as { name: string; quantity: string; unit: string }[])
|
ingredients: (parsedIngredients as { name: string; quantity: string; unit: string }[])
|
||||||
|
|||||||
@@ -178,6 +178,19 @@ describe('edit recipe page — update action', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sends null for serves and cookTimeMin when fields are blank', async () => {
|
||||||
|
mockPut.mockResolvedValue({ error: undefined });
|
||||||
|
const fd = makeFormData({ serves: '', cookTimeMin: '' });
|
||||||
|
await actions.update({
|
||||||
|
request: { formData: async () => fd },
|
||||||
|
fetch: vi.fn(),
|
||||||
|
params: { id: 'r1' }
|
||||||
|
} as any).catch(() => {});
|
||||||
|
const body = mockPut.mock.calls[0][1].body;
|
||||||
|
expect(body.serves).toBeNull();
|
||||||
|
expect(body.cookTimeMin).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('sends heroImageUrl in PUT body when provided', async () => {
|
it('sends heroImageUrl in PUT body when provided', async () => {
|
||||||
mockPut.mockResolvedValue({ error: undefined });
|
mockPut.mockResolvedValue({ error: undefined });
|
||||||
const fd = makeFormData({ heroImageUrl: 'data:image/jpeg;base64,abc123' });
|
const fd = makeFormData({ heroImageUrl: 'data:image/jpeg;base64,abc123' });
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ export const actions: Actions = {
|
|||||||
const { error: apiError } = await api.POST('/v1/recipes', {
|
const { error: apiError } = await api.POST('/v1/recipes', {
|
||||||
body: {
|
body: {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
serves: serves ? Number(serves) || undefined : undefined,
|
serves: serves ? Number(serves) || null : null,
|
||||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || undefined : undefined,
|
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || null : null,
|
||||||
effort,
|
effort,
|
||||||
heroImageUrl,
|
heroImageUrl,
|
||||||
ingredients: (parsedIngredients as { name: string; quantity: string; unit: string }[])
|
ingredients: (parsedIngredients as { name: string; quantity: string; unit: string }[])
|
||||||
|
|||||||
@@ -145,6 +145,15 @@ describe('new recipe page — create action', () => {
|
|||||||
expect(mockPost).toHaveBeenCalledWith('/v1/recipes', expect.objectContaining({ body: expect.objectContaining({ name: 'Test Rezept', effort: 'easy' }) }));
|
expect(mockPost).toHaveBeenCalledWith('/v1/recipes', expect.objectContaining({ body: expect.objectContaining({ name: 'Test Rezept', effort: 'easy' }) }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sends null for serves and cookTimeMin when fields are blank', async () => {
|
||||||
|
mockPost.mockResolvedValue({ error: undefined });
|
||||||
|
const fd = makeFormData({ serves: '', cookTimeMin: '' });
|
||||||
|
await actions.create({ request: { formData: async () => fd }, fetch: vi.fn() } as any).catch(() => {});
|
||||||
|
const body = mockPost.mock.calls[0][1].body;
|
||||||
|
expect(body.serves).toBeNull();
|
||||||
|
expect(body.cookTimeMin).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('sends heroImageUrl in POST body when provided', async () => {
|
it('sends heroImageUrl in POST body when provided', async () => {
|
||||||
mockPost.mockResolvedValue({ error: undefined });
|
mockPost.mockResolvedValue({ error: undefined });
|
||||||
const fd = makeFormData({ heroImageUrl: 'data:image/jpeg;base64,abc123' });
|
const fd = makeFormData({ heroImageUrl: 'data:image/jpeg;base64,abc123' });
|
||||||
|
|||||||
Reference in New Issue
Block a user