systers / PC-Prep-Kit

PC Prep Kit is a web application aimed at educating Peace Corps Volunteers and increasing awareness about Malaria and its prevention techniques.
9 stars 34 forks source link

Using Mocks for Unit Tests with external Dependencies #107

Open paavininanda opened 6 years ago

paavininanda commented 6 years ago

Description

As a programmer, I need the unit tests to work properly, so that I can have the app function without any glitches. Currently one of the test related to authentication is failing -

Executing (default): SELECT id, fname, lname, email, password, verificationStatus, resetPasswordToken, resetPasswordExpires, provider, google_id, google_token FROM user_accounts AS user_account WHERE user_account.email = 'pcpreptest@send22u.info' LIMIT 1; POST /auth/login 200 6.072 ms - 61 1) "before all" hook: Login Executing (default): DELETE FROM user_accounts WHERE email = 'pcpreptest@send22u.info' 3 passing (275ms) 1 failing 1) Testing APIs Creating User Authentication "before all" hook: Login: Uncaught TypeError: Cannot read property 'email' of undefined at Test. (test/test.js:94:34) at Test.assert (node_modules/supertest/lib/test.js:179:6) at assert (node_modules/supertest/lib/test.js:131:12) at node_modules/supertest/lib/test.js:128:5 at Test.Request.callback (node_modules/superagent/lib/node/index.js:706:12) at parser (node_modules/superagent/lib/node/index.js:906:18) at IncomingMessage.res.on.e (node_modules/superagent/lib/node/parsers/json.js:19:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)

It is happening because we are calling a email API in the unit tests. We need to find another way to test this.

Acceptance Criteria

Update [Required]

Definition of Done

Estimation

1-2 hours

Buddhiprabha commented 6 years ago

@paavininanda are you working on this?

shreyans29 commented 6 years ago

@paavininanda I would suggest renaming it to "Using Mocks for Unit Tests with external Dependencies". It would be more generalized and will be true for every other sevice.

Buddhiprabha commented 6 years ago

Is anyone working on this? If not @lunayach can look at this. Please confirm @paavininanda @shreyans29

paavininanda commented 6 years ago

No I am not working on this. @lunayach you can go ahead :)