-
Notifications
You must be signed in to change notification settings - Fork 27
Chai Mocha tests #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chai Mocha tests #60
Conversation
I changed the config file. Changed the DB to |
sounds good ! All the test config will be isolated from the main config. Just make sure to isolate them in the code as well. |
I found some errors in the code. I've marked them as Also out of curiosity, what do you mean by 'Referer' in api whitelist domains. here And shouldn't it be |
await runValidator.POST(req, res, nextSpy); | ||
// TODO | ||
expect(nextSpy.calledOnce).to.be.false; | ||
// error thrown == " mode" must be one of [sync, callback, poll] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are relying on Joi errors and as far as this is concerned, we may move to modes being numerical. For e.g. sync = 0, callback = 1
Impressive pull request 🚀 The entire purpose of having the tests is to have a code that works in the production environment. We can fix these errors in different PRs, but identifying them with the exhaustive set test is important. Let's just Review the ToDos in the test and complete the PR |
test/e2e/LangsScenario.spec.ts
Outdated
it('should throw 403 error API key is absent in the request', async () => { | ||
const res = await chai.request(app).get(`/api/langs`); | ||
expect(res.status).to.equal(403); | ||
// TODO this should be res.body.err maybe? (consistent with other error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status code will define the error and let's stick with body.message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the base validator is sending body.err
base-validator-error
test/e2e/RunScenario.spec.ts
Outdated
}).send(params); | ||
|
||
expect(res.status).to.equal(200); | ||
// TODO ? does not throw error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should fail with a 400 status code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue for this.
@jatinkatyal13 Have a look at the PR when you're free :) |
EDIT : tldr, I fixed it :) I need your help with test-config thing. I am not able to change the I changed npm test to But the enviroment is not getting changed. When I did this the |
about 1400 lines of code 😪 |
config/config.js
Outdated
const developmentConfig = require('./development-config'); | ||
const testConfig = require('./test-config'); | ||
|
||
if (process.env.NODE_ENV === 'test') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory structure should be as follows
- config/index.js
- config/development.js
- conifg/test.js
- config/production.js
All the common configs will be exported from index.js and overridable based on the NODE_ENV.
We should run |
@jatinkatyal13 made the changes. Also I am doing |
Generally following is the process of setting up DB
|
@jatinkatyal13 I think I am also doing something similar. Waiting for a complete review :) |
Setup is perfect now! Let's remove all the TODOs and let the test fail in the case of wrong result. If the lang is incorrect we should get 400 and if the domain is not whitelisted we should get 403 |
Yaay. This is probably my biggest PR . :) |
fixes #58
Added Chai and Mocha Tests