-
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 judgeapi-tests. So make sure you create another similar DB in postgres.
I think it would be better to have a test-config.json. and modify the npm test to use that config. Your thoughts?
@jatinkatyal13
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 TODO in the tests. Should I go and open the issue or just solve them in this PR only.
I guess it'd be better if you have a look at them first ( I might be wrong :P)
Also out of curiosity, what do you mean by 'Referer' in api whitelist domains. here
And shouldn't it be apiKey.whitelist_domains.indexOf('Referer') !==-1
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
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
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 process.env.NODE_ENV
I changed npm test to
cross-env NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/unit/validators/*.ts test/e2e/*.ts && cross-env NODE_ENV=test mocha
But the enviroment is not getting changed.
When I did this
cross-env NODE_ENV=test mocha && NODE_PATH=src node_modules/.bin/mocha --timeout 12000 --exit --require ts-node/register test/unit/validators/*.ts test/e2e/*.ts
the process.env.NODE_ENV was getting changed to test but throwing No test files found error
c33dab6 to
cbdc63a
Compare
about 1400 lines of code 😪
I hope I haven't made many mistakes 😅
config/config.js
Outdated
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 DB.sync once before starting the test. The test DB, in any case, will be discarded and hence we need not truncate it,
@jatinkatyal13 made the changes. Also I am doing truncateTable to make sure there no interference b/w the tests. Otherwise unexpected things might happen when something which was created in the previous tests is affecting the other tests
Generally following is the process of setting up DB
- Setup Tables and Sequences
- Seed mock data (Read only data common for all tests)
- Seed data per test
- Run test
- Truncate per test data
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
195c1b5 to
5c65914
Compare
Yaay. This is probably my biggest PR . :)
Uh oh!
There was an error while loading. Please reload this page.
fixes #58
Added Chai and Mocha Tests