Skip to content

Commit 09da201

Browse files
committed
test(e2e): add onboarding test with existing account when accepting invitation
1 parent 6406179 commit 09da201

File tree

1 file changed

+63
-33
lines changed

1 file changed

+63
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,71 @@
11
import { expect } from '@playwright/test';
22

3+
import { useLoggedUser } from '../helpers/auth.ts';
34
import { databaseBuilder } from '../helpers/db.ts';
45
import { test } from '../helpers/fixtures.ts';
56

6-
test('Join an organization without having an account', async function ({ page }) {
7-
const invitation = databaseBuilder.factory.buildOrganizationInvitation();
8-
await databaseBuilder.commit();
9-
10-
await page.goto(`/rejoindre?invitationId=${invitation.id}&code=${invitation.code}`);
11-
12-
await expect(page.getByText('Vous êtes invité(e) à')).toBeVisible();
13-
await page.getByRole('textbox', { name: 'Prénom' }).fill('mini');
14-
await page.getByRole('textbox', { name: 'Nom', exact: true }).fill('pixou');
15-
await page.getByRole('textbox', { name: 'Adresse e-mail' }).fill('minipixou@example.net');
16-
await page.getByRole('textbox', { name: 'Mot de passe' }).fill('Azerty123*');
17-
await page.getByRole('checkbox', { name: "Accepter les conditions d'utilisation de Pix" }).check();
18-
await page.getByRole('button', { name: "Je m'inscris" }).click();
19-
await page.getByRole('heading', { name: "Veuillez accepter nos Conditions Générales d'Utilisation" }).waitFor();
20-
await page.getByRole('button', { name: 'Accepter et continuer' }).click();
21-
await expect(page.getByRole('heading', { name: 'Campagnes' })).toBeVisible();
7+
test.describe('when user is not authenticated', () => {
8+
test('Join an organization without having an account', async function ({ page }) {
9+
const invitation = databaseBuilder.factory.buildOrganizationInvitation();
10+
await databaseBuilder.commit();
11+
12+
await page.goto(`/rejoindre?invitationId=${invitation.id}&code=${invitation.code}`);
13+
14+
await expect(page.getByText('Vous êtes invité(e) à')).toBeVisible();
15+
await page.getByRole('textbox', { name: 'Prénom' }).fill('mini');
16+
await page.getByRole('textbox', { name: 'Nom', exact: true }).fill('pixou');
17+
await page.getByRole('textbox', { name: 'Adresse e-mail' }).fill('minipixou@example.net');
18+
await page.getByRole('textbox', { name: 'Mot de passe' }).fill('Azerty123*');
19+
await page.getByRole('checkbox', { name: "Accepter les conditions d'utilisation de Pix" }).check();
20+
await page.getByRole('button', { name: "Je m'inscris" }).click();
21+
await page.getByRole('heading', { name: "Veuillez accepter nos Conditions Générales d'Utilisation" }).waitFor();
22+
await page.getByRole('button', { name: 'Accepter et continuer' }).click();
23+
await expect(page.getByRole('heading', { name: 'Campagnes' })).toBeVisible();
24+
});
25+
26+
test('Join an organization with an existing account', async function ({ page }) {
27+
const invitation = databaseBuilder.factory.buildOrganizationInvitation();
28+
databaseBuilder.factory.buildUser.withRawPassword({
29+
email: 'random-account@example.net',
30+
});
31+
await databaseBuilder.commit();
32+
33+
await page.goto(`/rejoindre?invitationId=${invitation.id}&code=${invitation.code}`);
34+
35+
await page.getByRole('button', { name: 'Se connecter' }).click();
36+
await page.getByRole('textbox', { name: 'Adresse e-mail' }).fill('random-account@example.net');
37+
await page.getByRole('textbox', { name: 'Mot de passe' }).fill('pix123');
38+
await page.getByRole('button', { name: 'Je me connecte' }).click();
39+
await expect(
40+
page.getByRole('heading', { name: "Veuillez accepter nos Conditions Générales d'Utilisation" }),
41+
).toBeVisible();
42+
await page.getByRole('button', { name: 'Accepter et continuer' }).click();
43+
await expect(page.getByRole('heading', { name: 'Campagnes' })).toBeVisible();
44+
});
2245
});
23-
test('Join an organization with an existing account', async function ({ page }) {
24-
const invitation = databaseBuilder.factory.buildOrganizationInvitation();
25-
databaseBuilder.factory.buildUser.withRawPassword({
26-
email: 'random-account@example.net',
46+
47+
test.describe('when user is authenticated', () => {
48+
const userId = useLoggedUser('pix-orga');
49+
50+
test('Join an organization with an existing account', async function ({ page }) {
51+
const invitation = databaseBuilder.factory.buildOrganizationInvitation();
52+
databaseBuilder.factory.buildUser.withMembership({
53+
id: userId,
54+
email: 'already-connected@example.net',
55+
});
56+
await databaseBuilder.commit();
57+
58+
await page.goto(`/rejoindre?invitationId=${invitation.id}&code=${invitation.code}`);
59+
await page.getByRole('button', { name: 'Se connecter' }).click();
60+
await page.getByRole('textbox', { name: 'Adresse e-mail' }).fill('already-connected@example.net');
61+
await page.getByRole('textbox', { name: 'Mot de passe' }).fill('pix123');
62+
await page.getByRole('button', { name: 'Je me connecte' }).click();
63+
64+
await expect(
65+
page.getByRole('heading', { name: "Veuillez accepter nos Conditions Générales d'Utilisation" }),
66+
).toBeVisible();
67+
await page.getByRole('button', { name: 'Accepter et continuer' }).click();
68+
await expect(page.getByRole('heading', { name: 'Campagnes' })).toBeVisible();
69+
await expect(page.getByRole('paragraph').filter({ hasText: 'Observatoire de Pix' })).toBeVisible();
2770
});
28-
await databaseBuilder.commit();
29-
30-
await page.goto(`/rejoindre?invitationId=${invitation.id}&code=${invitation.code}`);
31-
32-
await page.getByRole('button', { name: 'Se connecter' }).click();
33-
await page.getByRole('textbox', { name: 'Adresse e-mail' }).fill('random-account@example.net');
34-
await page.getByRole('textbox', { name: 'Mot de passe' }).fill('pix123');
35-
await page.getByRole('button', { name: 'Je me connecte' }).click();
36-
await expect(
37-
page.getByRole('heading', { name: "Veuillez accepter nos Conditions Générales d'Utilisation" }),
38-
).toBeVisible();
39-
await page.getByRole('button', { name: 'Accepter et continuer' }).click();
40-
await expect(page.getByRole('heading', { name: 'Campagnes' })).toBeVisible();
4171
});

0 commit comments

Comments
 (0)