From a5a52ff3a66189f9635c830a10ab90951fc6d675 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Thu, 14 Mar 2019 10:21:56 +0800 Subject: [PATCH 1/2] test are now running using a separate instance of PostgreSQL in docker-compose for tests, so we don't have to rebuid docker containers every time we want to switch from app running to tests running. --- README.md | 17 ++++------------- config/test.json | 2 +- local/docker-compose.yml | 8 ++++++++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e577765f..efbd4daf 100644 --- a/README.md +++ b/README.md @@ -98,22 +98,13 @@ To be able to run [Connect App](https://github.com/appirio-tech/connect-app) wit 3. Restart both Connect App and Project Service if they were running. ### Test +```bash +npm run test +``` +Tests are being executed with the `NODE_ENV` environment variable has a value `test` and `config/test.js` configuration is loaded. Each of the individual modules/services are unit tested. -To run unit tests run `npm run test` from root of project. - -While tests are being executed the `NODE_ENV` environment variable has a value `test` and `config/test.js` configuration is loaded. The default test configuration refers to `projectsdb_test` postgres database. So make sure that this database exists before running the tests. Since we are using docker-compose for local deployment change `local/docker-compose.yaml` postgres service with updated database name and re-create the containers. - -``` -// stop already executing containers if any -docker-compose stop -t 1 -// clear the containers -docker-compose rm -f -// re-run the services with build flag -docker-compose up --build -``` - #### JWT Authentication Authentication is handled via Authorization (Bearer) token header field. Token is a JWT token. Here is a sample token that is valid for a very long time for a user with administrator role. ``` diff --git a/config/test.json b/config/test.json index 23ca972e..4e94d1a1 100644 --- a/config/test.json +++ b/config/test.json @@ -14,7 +14,7 @@ "rabbitmqUrl": "amqp://localhost:5672", "connectProjectsUrl": "https://local.topcoder-dev.com/projects/", "dbConfig": { - "masterUrl": "postgres://coder:mysecretpassword@localhost:5432/projectsdb_test", + "masterUrl": "postgres://coder:mysecretpassword@localhost:5433/projectsdb_test", "maxPoolSize": 50, "minPoolSize": 4, "idleTimeout": 1000 diff --git a/local/docker-compose.yml b/local/docker-compose.yml index 73a9edcc..72e6985f 100644 --- a/local/docker-compose.yml +++ b/local/docker-compose.yml @@ -12,6 +12,14 @@ services: - POSTGRES_PASSWORD=mysecretpassword - POSTGRES_USER=coder - POSTGRES_DB=projectsdb + db_test: + image: "postgres:9.5" + ports: + - "5433:5432" + environment: + - POSTGRES_PASSWORD=mysecretpassword + - POSTGRES_USER=coder + - POSTGRES_DB=projectsdb_test esearch: image: "elasticsearch:2.3" ports: From 0af9407101ef02f0de5b5409126e668a162fc405 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Thu, 14 Mar 2019 11:14:56 +0800 Subject: [PATCH 2/2] README update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index efbd4daf..f0417f5e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Microservice to manage CRUD operations for all things Projects. docker-compose up ``` This will run several services locally: - - `postgres` + - `postgres` - two instances: for app and for unit tests - `elasticsearch` - `rabbitmq` - `mock-services` - mocks some Topcoder API