Skip to content

Add docker support #9

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

Merged
merged 2 commits into from
Oct 30, 2020
Merged
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
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Versioning and metadata
.git
.gitignore
.dockerignore

# Build dependencies
dist
node_modules
coverage
.nyc_output

# Environment (contains sensitive data)
.env

# Files not required for production
.editorconfig
docs
Dockerfile*
docker-compose.yml
README.md
tslint.json
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- nodejs https://nodejs.org/en/ (v12+)
- PostgreSQL
- ElasticSearch (7.x)
- Docker
- Docker-Compose

## Configuration

Expand Down Expand Up @@ -55,8 +57,10 @@ The following parameters can be set in config files or in env variables:
- Start app `npm start`
- App is running at `http://localhost:3000`

## Docker Deployment
- Run `docker-compose up`

## Testing
- Run tools/mock-project-service app
- Run `npm run test` to execute unit tests
- Run `npm run cov` to execute unit tests and generate coverage report.

Expand Down
1 change: 0 additions & 1 deletion Verification.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Topcoder Bookings API

## Postman test
- Refer `tools/mock-project-service/ReadMe.md` to start the mock app
- Refer `ReadMe.md` to start the app and postgreSQL database
- Run `npm run init-db` to init db before testing.
- Run `npm run create-index` to create es index before testing
Expand Down
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {

DATABASE_URL: process.env.DATABASE_URL || 'postgres://postgres:postgres@localhost:5432/postgres',
DB_SCHEMA_NAME: process.env.DB_SCHEMA_NAME || 'bookings',
PROJECT_API_URL: process.env.PROJECT_API_URL || 'http://localhost:4000',
PROJECT_API_URL: process.env.PROJECT_API_URL || 'https://api.topcoder-dev.com',

esConfig: {
HOST: process.env.ES_HOST || 'http://localhost:9200',
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'
services:
taas-apis:
container_name: taas-apis
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- '3000:3000'
21 changes: 21 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

FROM node:latest

# Set working directory. Paths will be relative this WORKDIR.
WORKDIR /usr/src/app

ENV NODE_CONFIG_DIR /usr/src/app/config/

# Install dependencies
COPY package*.json ./
RUN npm install

# Copy source files from host computer to the container
COPY . .


# Specify port app runs on
EXPOSE 3000

# Run the app
CMD [ "node", "app.js" ]
10 changes: 10 additions & 0 deletions test/unit/JobCandidateService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.fullyUpdateJobCandidate(connectUser, jobCandidateResponseBody.dataValues.id, fullyUpdateJobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('fully update job candidate test with topcoder user success', async () => {
Expand Down Expand Up @@ -210,11 +215,16 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.partiallyUpdateJobCandidate(connectUser, jobCandidateResponseBody.dataValues.id, partiallyUpdateJobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('partially update job candidate test with topcoder user failed', async () => {
Expand Down
18 changes: 17 additions & 1 deletion test/unit/JobService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,27 @@ describe('job service test', () => {
const stubDBCreate = sinon.stub(Job, 'create').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})

const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})
const entity = await service.createJob(connectUser, jobRequestBody)
expect(entity).to.deep.eql(jobResponseBody.dataValues)
expect(stubDBCreate.calledOnce).to.be.true
expect(stubESCreate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('create job with connect user failed user id not exist ', async () => {
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})
try {
await service.createJob(_.assign({}, connectUser, { userId: 'not_exist' }), jobRequestBody)
unexpected()
} catch (err) {
expect(err.message).to.equal('user id not found')
}
expect(stubConnect.calledOnce).to.be.true
})

it('create job with connect user failed ', async () => {
Expand Down Expand Up @@ -135,11 +142,15 @@ describe('job service test', () => {
}).onSecondCall().callsFake(() => {
return jobResBody
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.fullyUpdateJob(connectUser, jobResponseBody.dataValues.id, fullyUpdateJobRequestBody)
expect(entity).to.deep.eql(jobResBody.dataValues)
expect(stub.calledTwice).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('fully update job test with topcoder user failed', async () => {
Expand Down Expand Up @@ -201,10 +212,15 @@ describe('job service test', () => {
}).onSecondCall().callsFake(() => {
return jobResBody
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.partiallyUpdateJob(connectUser, jobResponseBody.dataValues.id, partiallyUpdateJobRequestBody)
expect(entity).to.deep.eql(jobResBody.dataValues)
expect(stub.calledTwice).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('partially update job with topcoder user failed', async () => {
Expand Down
20 changes: 20 additions & 0 deletions test/unit/ResourceBookingService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ describe('resourceBooking service test', () => {
const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(() => {
return resourceBookingResponseBody
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.createResourceBooking(connectUser, resourceBookingRequestBody)
expect(entity).to.deep.eql(resourceBookingResponseBody.dataValues)
expect(stubDBCreate.calledOnce).to.be.true
expect(stubESCreate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('create resource booking with topcoder user failed ', async () => {
Expand Down Expand Up @@ -76,9 +81,14 @@ describe('resourceBooking service test', () => {
const stub = sinon.stub(ResourceBooking, 'findOne').callsFake(() => {
return resourceBookingRes
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.getResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id)
expect(entity).to.deep.eql(_.omit(resourceBookingRes.dataValues, ['memberRate']))
expect(stub.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('get resource booking with topcoder user success', async () => {
Expand Down Expand Up @@ -132,10 +142,15 @@ describe('resourceBooking service test', () => {
update: () => { return null }
}
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.fullyUpdateResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id, fullyUpdateResourceBookingRequestBody)
expect(entity).to.deep.eql(resourceBookingRes.dataValues)
expect(stubResourceBookingFindOne.calledOnce).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('fully update resource booking test with topcoder user failed', async () => {
Expand Down Expand Up @@ -184,10 +199,15 @@ describe('resourceBooking service test', () => {
update: () => { return null }
}
})
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
return true
})

const entity = await service.partiallyUpdateResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id, partiallyUpdateResourceBookingRequestBody)
expect(entity).to.deep.eql(resourceBookingRes.dataValues)
expect(stubResourceBookingFindOne.calledOnce).to.be.true
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('partially update resource booking test with topcoder user failed', async () => {
Expand Down
21 changes: 0 additions & 21 deletions tools/mock-project-service/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions tools/mock-project-service/app.js

This file was deleted.

6 changes: 0 additions & 6 deletions tools/mock-project-service/config/default.js

This file was deleted.

Loading