feat(recipes): image upload, fix save 500, HelloFresh seed data #53
@@ -72,8 +72,8 @@ export const actions: Actions = {
|
||||
params: { path: { id: params.id } },
|
||||
body: {
|
||||
name: name.trim(),
|
||||
serves: serves ? Number(serves) || undefined : undefined,
|
||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || undefined : undefined,
|
||||
serves: serves ? Number(serves) || null : null,
|
||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || null : null,
|
||||
effort,
|
||||
heroImageUrl,
|
||||
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 () => {
|
||||
mockPut.mockResolvedValue({ error: undefined });
|
||||
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', {
|
||||
body: {
|
||||
name: name.trim(),
|
||||
serves: serves ? Number(serves) || undefined : undefined,
|
||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || undefined : undefined,
|
||||
serves: serves ? Number(serves) || null : null,
|
||||
cookTimeMin: cookTimeMin ? Number(cookTimeMin) || null : null,
|
||||
effort,
|
||||
heroImageUrl,
|
||||
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' }) }));
|
||||
});
|
||||
|
||||
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 () => {
|
||||
mockPost.mockResolvedValue({ error: undefined });
|
||||
const fd = makeFormData({ heroImageUrl: 'data:image/jpeg;base64,abc123' });
|
||||
|
||||
Reference in New Issue
Block a user