Skip to content

Commit d8173ea

Browse files
authored
Merge pull request #68 from WildCodeSchool/dev
Dev vers staging
2 parents feacf88 + d87871b commit d8173ea

34 files changed

+2260
-94
lines changed

backend/src/services/groupMemberService.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,35 @@ type RemoveMembersInput = {
1414

1515
/**
1616
* Add users to a group from a list of emails.
17-
* - Silently skips emails that do not match a user.
17+
* - Add emails to a pending invitation list if they do not exist in the db.
1818
*/
1919
export async function addMembersToGroup({ userEmails, groupId }: AddMembersInput) {
2020
if (!userEmails.length) return;
2121

2222
await Promise.all(
2323
userEmails.map(async (userEmail) => {
2424
const userToAdd = await User.findOne({ where: { email: userEmail } });
25-
const userPending = await PendingInvitation.findOne({ where: { userEmail: userEmail } });
26-
if (!userToAdd && !userPending) {
27-
// if the user does not exist in the db, add it to the pendinginvitationList
28-
const pendingInvitation = PendingInvitation.create({
29-
userEmail: userEmail,
30-
groupId,
25+
26+
//If the user exists in the db, check if they are already a member of the group and if not, add them to the group
27+
if (userToAdd) {
28+
const existingMember = await GroupMember.findOne({
29+
where: { userId: userToAdd.id, groupId },
3130
});
31+
if (existingMember) return;
3232

33-
await pendingInvitation.save();
33+
const groupMember = GroupMember.create({ userId: userToAdd.id, groupId });
34+
await groupMember.save();
3435
return;
3536
}
3637

37-
const groupMember = GroupMember.create({
38-
userId: userToAdd?.id,
39-
groupId,
38+
//If the user does not exist in the db, check if they are already in the pendinginvitationList and if not, add them to the pendinginvitationList
39+
const userPending = await PendingInvitation.findOne({
40+
where: { userEmail, groupId },
4041
});
42+
if (userPending) return;
4143

42-
await groupMember.save();
44+
const pendingInvitation = PendingInvitation.create({ userEmail, groupId });
45+
await pendingInvitation.save();
4346
}),
4447
);
4548
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

frontend/.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25-
.env
25+
.env
26+
27+
# Playwright
28+
/test-results/
29+
/playwright-report/
30+
/blob-report/
31+
/playwright/.cache/
32+
/playwright/.auth/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
function generateRandomEmail() {
4+
return `test-${Math.random()}@example.com`;
5+
}
6+
7+
const randomEmail = generateRandomEmail();
8+
9+
test('inscription', async ({ page }) => {
10+
await page.goto('http://localhost:3000/');
11+
12+
// Vérifier que la homepage est chargée
13+
await expect(page.getByRole('heading', { name: 'Le site magique pour ne plus se prendre la tête pour les cadeaux communs.', level: 1 })).toBeVisible();
14+
15+
// Inscription
16+
await page.getByRole('link', { name: 'Inscription' }).click();
17+
await expect(page.getByRole('heading', { name: 'Créer mon compte', level: 2 })).toBeVisible();
18+
19+
// Remplir le formulaire d'inscription
20+
await page.getByTestId('lastNameRegister').fill('Doe');
21+
await page.getByTestId('firstNameRegister').fill('John');
22+
await page.getByTestId('emailRegister').fill(randomEmail);
23+
await page.getByTestId('birthdayRegister').fill('1990-01-01');
24+
await page.getByTestId('passwordRegister').fill('Unmdp123!');
25+
await page.getByTestId('passwordConfirmRegister').fill('Unmdp123!');
26+
await page.getByTestId('buttonRegister').click();
27+
28+
// Vérifier que l'utilisateur est redirigé vers le dashboard
29+
await expect(page.getByRole('heading', { name: 'Mes groupes', level: 2 })).toBeVisible();
30+
await expect(page.getByText('Aucun groupe de discussion')).toBeVisible();
31+
await expect(page.getByRole('button', { name: 'Créer un groupe' })).toBeVisible();
32+
33+
// Accéder au profil
34+
await page.getByTestId('[object Object]').nth(2).click();
35+
await expect(page.getByRole('heading', { name: 'Mon profil', level: 1 })).toBeVisible();
36+
37+
// Modifier le profil
38+
const btnModifier = page.getByRole('button', { name: 'Modifier mes infos' });
39+
await btnModifier.scrollIntoViewIfNeeded();
40+
await btnModifier.click();
41+
42+
// Remplir le formulaire de modification
43+
await page.getByTestId('firstName').fill('Jane');
44+
await page.getByTestId('email').fill('jane.doe@example.com');
45+
await page.getByTestId('phoneNumber').fill('1234567890');
46+
await page.getByTestId('birthday').fill('1990-01-01');
47+
48+
await page.getByRole('button', { name: 'Enregistrer' }).click();
49+
await expect(page.getByText('Profil mis à jour avec succès !')).toBeVisible();
50+
51+
// Supprimer le profil
52+
const btnSupprimer = page.getByRole('button', { name: 'Supprimer mon profil' });
53+
await btnSupprimer.scrollIntoViewIfNeeded();
54+
await btnSupprimer.click();
55+
56+
// Vérifier que le modal de suppression est ouvert
57+
await expect(page.getByTestId('modal-delete-profile')).toBeVisible();
58+
await page.getByRole('button', { name: 'Confirmer' }).click();
59+
60+
61+
// Vérifier que l'utilisateur est déconnecté
62+
await expect(page.getByText('Votre profil a bien été supprimé.')).toBeVisible();
63+
await expect(page.url()).toBe('http://localhost:3000/');
64+
await expect(page.getByRole('link', { name: 'Connexion' })).toBeVisible();
65+
await expect(page.getByRole('link', { name: 'Inscription' })).toBeVisible();
66+
67+
});
68+

0 commit comments

Comments
 (0)