import { expect, test } from '@playwright/test'; import { authConfig, triggerErrors } from '../../support/auth-config'; import { profileByEmail, userByEmail } from '../../support/db'; import { GoTrueClient, randomEmail, randomPassword, validMetadata } from '../../support/gotrue'; const gotrue = new GoTrueClient(); test.describe('KTO-01 Kriterium 10: Anzeigename (api)', () => { test('KTO-01 Kriterium 10: 31 Zeichen -> HTTP 500, Body {"code":"P0001","message":"display_name_invalid"}, kein Nutzer', async () => { const email = randomEmail(); const res = await gotrue.signUp( email, randomPassword(), validMetadata({ display_name: 'a'.repeat(authConfig.displayNameMaxLength + 1) }), ); // Format aus Spike B0 (f), Mapping-Regel 4.4: maßgeblich ist HTTP 500 beim signUp. expect(res.status).toBe(500); expect(res.body).toEqual({ code: 'P0001', message: triggerErrors.displayNameInvalid }); expect(res.headers.get('x-sb-error-code')).toBe('unexpected_failure'); expect(await userByEmail(email)).toBeUndefined(); }); for (const [label, value] of [ ['fehlend', undefined], ['leer', ''], ['nur Leerzeichen', ' '], ] as const) { test(`KTO-01 Kriterium 10: Anzeigename ${label} -> display_name_invalid`, async () => { const email = randomEmail(); const res = await gotrue.signUp(email, randomPassword(), validMetadata({ display_name: value })); expect(res.status).toBe(500); expect(res.body.message).toBe(triggerErrors.displayNameInvalid); expect(await userByEmail(email)).toBeUndefined(); }); } test('KTO-01 Kriterium 10: genau 30 Zeichen werden akzeptiert', async () => { const email = randomEmail(); const name = 'b'.repeat(authConfig.displayNameMaxLength); const res = await gotrue.signUp(email, randomPassword(), validMetadata({ display_name: name })); expect(res.status).toBe(200); expect((await profileByEmail(email)).display_name).toBe(name); }); test('KTO-01 Kriterium 10: Codepoints zaehlen, nicht UTF-16-Einheiten (30 Emoji ok, 31 abgelehnt)', async () => { const ok = randomEmail(); const accepted = await gotrue.signUp(ok, randomPassword(), validMetadata({ display_name: '😀'.repeat(30) })); expect(accepted.status).toBe(200); expect([...(await profileByEmail(ok)).display_name]).toHaveLength(30); const bad = randomEmail(); const rejected = await gotrue.signUp(bad, randomPassword(), validMetadata({ display_name: '😀'.repeat(31) })); expect(rejected.status).toBe(500); expect(rejected.body.message).toBe(triggerErrors.displayNameInvalid); }); test('KTO-01 Kriterium 10: Anzeigename wird getrimmt gespeichert; 30 Zeichen plus Rand-Leerzeichen sind zulaessig', async () => { const email = randomEmail(); const name = 'c'.repeat(authConfig.displayNameMaxLength); const res = await gotrue.signUp(email, randomPassword(), validMetadata({ display_name: ` ${name} ` })); expect(res.status).toBe(200); expect((await profileByEmail(email)).display_name).toBe(name); }); });