Skip to content

Commit 713ebf0

Browse files
Merge pull request #13 from topcoder-platform/feature/integration-test-fix
merge from Feature/integration test fix
2 parents cf817e3 + 456fc15 commit 713ebf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4000
-458
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ workflows:
6868
branches:
6969
only:
7070
- dev
71+
- feature/es-segregation
72+
- feature/integration-test-fix
7173

7274
# Production builds are exectuted only on tagged commits to the
7375
# master branch.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,7 @@ dist
113113
.yarn/unplugged
114114
.yarn/build-state.yml
115115
.yarn/install-state.gz
116-
.pnp.*
116+
.pnp.*
117+
118+
# api.env
119+
api.env

README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,49 @@ The following parameters can be set in config files or in env variables:
1919
- `BASE_PATH`: the server api base path
2020
- `AUTH_SECRET`: The authorization secret used during token verification.
2121
- `VALID_ISSUERS`: The valid issuer of tokens, a json array contains valid issuer.
22+
2223
- `AUTH0_URL`: Auth0 URL, used to get TC M2M token
2324
- `AUTH0_AUDIENCE`: Auth0 audience, used to get TC M2M token
25+
- `AUTH0_AUDIENCE_FOR_BUS_API`: Auth0 audience, used to get TC M2M token to be used in bus api client
2426
- `TOKEN_CACHE_TIME`: Auth0 token cache time, used to get TC M2M token
2527
- `AUTH0_CLIENT_ID`: Auth0 client id, used to get TC M2M token
2628
- `AUTH0_CLIENT_SECRET`: Auth0 client secret, used to get TC M2M token
2729
- `AUTH0_PROXY_SERVER_URL`: Proxy Auth0 URL, used to get TC M2M token
30+
2831
- `DATABASE_URL`: PostgreSQL database url.
2932
- `DB_SCHEMA_NAME`: string - PostgreSQL database target schema
3033
- `PROJECT_API_URL`: the project service url
3134
- `TC_API`: the Topcoder v5 url
3235
- `ORG_ID`: the organization id
33-
- `HOST`: the elasticsearch host
34-
- `ES_INDEX_JOB`: the job index
35-
- `ES_INDEX_JOB_CANDIDATE`: the job candidate index
36-
- `ES_INDEX_RESOURCE_BOOKING`: the resource booking index
36+
37+
- `esConfig.HOST`: the elasticsearch host
38+
- `esConfig.ES_INDEX_JOB`: the job index
39+
- `esConfig.ES_INDEX_JOB_CANDIDATE`: the job candidate index
40+
- `esConfig.ES_INDEX_RESOURCE_BOOKING`: the resource booking index
41+
- `esConfig.AWS_REGION`: The Amazon region to use when using AWS Elasticsearch service
42+
- `esConfig.ELASTICCLOUD.id`: The elastic cloud id, if your elasticsearch instance is hosted on elastic cloud. DO NOT provide a value for ES_HOST if you are using this
43+
- `esConfig.ELASTICCLOUD.username`: The elastic cloud username for basic authentication. Provide this only if your elasticsearch instance is hosted on elastic cloud
44+
- `esConfig.ELASTICCLOUD.password`: The elastic cloud password for basic authentication. Provide this only if your elasticsearch instance is hosted on elastic cloud
45+
46+
- `BUSAPI_URL`: Topcoder Bus API URL
47+
- `KAFKA_ERROR_TOPIC`: The error topic at which bus api will publish any errors
48+
- `KAFKA_MESSAGE_ORIGINATOR`: The originator value for the kafka messages
49+
50+
- `TAAS_JOB_CREATE_TOPIC`: the create job entity Kafka message topic
51+
- `TAAS_JOB_UPDATE_TOPIC`: the update job entity Kafka message topic
52+
- `TAAS_JOB_DELETE_TOPIC`: the delete job entity Kafka message topic
53+
- `TAAS_JOB_CANDIDATE_CREATE_TOPIC`: the create job candidate entity Kafka message topic
54+
- `TAAS_JOB_CANDIDATE_UPDATE_TOPIC`: the update job candidate entity Kafka message topic
55+
- `TAAS_JOB_CANDIDATE_DELETE_TOPIC`: the delete job candidate entity Kafka message topic
56+
- `TAAS_RESOURCE_BOOKING_CREATE_TOPIC`: the create resource booking entity Kafka message topic
57+
- `TAAS_RESOURCE_BOOKING_UPDATE_TOPIC`: the update resource booking entity Kafka message topic
58+
- `TAAS_RESOURCE_BOOKING_DELETE_TOPIC`: the delete resource booking entity Kafka message topic
3759

