-
Notifications
You must be signed in to change notification settings - Fork 3
Add test suite #66
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
Open
calufa
wants to merge
7
commits into
main
Choose a base branch
from
feature/add-unit-test-suite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add test suite #66
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0bd91b0
add test suite
calufa c7ebfd9
calculate coverage
calufa acec833
use nodemon
calufa 0ef81f3
use getConfig()
calufa 3a63a22
update README
calufa 4a47548
use trap
calufa 3d2e20a
Merge pull request #77 from vlab-research/feature/use-trap
calufa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| FROM node:10-stretch | ||
|
|
||
| WORKDIR /usr/src/app | ||
| RUN mkdir /app | ||
| WORKDIR /app | ||
|
|
||
| COPY package.json . | ||
| RUN npm i | ||
|
|
||
| COPY . . | ||
| COPY package.json /app | ||
| RUN npm install | ||
|
|
||
| COPY . /app | ||
| EXPOSE 3000 | ||
|
|
||
| CMD [ "npm", "start"] | ||
| CMD [ "npm", "start" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,94 @@ | ||
| const { Pool } = require('pg'); | ||
| require('chai').should(); | ||
| require('mocha'); | ||
| const axios = require('axios'); | ||
|
|
||
| const model = require('./response.queries'); | ||
| const responseModel = require('./response.queries'); | ||
| const surveyModel = require('../surveys/survey.queries'); | ||
| const userModel = require('../users/user.queries'); | ||
|
|
||
| const { DATABASE_CONFIG } = require('../../config'); | ||
|
|
||
| describe('Response queries', () => { | ||
| let pool; | ||
| let Response; | ||
| let vlabPool; | ||
| let Survey; | ||
| let User; | ||
|
|
||
| before(async () => { | ||
| let pool = new Pool({ | ||
| user: 'postgres', | ||
| host: 'localhost', | ||
| database: 'postgres', | ||
| password: undefined, | ||
| port: 5432, | ||
| }); | ||
| pool = new Pool(DATABASE_CONFIG); | ||
| Response = responseModel.queries(pool); | ||
| Survey = surveyModel.queries(pool); | ||
| User = userModel.queries(pool); | ||
| }); | ||
|
|
||
| try { | ||
| await pool.query('CREATE DATABASE vlab_dashboard_test'); | ||
| } catch (e) {} | ||
| beforeEach(async () => { | ||
| await axios.get('http://system/resetdb'); | ||
| }); | ||
|
|
||
| vlabPool = new Pool(DATABASE_CONFIG); | ||
| describe('.all()', () => { | ||
| it('should get the list of the first and last responses for each user', async () => { | ||
| const user1 = await User.create({ | ||
| token: 'AAAA', | ||
| email: 'test1@vlab.com', | ||
| }); | ||
|
|
||
| await vlabPool.query( | ||
| `CREATE TABLE responses( | ||
| parent_surveyid UUID NOT NULL, | ||
| parent_shortcode INT NOT NULL, | ||
| surveyid UUID NOT NULL, | ||
| shortcode INT NOT NULL, | ||
| flowid INT NOT NULL, | ||
| userid VARCHAR NOT NULL, | ||
| question_ref VARCHAR NOT NULL, | ||
| question_idx INT NOT NULL, | ||
| question_text VARCHAR NOT NULL, | ||
| response VARCHAR NOT NULL, | ||
| seed INT NOT NULL, | ||
| timestamp TIMESTAMPTZ NOT NULL, | ||
| PRIMARY KEY (userid, timestamp) | ||
| )`, | ||
| ); | ||
| await vlabPool.query('DELETE FROM responses'); | ||
| const user2 = await User.create({ | ||
| token: 'BBBB', | ||
| email: 'test2@vlab.com', | ||
| }); | ||
|
|
||
| Response = model.queries(vlabPool); | ||
| }); | ||
| const user3 = await User.create({ | ||
| token: 'CCCC', | ||
| email: 'test3@vlab.com', | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await vlabPool.query('DELETE FROM responses'); | ||
| }); | ||
| const survey1 = await Survey.create({ | ||
| created: new Date(), | ||
| formid: 'DDD', | ||
| form: '{"form": "form detail 1"}', | ||
| shortcode: 123, | ||
| userid: user1.id, | ||
| title: 'New User Title 1', | ||
| metadata: '{}', | ||
| survey_name: "test 1", | ||
| translation_conf: '{}', | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await vlabPool.query('DROP TABLE responses'); | ||
| }); | ||
| const survey2 = await Survey.create({ | ||
| created: new Date(), | ||
| formid: 'EEE', | ||
| form: '{"form": "form detail 2"}', | ||
| shortcode: 567, | ||
| userid: user2.id, | ||
| title: 'New User Title 2', | ||
| metadata: '{}', | ||
| survey_name: "test 2", | ||
| translation_conf: '{}', | ||
| }); | ||
|
|
||
| describe('.all()', () => { | ||
| it('should get the list of the first and last responses for each user', async () => { | ||
| const MOCK_QUERY = `INSERT INTO responses(parent_surveyid, parent_shortcode, surveyid, shortcode, flowid, userid, question_ref, question_idx, question_text, response, seed, timestamp) | ||
| VALUES | ||
| ('b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 'b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 100001, '124', 'ref', 10, 'text', '{ "text": "last" }', '6789', current_date + interval '14 hour') | ||
| ,('f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 'f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 100003, '123', 'ref', 10, 'text', '{ "text": "last" }', '6789', date '2019-04-18' + interval '12 hour') | ||
| ,('b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 'b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 100004, '124', 'ref', 10, 'text', '{ "text": "first" }', '6789', current_date + interval '10 hour') | ||
| ,('f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 'f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 100005, '123', 'ref', 10, 'text', '{ "text": "first" }', '6789', date '2019-04-18' + interval '8 hour') | ||
| ,('f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 'f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 100003, '125', 'ref', 10, 'text', '{ "text": "last" }', '6789', date '2019-04-18' + interval '12 hour') | ||
| ,('b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 'b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 100004, '125', 'ref', 10, 'text', '{ "text": "first" }', '6789', date '2019-04-18' + interval '10 hour') | ||
| ,('f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 'f5de09c8-f2c3-49ac-847d-33c8bf5be427', '202', 100005, '125', 'ref', 10, 'text', '{ "text": "first" }', '6789', date '2019-04-18' + interval '8 hour') | ||
| ,('b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 'b8b960ca-3c0d-4a64-a058-2140ee89596b', '101', 100006, '124', 'ref', 10, 'text', '{ "text": "middle" }', '6789', current_date + interval '12 hour')`; | ||
| const MOCK_QUERY = ` | ||
| INSERT INTO responses(parent_surveyid, parent_shortcode, surveyid, shortcode, flowid, userid, question_ref, question_idx, question_text, response, seed, timestamp) | ||
| VALUES | ||
| ('${survey1.id}', '${survey1.shortcode}', '${survey1.id}', '${survey1.shortcode}', 100001, '${user1.id}', 'ref', 10, 'text', '{ "text": "last" }', '6789', '2019-05-29T14:00:01.00Z'), | ||
| ('${survey2.id}', '${survey2.shortcode}', '${survey2.id}', '${survey2.shortcode}', 100003, '${user2.id}', 'ref', 10, 'text', '{ "text": "last" }', '6789', '2010-05-29T12:00:01.00Z'), | ||
| ('${survey1.id}', '${survey1.shortcode}', '${survey1.id}', '${survey1.shortcode}', 100004, '${user1.id}', 'ref', 10, 'text', '{ "text": "first" }', '6789', '2019-05-29T10:20:01.00Z'), | ||
| ('${survey2.id}', '${survey2.shortcode}', '${survey2.id}', '${survey2.shortcode}', 100005, '${user2.id}', 'ref', 10, 'text', '{ "text": "first" }', '6789', '2010-05-29T08:00:01.00Z'), | ||
| ('${survey2.id}', '${survey2.shortcode}', '${survey2.id}', '${survey2.shortcode}', 100003, '${user3.id}', 'ref', 10, 'text', '{ "text": "last" }', '6789', '2010-05-29T12:00:01.00Z'), | ||
| ('${survey1.id}', '${survey1.shortcode}', '${survey1.id}', '${survey1.shortcode}', 100004, '${user3.id}', 'ref', 10, 'text', '{ "text": "first" }', '6789', '2010-05-29T10:00:01.00Z'), | ||
| ('${survey2.id}', '${survey2.shortcode}', '${survey2.id}', '${survey2.shortcode}', 100005, '${user3.id}', 'ref', 10, 'text', '{ "text": "first" }', '6789', '2010-05-29T08:00:01.00Z'), | ||
| ('${survey1.id}', '${survey1.shortcode}', '${survey1.id}', '${survey1.shortcode}', 100006, '${user1.id}', 'ref', 10, 'text', '{ "text": "middle" }', '6789', '2019-05-29T12:00:01.00Z') | ||
| `; | ||
|
|
||
| await vlabPool.query(MOCK_QUERY); | ||
| await pool.query(MOCK_QUERY); | ||
| const responses = await Response.all(); | ||
|
|
||
| responses[0].first_response.should.equal('{ "text": "first" }'); | ||
| responses[0].last_response.should.equal('{ "text": "last" }'); | ||
| responses[0].surveyid.should.equal( | ||
| 'f5de09c8-f2c3-49ac-847d-33c8bf5be427', | ||
| ); | ||
| responses[0].surveyid.should.equal(survey1.id); | ||
| responses[1].first_response.should.equal('{ "text": "first" }'); | ||
| responses[1].last_response.should.equal('{ "text": "last" }'); | ||
| responses[1].surveyid.should.equal( | ||
| 'b8b960ca-3c0d-4a64-a058-2140ee89596b', | ||
| ); | ||
| responses[1].surveyid.should.equal(survey2.id); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is basically a copy and paste from, #59 (comment)