From d3a752f0e5a695dbe41458ecdce8c11d7d130671 Mon Sep 17 00:00:00 2001 From: Basar Buyukkahraman Date: Tue, 4 Aug 2020 17:46:20 +0300 Subject: [PATCH] 1403-running-tests-against-shared-db --- __tests__/Auth.spec.js | 4 +++- __tests__/PasswordReset.spec.js | 4 +++- __tests__/TokenService.spec.js | 4 +++- __tests__/UserDelete.spec.js | 4 +++- __tests__/UserListing.spec.js | 4 +++- __tests__/UserRegister.spec.js | 4 +++- __tests__/UserUpdate.spec.js | 4 +++- config/staging.js | 19 +++++++++++++++++++ database/config.json | 8 ++++++++ package.json | 5 ++++- 10 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 config/staging.js diff --git a/__tests__/Auth.spec.js b/__tests__/Auth.spec.js index e362758..6fb743a 100644 --- a/__tests__/Auth.spec.js +++ b/__tests__/Auth.spec.js @@ -8,7 +8,9 @@ const en = require('../locales/en/translation.json'); const tr = require('../locales/tr/translation.json'); beforeAll(async () => { - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } }); beforeEach(async () => { diff --git a/__tests__/PasswordReset.spec.js b/__tests__/PasswordReset.spec.js index 5c6796b..d162123 100644 --- a/__tests__/PasswordReset.spec.js +++ b/__tests__/PasswordReset.spec.js @@ -34,7 +34,9 @@ beforeAll(async () => { await server.listen(config.mail.port, 'localhost'); - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } jest.setTimeout(20000); }); diff --git a/__tests__/TokenService.spec.js b/__tests__/TokenService.spec.js index a36122b..000ce97 100644 --- a/__tests__/TokenService.spec.js +++ b/__tests__/TokenService.spec.js @@ -4,7 +4,9 @@ const Token = require('../src/auth/Token'); const TokenService = require('../src/auth/TokenService'); beforeAll(async () => { - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } }); beforeEach(async () => { diff --git a/__tests__/UserDelete.spec.js b/__tests__/UserDelete.spec.js index 5f72898..bb56226 100644 --- a/__tests__/UserDelete.spec.js +++ b/__tests__/UserDelete.spec.js @@ -8,7 +8,9 @@ const en = require('../locales/en/translation.json'); const tr = require('../locales/tr/translation.json'); beforeAll(async () => { - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } }); beforeEach(async () => { diff --git a/__tests__/UserListing.spec.js b/__tests__/UserListing.spec.js index e222dac..537161f 100644 --- a/__tests__/UserListing.spec.js +++ b/__tests__/UserListing.spec.js @@ -7,7 +7,9 @@ const en = require('../locales/en/translation.json'); const tr = require('../locales/tr/translation.json'); beforeAll(async () => { - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } }); beforeEach(async () => { diff --git a/__tests__/UserRegister.spec.js b/__tests__/UserRegister.spec.js index b791388..bdee65d 100644 --- a/__tests__/UserRegister.spec.js +++ b/__tests__/UserRegister.spec.js @@ -32,7 +32,9 @@ beforeAll(async () => { await server.listen(config.mail.port, 'localhost'); - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } jest.setTimeout(20000); }); diff --git a/__tests__/UserUpdate.spec.js b/__tests__/UserUpdate.spec.js index 57f64d3..8d19e0d 100644 --- a/__tests__/UserUpdate.spec.js +++ b/__tests__/UserUpdate.spec.js @@ -13,7 +13,9 @@ const { uploadDir, profileDir } = config; const profileDirectory = path.join('.', uploadDir, profileDir); beforeAll(async () => { - await sequelize.sync(); + if (process.env.NODE_ENV === 'test') { + await sequelize.sync(); + } }); beforeEach(async () => { diff --git a/config/staging.js b/config/staging.js new file mode 100644 index 0000000..f9876c5 --- /dev/null +++ b/config/staging.js @@ -0,0 +1,19 @@ +module.exports = { + database: { + database: 'hoaxify', + username: 'my-db-user', + password: 'db-p4ss', + dialect: 'sqlite', + storage: './staging.sqlite', + logging: false, + }, + mail: { + host: 'localhost', + port: Math.floor(Math.random() * 2000) + 10000, + tls: { + rejectUnauthorized: false, + }, + }, + uploadDir: 'uploads-staging', + profileDir: 'profile', +}; diff --git a/database/config.json b/database/config.json index 64edb49..5e30059 100644 --- a/database/config.json +++ b/database/config.json @@ -6,5 +6,13 @@ "host": "localhost", "dialect": "sqlite", "storage": "./database.sqlite" + }, + "staging": { + "username": "my-db-user", + "password": "db-p4ss", + "database": "hoaxify", + "host": "localhost", + "dialect": "sqlite", + "storage": "./staging.sqlite" } } diff --git a/package.json b/package.json index ee817db..7a8df95 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "start": "cross-env NODE_ENV=development nodemon index", "test": "cross-env NODE_ENV=test jest --watch", "posttest": "cross-env NODE_ENV=test node test-cleanup", - "lint": "eslint ." + "lint": "eslint .", + "test:staging": "cross-env NODE_ENV=staging jest -f . --runInBand", + "migrate:test": "cross-env NODE_ENV=staging sequelize-cli db:migrate", + "pretest:staging": "npm run migrate:test" }, "author": "Basar Buyukkahraman", "license": "ISC",