3860

3961
## PostgreSQL Database Setup
4062
- Go to https://www.postgresql.org/ download and install the PostgreSQL.
4163
- Modify `DATABASE_URL` under `config/default.js` to meet your environment.
42-
- Run `npm run init-db` to create table
64+
- Run `npm run init-db` to create table(run `npm run init-db force` to force creating table)
4365

4466
## ElasticSearch Setup
4567
- Go to https://www.elastic.co/downloads/ download and install the elasticsearch.
@@ -52,17 +74,41 @@ The following parameters can be set in config files or in env variables:
5274
- Install dependencies `npm install`
5375
- Run lint `npm run lint`
5476
- Run lint fix `npm run lint:fix`
55-
- Clear and init db `npm run init-db`
56-
- Clear and create es index `npm run delete-index && npm run create-index`
77+
- Clear and init db `npm run init-db force`
78+
- Clear and create es index
79+
80+
``` bash
81+
npm run delete-index # run this if you already created index
82+
npm run create-index
83+
```
84+
5785
- Start app `npm start`
5886
- App is running at `http://localhost:3000`
5987

60-
## Docker Deployment
61-
- Run `docker-compose up`
88+
## Local Deployment with Docker
89+
90+
Make sure all config values are right, and you can run on local successful, then run below commands
91+
92+
1. Navigate to the directory `docker`
93+
94+
2. Rename the file `sample.api.env` to `api.env`
95+
96+
3. Set the required AUTH0 configurations, PostgreSQL Database url and ElasticSearch host in the file `api.env`
97+
98+
Note that you can also add other variables to `api.env`, with `<key>=<value>` format per line.
99+
If using AWS ES you should add `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` variables as well.
100+
101+
4. Once that is done, run the following command
102+
103+
```bash
104+
docker-compose up
105+
```
106+
107+
5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies
62108

63109
## Testing
64110
- Run `npm run test` to execute unit tests
65111
- Run `npm run cov` to execute unit tests and generate coverage report.
66112

67113
## Verification
68-
Refer to the verification document [Verification.md](Verification.md)
114+
Refer to the verification document [Verification.md](Verification.md)

Verification.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
# Topcoder Bookings API
22

33
## Postman test
4-
- Refer `ReadMe.md` to start the app and postgreSQL database
5-
- Run `npm run init-db` to init db before testing.
6-
- Run `npm run create-index` to create es index before testing
4+
- start PostgreSQL and ElasticSearch
5+
- Refer `README.md#Local Deployment` to start the app
76
- Import Postman collection and environment file in the `docs` folder to Postman and execute the scripts to validate the app from top to bottom.
87

8+
## Note About Testing `/taas-teams` Endpoints
9+
Before you run tests against the `taas-teams` endpoints, you should insert the dedicated test data by running `npm run test-data`.
910

1011
## Unit test Coverage
1112

1213

