Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Ajout de tests automatiques pour toutes les vues #84

Merged
merged 9 commits into from
Jul 23, 2020
Merged

Conversation

alemangui
Copy link
Collaborator

@alemangui alemangui commented Jul 22, 2020

Ce PR ajoute des tests automatiques pour toutes les vues - en mode authentifié et anonyme.

Les tests automatiques n'appellent aucun service web externe (OVH et l'API users est mocké).

Nock est ajouté en tant que dev-dependency pour mocker des requêtes externes et bloquer toute tentative de requête qui n'a pas été mocké.

Ce PR ajoute aussi une configuration VScode additionnelle pour permettre aux devs de mettre des points d'arrêt pour la commande de test.

Le seul commit contenant du code hors /tests est 68c8ba5 - qui fixe juste un paramètre dans un console.log. Tout le reste est dans /tests

@alemangui
Copy link
Collaborator Author

alemangui commented Jul 22, 2020

Les tests (visibles sur les checks Github) incluent maintenant :

Emails
    GET /emails unauthenticated
      ✓ should redirect to login
    GET /emails authenticated
      ✓ should return a valid page

  Home
    GET / unauthenticated
      ✓ should return valid page
      ✓ should include a login form
    GET / authenticated
      ✓ should redirect to users page

  User
    GET /users/:name unauthenticated
      ✓ should redirect to login
    GET /users authenticated
      ✓ should return a valid page
      ✓ should include the user's information
      ✓ should include an email creation form for email-less users
      ✓ should not include an email creation form for users with existing emails
      ✓ should show the user an email redirection form
      ✓ should not show an email redirection form to other users
    POST /users/:id/email unauthenticated
      ✓ should redirect to login
    POST /users/:id/email authenticated
      ✓ should ask OVH to create an email
    POST /users/:id/redirections unauthenticated
      ✓ should redirect to login
    POST /users/:id/redirections authenticated
      ✓ should ask OVH to create a redirection
    POST /users/:id/redirections/:email/delete unauthenticated
      ✓ should redirect to login
    POST /users/:id/redirections/:email/delete authenticated
      ✓ should ask OVH to delete a redirection

  Users
    GET /users unauthenticated
      ✓ should redirect to login
    GET /users authenticated
      ✓ should return a valid page
      ✓ should include a search form

@alemangui alemangui changed the title Ajoute de tests automatiques pour toutes les vues Ajout de tests automatiques pour toutes les vues Jul 22, 2020
@alemangui alemangui requested a review from jdauphant July 22, 2020 16:47
Copy link
Member

@jdauphant jdauphant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est super.
C'est peut être le moment de corriger les noms dans les tests ("jenexistepas.test" )

tests/utils.js Outdated

module.exports = {
getJWT() {
return jwt.sign({ id: 'jenexistepas.test' }, process.env.SESSION_SECRET, { expiresIn: '1 hours' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est peut être le moment de clarifier les id (c'est l'époque de mes tests en prod ^^), "jenexistepas.test" -> "utilisateur.valide"

on pourrait avoir "utilisateur.parti"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En effet ^^ noms mis à jour sur 9662c9c (utilisateur.actif et utilisateur.parti)

.type('form')
.send({
'_method': 'POST',
'to_email': 'test@test.com'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je dérecommande les emails avec un domaine qu'on ne contrôle pas.
Il y a example.com prévu par l'icann pour ça ou sinon un de nos domaines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tout à fait ! example.com utilisé sur le commit 9662c9c

@alemangui alemangui merged commit 147a42c into master Jul 23, 2020
@alemangui alemangui deleted the task/add-tests branch July 23, 2020 15:52
describe("POST /users/:id/redirections/:email/delete unauthenticated", () => {
it("should redirect to login", (done) => {
chai.request(app)
.post('/users/utilisateur.parti/redirections/test@email.com/delete')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alemangui tu as oublié celui là 🙄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants