-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute des tests end-to-end pour les audits et rapports (#894)
* add basic test * test audit edition * test audit deletion * improve seeds generation and document it * add notes test * add statement test * move tests documentation in cypress folder * add copy audit, criteria search and hide references tests * add tests commands * make getbylabel accept regex * test filters, download, transverse status, finish audit, na on topic and reset filters features * add some report tests * seed an audit before each test * seed audits for report tests * use object options in create test audit and fix wait tests * document tests script and command * add todo tests * fix regex in test to catch finish date on audit overview page * add account creation tests * handle error where user login with wrong token format * test user login and settings actions * temp: to reset * remove unecessary create test account function * use debug api endpoints to generate test audits * test audits list page * update tests doc * lint * only import debug controller on certain condition * remove faker * remove cypress boilerplate files --------- Co-authored-by: Adrien Boutigny <[email protected]>
- Loading branch information
1 parent
b6391eb
commit 9435124
Showing
40 changed files
with
1,502 additions
and
2,341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import { Body, Controller, Post } from "@nestjs/common"; | ||
import { PrismaService } from "./prisma.service"; | ||
import { AuthService } from "./auth/auth.service"; | ||
import { | ||
CriterionResultStatus, | ||
CriterionResultUserImpact | ||
} from "@prisma/client"; | ||
import { nanoid } from "nanoid"; | ||
import { CRITERIA } from "./audits/criteria"; | ||
|
||
@Controller("debug") | ||
export class DebugController { | ||
constructor( | ||
private readonly prisma: PrismaService, | ||
private readonly auth: AuthService | ||
) {} | ||
|
||
@Post("verification-token") | ||
async getAccountVerificationToken(@Body() body: { username: string }) { | ||
const token = this.auth.regenerateVerificationToken(body.username); | ||
return token; | ||
} | ||
|
||
@Post("password-reset-verification-token") | ||
async getPasswordResetVerificationToken(@Body() body: { username: string }) { | ||
const token = this.auth.generatePasswordResetVerificationToken( | ||
body.username | ||
); | ||
|
||
return token; | ||
} | ||
|
||
@Post("email-update-verification-token") | ||
async getEmailUpdateVerificationToken(@Body() body: { uid: string }) { | ||
const token = this.auth.regenerateEmailUpdateVerificationToken(body.uid); | ||
|
||
return token; | ||
} | ||
|
||
@Post("create-verified-user") | ||
async createVerifiedUser() { | ||
const email = `john-doe${Math.random()}@example.com`; | ||
const password = "pouetpouetpouet"; | ||
|
||
await this.auth.createUnverifiedUser(email, password); | ||
const user = await this.prisma.user.update({ | ||
data: { | ||
isVerified: true, | ||
verificationJti: null | ||
}, | ||
where: { | ||
username: email | ||
} | ||
}); | ||
|
||
const authToken = await this.auth.signin(email, password); | ||
|
||
return { | ||
username: email, | ||
password, | ||
authToken, | ||
uid: user.uid | ||
}; | ||
} | ||
|
||
@Post("create-audit") | ||
async createAudit( | ||
@Body() | ||
body: { | ||
isComplete: boolean; | ||
isPristine: boolean; | ||
noImprovements: boolean; | ||
auditorEmail?: string; | ||
} | ||
) { | ||
const editUniqueId = `edit-${nanoid()}`; | ||
const reportUniqueId = `report-${nanoid()}`; | ||
|
||
const completedAudit = await this.prisma.audit.create({ | ||
data: { | ||
editUniqueId: editUniqueId, | ||
consultUniqueId: reportUniqueId, | ||
creationDate: new Date(), | ||
publicationDate: body.isComplete ? new Date() : null, | ||
auditTrace: { | ||
create: { | ||
auditConsultUniqueId: editUniqueId, | ||
auditEditUniqueId: reportUniqueId | ||
} | ||
}, | ||
auditType: "FULL", | ||
procedureName: "Audit de mon petit site", | ||
auditorEmail: body.auditorEmail || "[email protected]", | ||
auditorName: "Étienne Durand", | ||
transverseElementsPage: { | ||
create: { | ||
name: "Éléments transverses", | ||
url: "" | ||
} | ||
}, | ||
pages: { | ||
createMany: { | ||
data: [ | ||
{ | ||
name: "Accueil", | ||
url: "https://example.com" | ||
}, | ||
{ | ||
name: "Contact", | ||
url: "https://example.com/contact" | ||
}, | ||
{ | ||
name: "À propos", | ||
url: "https://example.com/a-propos" | ||
}, | ||
{ | ||
name: "Blog", | ||
url: "https://example.com/blog" | ||
}, | ||
{ | ||
name: "Article", | ||
url: "https://example.com/blog/article" | ||
}, | ||
{ | ||
name: "Connexion", | ||
url: "https://example.com/connexion" | ||
}, | ||
{ | ||
name: "Documentation", | ||
url: "https://example.com/documentation" | ||
}, | ||
{ | ||
name: "FAQ", | ||
url: "https://example.com/faq" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
include: { | ||
transverseElementsPage: true | ||
} | ||
}); | ||
|
||
const auditPages = await this.prisma.auditedPage.findMany({ | ||
where: { | ||
auditUniqueId: editUniqueId | ||
} | ||
}); | ||
|
||
if (!body.isPristine) { | ||
await Promise.all( | ||
[completedAudit.transverseElementsPage, ...auditPages].map(async (p) => | ||
this.prisma.criterionResult.createMany({ | ||
data: CRITERIA.map((c, i) => ({ | ||
status: [ | ||
CriterionResultStatus.COMPLIANT, | ||
CriterionResultStatus.NOT_APPLICABLE, | ||
CriterionResultStatus.NOT_COMPLIANT | ||
][i % 3], | ||
notCompliantComment: "Une erreur ici", | ||
notApplicableComment: body.noImprovements | ||
? null | ||
: "Attention quand même si ça devient applicable", | ||
compliantComment: body.noImprovements ? null : "Peut mieux faire", | ||
quickWin: i % 7 === 0, | ||
userImpact: [ | ||
CriterionResultUserImpact.MINOR, | ||
CriterionResultUserImpact.MAJOR, | ||
CriterionResultUserImpact.BLOCKING, | ||
null | ||
][i % 4], | ||
topic: c.topic, | ||
criterium: c.criterium, | ||
pageId: p.id | ||
})) | ||
}) | ||
) | ||
); | ||
} | ||
|
||
if (!body.isComplete && !body.isPristine) { | ||
await this.prisma.criterionResult.delete({ | ||
where: { | ||
pageId_topic_criterium: { | ||
topic: 1, | ||
criterium: 1, | ||
pageId: auditPages[0].id | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
editId: editUniqueId, | ||
reportId: reportUniqueId | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
downloads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Tests end-to-end | ||
|
||
[Cypress](https://www.cypress.io/) est utilisé pour lancer des tests end-to-end (e2e) dans un navigateur pour reproduire le comportement des utilisateurs. | ||
|
||
En parallèle des tests, le serveur back-end doit être lancé avec la variable `DEBUG_ENDPOINTS` à `1` : | ||
|
||
```sh | ||
DEBUG_ENDPOINTS=1 yarn start:dev | ||
``` | ||
|
||
Différentes données (audit, rapport ou compte) sont créées avant chaque test et de manière indépendante. Il est possible d’ajouter des options en fonction de la donnée souhaitée avec les fonctions [`createTestAccount` et `createTestAudit()`](/cypress/support/commands.ts). | ||
|
||
Les tests peuvent être lancés de 2 manières, depuis la racine du projet : | ||
|
||
- Via l’application Cypress avec : | ||
|
||
```sh | ||
yarn tests:open | ||
``` | ||
|
||
- Via le terminal avec : | ||
|
||
```sh | ||
yarn tests:run | ||
``` | ||
|
||
## Guidelines | ||
|
||
- Cypress ne supporte pas la gestion des liens externes avec `target="_blank"`. Dans ce cas, il faut ajouter `.invoke("removeAttr", "target")` sur le lien avant de cliquer dessus. Exemple : | ||
|
||
```js | ||
cy.contains("a", "Compléter").invoke("removeAttr", "target").click(); | ||
``` | ||
|
||
- Il est préférable d'indique le type d’élément ciblé avec `contains()` pour s’assurer qu’il ne s’agisse pas d’un autre texte sur la page. Exemple : | ||
```js | ||
cy.contains("button", "Valider les paramètres").click(); | ||
``` |
Oops, something went wrong.