13-
63 passing (43s)
14+
``` bash
15+
96 passing (170ms)
1416

15-
16-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
17-
----------------------------|---------|----------|---------|---------|-------------------
18-
All files | 99.49 | 97.62 | 100 | 99.74 |
19-
config | 100 | 100 | 100 | 100 |
20-
default.js | 100 | 100 | 100 | 100 |
21-
test.js | 100 | 100 | 100 | 100 |
22-
src | 90.48 | 50 | 100 | 94.12 |
23-
bootstrap.js | 90.48 | 50 | 100 | 94.12 | 18
24-
src/common | 100 | 100 | 100 | 100 |
25-
errors.js | 100 | 100 | 100 | 100 |
26-
helper.js | 100 | 100 | 100 | 100 |
27-
src/models | 100 | 92.86 | 100 | 100 |
28-
Job.js | 100 | 100 | 100 | 100 |
29-
JobCandidate.js | 100 | 100 | 100 | 100 |
30-
ResourceBooking.js | 100 | 100 | 100 | 100 |
31-
index.js | 100 | 80 | 100 | 100 | 29
32-
src/services | 100 | 100 | 100 | 100 |
33-
JobCandidateService.js | 100 | 100 | 100 | 100 |
34-
JobService.js | 100 | 100 | 100 | 100 |
35-
ResourceBookingService.js | 100 | 100 | 100 | 100 |
17+
----------------------------|---------|----------|---------|---------|----------------------------
18+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
19+
----------------------------|---------|----------|---------|---------|----------------------------
20+
All files | 98.43 | 91.03 | 100 | 98.56 |
21+
config | 100 | 100 | 100 | 100 |
22+
default.js | 100 | 100 | 100 | 100 |
23+
test.js | 100 | 100 | 100 | 100 |
24+
src | 90.91 | 50 | 100 | 94.44 |
25+
bootstrap.js | 90.91 | 50 | 100 | 94.44 | 18
26+
src/common | 97.69 | 90.91 | 100 | 97.66 |
27+
errors.js | 100 | 50 | 100 | 100 | 23
28+
helper.js | 97.5 | 92.86 | 100 | 97.46 | 94,176,284
29+
src/models | 100 | 92.86 | 100 | 100 |
30+
Job.js | 100 | 100 | 100 | 100 |
31+
JobCandidate.js | 100 | 100 | 100 | 100 |
32+
ResourceBooking.js | 100 | 100 | 100 | 100 |
33+
index.js | 100 | 80 | 100 | 100 | 29
34+
src/services | 98.81 | 89.5 | 100 | 98.8 |
35+
JobCandidateService.js | 98.77 | 88 | 100 | 98.77 | 37
36+
JobService.js | 97.37 | 85.37 | 100 | 97.32 | 73,285,326
37+
ResourceBookingService.js | 98.86 | 93.1 | 100 | 98.86 | 54
38+
TeamService.js | 100 | 90.7 | 100 | 100 | 19,135-138,188-202,251,267
39+
----------------------------|---------|----------|---------|---------|----------------------------
40+
```

app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const config = require('config')
88
const express = require('express')
99
const cors = require('cors')
1010
const HttpStatus = require('http-status-codes')
11-
const logger = require('./src/common/logger')
1211
const interceptor = require('express-interceptor')
12+
const logger = require('./src/common/logger')
1313

