pwa and mobile client

This commit is contained in:
azykov@mail.ru
2026-09-29 15:55:25 +03:00
parent 657009bd6c
commit 1935acf2ff
96 changed files with 8370 additions and 58 deletions
+2
View File
@@ -17,6 +17,7 @@ const cardSchema = z.object({
color: z.string(),
code: z.coerce.string(),
codeType: z.enum(CODE_TYPES),
comment: z.string().default(''),
logo: imageRefSchema.nullable().default(null),
images: z.array(imageRefSchema).default([]),
imagesVersion: z.number().int().default(0),
@@ -110,6 +111,7 @@ export class CardsService {
const card: Card = {
id,
...fields,
comment: fields.comment ?? '',
logo: logoRef,
images: [],
imagesVersion: logoRef ? 1 : 0,
+28
View File
@@ -124,6 +124,34 @@ describe('client API', () => {
expect((await theirs('DELETE', `/cards/${mine.id}`)).statusCode).toBe(404);
});
it('stores a multiline comment and keeps it on partial updates', async () => {
const { app, key } = await setup();
const api = client(app, key);
const comment = 'Line one\nLine two\n\n indented';
const created = (await api('POST', '/cards', [...cardParts(), { name: 'comment', value: ' Line one\r\nLine two\r\n\r\n indented\n' }])).json() as Card;
expect(created.comment).toBe(comment);
const renamed = (await api('PUT', `/cards/${created.id}`, [{ name: 'name', value: 'Renamed' }])).json() as Card;
expect(renamed.comment).toBe(comment);
const cleared = (await api('PUT', `/cards/${created.id}`, [{ name: 'comment', value: '' }])).json() as Card;
expect(cleared.comment).toBe('');
expect((await api('PUT', `/cards/${created.id}`, [{ name: 'comment', value: 'x'.repeat(2001) }])).statusCode).toBe(400);
const withoutComment = (await api('POST', '/cards', cardParts())).json() as Card;
expect(withoutComment.comment).toBe('');
const patched = await app.inject({
method: 'PATCH',
url: `/admin/cards/${created.id}`,
headers: adminHeaders,
payload: { comment: 'From admin\nsecond line' },
});
expect((patched.json() as Card).comment).toBe('From admin\nsecond line');
});
it('returns JSON 404 for unknown API routes', async () => {
const { app, key } = await setup();
const res = await client(app, key)('GET', '/nope');