capgo and adk autoupdates. card tags
This commit is contained in:
@@ -18,6 +18,7 @@ const cardSchema = z.object({
|
||||
code: z.coerce.string(),
|
||||
codeType: z.enum(CODE_TYPES),
|
||||
comment: z.string().default(''),
|
||||
tags: z.array(z.string()).default([]),
|
||||
logo: imageRefSchema.nullable().default(null),
|
||||
images: z.array(imageRefSchema).default([]),
|
||||
imagesVersion: z.number().int().default(0),
|
||||
@@ -112,6 +113,7 @@ export class CardsService {
|
||||
id,
|
||||
...fields,
|
||||
comment: fields.comment ?? '',
|
||||
tags: fields.tags ?? [],
|
||||
logo: logoRef,
|
||||
images: [],
|
||||
imagesVersion: logoRef ? 1 : 0,
|
||||
|
||||
@@ -152,6 +152,33 @@ describe('client API', () => {
|
||||
expect((patched.json() as Card).comment).toBe('From admin\nsecond line');
|
||||
});
|
||||
|
||||
it('parses comma-separated tags and keeps them on partial updates', async () => {
|
||||
const { app, key } = await setup();
|
||||
const api = client(app, key);
|
||||
|
||||
const created = (await api('POST', '/cards', [...cardParts(), { name: 'tags', value: 'один,,, два' }])).json() as Card;
|
||||
expect(created.tags).toEqual(['один', 'два']);
|
||||
|
||||
const renamed = (await api('PUT', `/cards/${created.id}`, [{ name: 'name', value: 'Renamed' }])).json() as Card;
|
||||
expect(renamed.tags).toEqual(['один', 'два']);
|
||||
|
||||
const retagged = (await api('PUT', `/cards/${created.id}`, [{ name: 'tags', value: ' food , ,pharmacy ' }])).json() as Card;
|
||||
expect(retagged.tags).toEqual(['food', 'pharmacy']);
|
||||
|
||||
const cleared = (await api('PUT', `/cards/${created.id}`, [{ name: 'tags', value: '' }])).json() as Card;
|
||||
expect(cleared.tags).toEqual([]);
|
||||
|
||||
expect((await api('POST', '/cards', cardParts())).json()).toMatchObject({ tags: [] });
|
||||
|
||||
const patched = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: `/admin/cards/${created.id}`,
|
||||
headers: adminHeaders,
|
||||
payload: { tags: [' a ', '', 'b, c'] },
|
||||
});
|
||||
expect((patched.json() as Card).tags).toEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('returns JSON 404 for unknown API routes', async () => {
|
||||
const { app, key } = await setup();
|
||||
const res = await client(app, key)('GET', '/nope');
|
||||
|
||||
Reference in New Issue
Block a user