1414
// setup express app
1515
const app = express()
@@ -52,7 +52,7 @@ require('./app-routes')(app)
5252
// The error handler
5353
// eslint-disable-next-line no-unused-vars
5454
app.use((err, req, res, next) => {
55-
logger.logFullError(err, req.signature || `${req.method} ${req.url}`)
55+
logger.logFullError(err, { component: 'app', signature: req.signature || `${req.method}_${req.url}` })
5656
const errorResponse = {}
5757
const status = err.isJoi ? HttpStatus.BAD_REQUEST : (err.status || err.httpStatus || HttpStatus.INTERNAL_SERVER_ERROR)
5858

@@ -87,7 +87,7 @@ app.use((err, req, res, next) => {
8787
})
8888

8989
const server = app.listen(app.get('port'), () => {
90-
logger.info(`Express server listening on port ${app.get('port')}`)
90+
logger.info({ component: 'app', message: `Express server listening on port ${app.get('port')}` })
9191
})
9292

9393
if (process.env.NODE_ENV === 'test') {

config/default.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/", "https://auth.topcoder-dev.com/"]',
99
AUTH0_URL: process.env.AUTH0_URL,
1010
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
11+
AUTH0_AUDIENCE_FOR_BUS_API: process.env.AUTH0_AUDIENCE_FOR_BUS_API,
1112
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
1213
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
1314
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
@@ -22,8 +23,33 @@ module.exports = {
2223

2324
esConfig: {
2425
HOST: process.env.ES_HOST || 'http://localhost:9200',
26+
27+
ELASTICCLOUD: {
28+
id: process.env.ELASTICCLOUD_ID,
29+
username: process.env.ELASTICCLOUD_USERNAME,
30+
password: process.env.ELASTICCLOUD_PASSWORD
31+
},
32+
33+
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used if we use AWS ES
34+
2535
ES_INDEX_JOB: process.env.ES_INDEX_JOB || 'job',
2636
ES_INDEX_JOB_CANDIDATE: process.env.ES_INDEX_JOB_CANDIDATE || 'job_candidate',
2737
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking'
28-
}
38+
},
39+
40+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
41+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
42+
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'taas-api',
43+
// topics for job service
44+
TAAS_JOB_CREATE_TOPIC: process.env.TAAS_JOB_CREATE_TOPIC || 'taas.job.create',
45+
TAAS_JOB_UPDATE_TOPIC: process.env.TAAS_JOB_UPDATE_TOPIC || 'taas.job.update',
46+
TAAS_JOB_DELETE_TOPIC: process.env.TAAS_JOB_DELETE_TOPIC || 'taas.job.delete',
47+
// topics for jobcandidate service
48+
TAAS_JOB_CANDIDATE_CREATE_TOPIC: process.env.TAAS_JOB_CANDIDATE_CREATE_TOPIC || 'taas.jobcandidate.create',
49+
TAAS_JOB_CANDIDATE_UPDATE_TOPIC: process.env.TAAS_JOB_CANDIDATE_UPDATE_TOPIC || 'taas.jobcandidate.update',
50+
TAAS_JOB_CANDIDATE_DELETE_TOPIC: process.env.TAAS_JOB_CANDIDATE_DELETE_TOPIC || 'taas.jobcandidate.delete',
51+
// topics for job service
52+
TAAS_RESOURCE_BOOKING_CREATE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_CREATE_TOPIC || 'taas.resourcebooking.create',
53+
TAAS_RESOURCE_BOOKING_UPDATE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC || 'taas.resourcebooking.update',
54+
TAAS_RESOURCE_BOOKING_DELETE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_DELETE_TOPIC || 'taas.resourcebooking.delete'
2955
}

config/test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module.exports = {
2-
LOG_LEVEL: process.env.LOG_LEVEL || 'info'
2+
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
3+
AUTH0_URL: 'http://example.com',
4+
AUTH0_AUDIENCE: 'http://example.com',
5+
AUTH0_AUDIENCE_FOR_BUS_API: 'http://example.com',
6+
AUTH0_CLIENT_ID: 'fake_id',
7+
AUTH0_CLIENT_SECRET: 'fake_secret'
38
}

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ RUN npm install
1414
COPY . .
1515

1616
# Run the app
17-
CMD [ "node", "app.js" ]
17+
CMD [ "npm", "start" ]

docker/docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
services:
3+
taas_api:
4+
image: taas_api:latest
5+
build:
6+
context: ../
7+
dockerfile: docker/Dockerfile
8+
env_file:
9+
- api.env
10+
ports:
11+
- "3000:3000"

docker/sample.api.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DATABASE_URL=<Database Url>
2+
ES_HOST=<ES Host Endpoint>
3+
4+
AUTH0_URL=<AUTH0 URL>
5+
AUTH0_AUDIENCE=<AUTH0 Audience>
6+
AUTH0_AUDIENCE_FOR_BUS_API=<AUTH0 Audience For Bus Api>
7+
TOKEN_CACHE_TIME=500000
8+
AUTH0_CLIENT_ID=<AUTH0 Client ID>
9+
AUTH0_CLIENT_SECRET=<AUTH0 Client Secret>

0 commit comments

Comments
 (0)