Skip to content
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

Feature/test env #18

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NODE_ENV=test
PORT=4040
MONGO_HOST=mongodb://localhost/hl7-telescoper-api-server-development
MONGO_PORT=27017
JWT_SECRET=0a6b944d-d2fb-46fc-a85e-0295c986cd9f
JWT_EXP_TIME=1h
FILE_UPLOAD_PATH=data/hl7-uploads-test
9 changes: 9 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const Joi = require('joi');
const dotenv = require('dotenv')

// require and configure dotenv, will load vars in .env or .env.test in PROCESS.ENV
if (process.env.NODE_ENV === 'test') {
console.log('config.js: Using .env.test')
dotenv.config({ path: '.env.test' });
} else {
console.log('config.js: Using .env')
dotenv.config();
}
// require and configure dotenv, will load vars in .env in PROCESS.ENV
require('dotenv').config();

Expand Down
12 changes: 11 additions & 1 deletion server/hl7/hl7.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ const httpStatus = require('http-status');
const chai = require('chai'); // eslint-disable-line import/newline-after-import
const expect = chai.expect;
const app = require('../../index');
const fs = require('fs');

chai.config.includeStack = true;

/**
* root level hooks
*/
after((done) => {
// Deleting any sample HL7 message used for testing if they exist already before running tests
fs.unlinkSync('data/hl7-uploads-test/500HL7Messages.txt', (err) => {
if (err) throw err;
console.log('data/hl7-uploads-test/500HL7Messages.txt was deleted');
});
// required because https://github.com/Automattic/mongoose/issues/1251#issuecomment-65793092
mongoose.models = {};
mongoose.modelSchemas = {};
Expand All @@ -25,6 +31,10 @@ const user = {
};
let userToken = '';
before((done) => {
if(!fs.existsSync('data/hl7-uploads-test')) {
fs.mkdirSync('data/hl7-uploads-test')
}

// create a user
request(app)
.post('/api/users')
Expand All @@ -46,7 +56,7 @@ before((done) => {

describe('## File Upload', () => {
describe('# POST /api/hl7/upload', () => {
it('should upload a file to /data/hl7-uploads', (done) => {
it('should upload a file to /data/hl7-uploads-test', (done) => {
request(app)
.post('/api/hl7/upload')
.set('Authorization', `Bearer ${userToken}`)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

bcrypt@false3.0.6:
bcrypt@3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-3.0.6.tgz#f607846df62d27e60d5e795612c4f67d70206eb2"
integrity sha512-taA5bCTfXe7FUjKroKky9EXpdhkVvhE5owfxfLYodbrAR1Ul3juLmIQmIQBK4L9a5BuUcE6cqmwT+Da20lF9tg==
Expand Down