---
# System prepended metadata

title: 'Audioconf : Tasks refactor tests'

---

Audioconf : Tasks refactor tests
===

PR #1: Add 2 environements for knexfile

- KnexFile.js
    - return the client Knex for DATABASE_URL
- setup test.js
    - override DATABASE_URL with __test
- before/after : call a createDB, removeDB for each tests
- db.js
    - Replace the call of require("knex") in db.js by the call on knexfile.js
- knex.destroy destoys the connection pool. How to reinit it afterwards ?  

PR #2
- make 2 new folders test/unit and test/integration
- modify call in package.json with the test command with TEST_MODE=true
- modify node.js.yml to run also npm:integration

PR #3
- refactor job anonymizeConference to return a conferences (and not void)
- sendSurveyEmails 
    - must require emailer and not directly sendSurveyEmail to be mockable
    - use emails.length and remove nbEmails
- db.js.anonymizeConferences
    -  must return an empty array
 
PR #4
- refactor dbTest.js
- add lib/testUtils.js to reinit the test database

PR #5
- add anonymizeTest.js

PR #6
- add sendSurveyEmail.js

Questions
- certaines choses pas prévisibles: pas possible de mocker sendSurveyEmail directement, mais obligé de passer par l'objet emailer
- le mécanisme de réinit de la base, a marchoté pendant un certain temps et la solution a mis du temps à émerger.