81 lines
3.6 KiB
TypeScript
81 lines
3.6 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import { env, subjects } from '../../support/auth-config';
|
|
import { GoTrueClient, randomEmail, randomPassword, validMetadata, waitMailInterval } from '../../support/gotrue';
|
|
import { expectMailCount, extractTokenHash, waitForMail } from '../../support/mailpit';
|
|
|
|
const gotrue = new GoTrueClient();
|
|
|
|
test.describe('KTO-01 Kriterium 11: Mails nur in der Profilsprache, nur die zwei Mailarten (api)', () => {
|
|
test('KTO-01 Kriterium 11: AUTH-CFG-17 locale=de -> deutsche Bestaetigungsmail', async () => {
|
|
const email = randomEmail();
|
|
await gotrue.signUp(email, randomPassword(), validMetadata({ locale: 'de' }));
|
|
const mail = await waitForMail(email);
|
|
expect(mail.Subject).toBe(subjects.confirmation.de);
|
|
expect(mail.html).toContain('<html lang="de">');
|
|
});
|
|
|
|
test('KTO-01 Kriterium 11: AUTH-CFG-17 locale=en -> englische Bestaetigungsmail', async () => {
|
|
const email = randomEmail();
|
|
await gotrue.signUp(email, randomPassword(), validMetadata({ locale: 'en' }));
|
|
const mail = await waitForMail(email);
|
|
expect(mail.Subject).toBe(subjects.confirmation.en);
|
|
expect(mail.html).toContain('<html lang="en">');
|
|
});
|
|
|
|
test('KTO-01 Kriterium 11: ohne locale -> Englisch (F6)', async () => {
|
|
const email = randomEmail();
|
|
await gotrue.signUp(email, randomPassword(), validMetadata({ locale: undefined }));
|
|
const mail = await waitForMail(email);
|
|
expect(mail.Subject).toBe(subjects.confirmation.en);
|
|
});
|
|
|
|
test('KTO-01 Kriterium 11: AUTH-CFG-18 Profilsprache auf en aendern -> Reset-Mail englisch; vorher deutsch', async () => {
|
|
const email = randomEmail();
|
|
const password = randomPassword();
|
|
const created = await gotrue.createConfirmedUser(email, password, validMetadata({ locale: 'de' }));
|
|
const userId = created.body.id as string;
|
|
|
|
await gotrue.recover(email);
|
|
const german = await waitForMail(email);
|
|
expect(german.Subject).toBe(subjects.recovery.de);
|
|
expect(german.html).toContain('<html lang="de">');
|
|
expect(extractTokenHash(german).type).toBe('recovery');
|
|
|
|
// Profilsprache wie die App ueber PostgREST mit dem Token des Nutzers aendern (Sync-Trigger -> user_metadata).
|
|
const token = (await gotrue.signIn(email, password)).body.access_token as string;
|
|
const patch = await fetch(`${env.supabaseUrl}/rest/v1/profiles?id=eq.${userId}`, {
|
|
method: 'PATCH',
|
|
headers: {
|
|
apikey: env.anonKey,
|
|
authorization: `Bearer ${token}`,
|
|
'content-type': 'application/json',
|
|
prefer: 'return=representation',
|
|
},
|
|
body: JSON.stringify({ locale: 'en' }),
|
|
});
|
|
expect(patch.status).toBe(200);
|
|
expect((await patch.json())[0].locale).toBe('en');
|
|
|
|
await waitMailInterval();
|
|
await gotrue.recover(email);
|
|
const english = await waitForMail(email, 2);
|
|
expect(english.Subject).toBe(subjects.recovery.en);
|
|
expect(english.html).toContain('<html lang="en">');
|
|
});
|
|
|
|
test('KTO-01 Kriterium 11: AUTH-CFG-19 nach Reset und Login keine weitere Mail (Benachrichtigungen aus)', async () => {
|
|
const email = randomEmail();
|
|
const password = randomPassword();
|
|
await gotrue.createConfirmedUser(email, password);
|
|
|
|
await gotrue.recover(email);
|
|
const { tokenHash } = extractTokenHash(await waitForMail(email));
|
|
const session = await gotrue.verify(tokenHash, 'recovery');
|
|
const newPassword = randomPassword();
|
|
expect((await gotrue.updateUser(session.body.access_token, { password: newPassword })).status).toBe(200);
|
|
expect((await gotrue.signIn(email, newPassword)).status).toBe(200);
|
|
|
|
// Genau die eine Reset-Mail; keine password_changed-Benachrichtigung.
|
|
await expectMailCount(email, 1);
|
|
});
|
|
});
|