Skip to content

Remove mock project api #8

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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ The following parameters can be set in config files or in env variables:
- App is running at `http://localhost:3000`

## Testing
- Run tools/mock-project-service app
- Run `npm run init-db`
- Run `npm run create-index`
- 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
110 changes: 57 additions & 53 deletions test/unit/JobCandidateService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,48 @@ const JobCandidate = models.JobCandidate
const Job = models.Job

describe('jobCandidate service test', () => {
beforeEach(() => {
sinon.restore()
})

describe('create job candidate test', () => {
let stubESCreate
beforeEach(() => {
stubESCreate = sinon.stub(esClient, 'create').callsFake(async () => {})
})

it('create job candidate with booking manager success ', async () => {
const jobCandidateRes = _.cloneDeep(jobCandidateResponseBody)
const stubCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
const stubDBCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
return jobCandidateResponseBody
})

const entity = await service.createJobCandidate(bookingManagerUser, jobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubCreate.calledOnce).to.be.true
stubCreate.restore()
expect(stubDBCreate.calledOnce).to.be.true
expect(stubESCreate.calledOnce).to.be.true
})

it('create job candidate with connect user success ', async () => {
const jobCandidateRes = _.cloneDeep(jobCandidateResponseBody)
const stubCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
const stubDBCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
return jobCandidateRes
})
const entity = await service.createJobCandidate(connectUser, jobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubCreate.calledOnce).to.be.true
stubCreate.restore()
expect(stubDBCreate.calledOnce).to.be.true
expect(stubESCreate.calledOnce).to.be.true
})

it('create job candidate with topcoder user success', async () => {
const jobCandidateRes = _.cloneDeep(jobCandidateResponseBody)
const stubCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
const stubDBCreate = sinon.stub(JobCandidate, 'create').callsFake(() => {
return jobCandidateRes
})
const entity = await service.createJobCandidate(topCoderUser, jobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubCreate.calledOnce).to.be.true
stubCreate.restore()
expect(stubDBCreate.calledOnce).to.be.true
expect(stubDBCreate.calledOnce).to.be.true
})
})

Expand All @@ -63,7 +73,6 @@ describe('jobCandidate service test', () => {
const entity = await service.getJobCandidate(jobCandidateResponseBody.dataValues.id)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
stubJobCandidateFindOne.restore()
})

it('get job candidate with candidate not exist success', async () => {
Expand All @@ -76,12 +85,16 @@ describe('jobCandidate service test', () => {
} catch (error) {
expect(error.message).to.equal(`JobCandidate with id: ${jobCandidateResponseBody.dataValues.id} doesn't exists.`)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
stubJobCandidateFindOne.restore()
}
})
})

describe('fully update job candidate test', () => {
let stubESUpdate
beforeEach(() => {
stubESUpdate = sinon.stub(esClient, 'update').callsFake(() => {})
})

it('fully update job candidate test with booking manager success', async () => {
const jobCandidateRes = _.cloneDeep(jobCandidateResponseBody)
const stubJobCandidateFindOne = sinon.stub(JobCandidate, 'findOne').callsFake(() => {
Expand All @@ -94,14 +107,11 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})
const entity = await service.fullyUpdateJobCandidate(bookingManagerUser, jobCandidateResponseBody.dataValues.id, fullyUpdateJobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
stubES.restore()
expect(stubESUpdate.calledOnce).to.be.true
})

it('fully update job candidate test with connect user success', async () => {
Expand All @@ -115,14 +125,16 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})
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
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
stubES.restore()
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('fully update job candidate test with topcoder user success', async () => {
Expand All @@ -136,19 +148,13 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})
const user = _.assign({}, topCoderUser, { userId: 40152856 })
try {
const entity = await service.fullyUpdateJobCandidate(user, jobCandidateResponseBody.dataValues.id, fullyUpdateJobCandidateRequestBody)
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
} catch (err) {
console.log(err.message)
}
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
stubES.restore()

const entity = await service.fullyUpdateJobCandidate(user, 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
})

it('fully update job candidate test with topcoder user failed', async () => {
Expand All @@ -168,13 +174,17 @@ describe('jobCandidate service test', () => {
} catch (error) {
expect(error.message).to.equal('You are not allowed to perform this action!')
}

stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
})
})

describe('partially update job candidate test', () => {
let stubESUpdate
beforeEach(() => {
stubESUpdate = sinon.stub(esClient, 'update').callsFake(() => {})
})

it('partially update job candidate test with booking manager success', async () => {
const jobCandidateRes = _.cloneDeep(jobCandidateResponseBody)
const stubJobCandidateFindOne = sinon.stub(JobCandidate, 'findOne').callsFake(() => {
Expand All @@ -186,14 +196,12 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})

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

it('partially update job candidate test with connect user success', async () => {
Expand All @@ -207,14 +215,16 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return _.cloneDeep(jobResponseBody)
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})
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
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
stubES.restore()
expect(stubESUpdate.calledOnce).to.be.true
expect(stubConnect.calledOnce).to.be.true
})

it('partially update job candidate test with topcoder user failed', async () => {
Expand All @@ -234,8 +244,8 @@ describe('jobCandidate service test', () => {
} catch (error) {
expect(error.message).to.equal('You are not allowed to perform this action!')
}
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
})

it('partially update job candidate test with job not exist', async () => {
Expand All @@ -248,14 +258,11 @@ describe('jobCandidate service test', () => {
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
return null
})
const stubES = sinon.stub(esClient, 'update').callsFake(() => {})

await service.partiallyUpdateJobCandidate(bookingManagerUser, jobCandidateResponseBody.dataValues.id, partiallyUpdateJobCandidateRequestBody)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
expect(stubJobFindOne.calledOnce).to.be.true
stubJobCandidateFindOne.restore()
stubJobFindOne.restore()
stubES.restore()
expect(stubESUpdate.calledOnce).to.be.true
})
})

Expand All @@ -267,11 +274,10 @@ describe('jobCandidate service test', () => {
update: () => { return null }
}
})
const stubES = sinon.stub(esClient, 'delete').callsFake(() => {})
const stubESDelete = sinon.stub(esClient, 'delete').callsFake(() => {})
await service.deleteJobCandidate(bookingManagerUser, jobCandidateResponseBody.dataValues.id)
expect(stubJobCandidateFindOne.calledOnce).to.be.true
stubJobCandidateFindOne.restore()
stubES.restore()
expect(stubESDelete.calledOnce).to.be.true
})

it('delete job candidate test with connect user success', async () => {
Expand Down Expand Up @@ -313,7 +319,6 @@ describe('jobCandidate service test', () => {
const entity = await service.searchJobCandidates({ sortBy: 'id', sortOrder: 'asc', page: 1, perPage: 1, jobId: '36762910-4efa-4db4-9b2a-c9ab54c232ed' })
expect(entity.result[0]).to.deep.eql(jobCandidateResponseBody.dataValues)
expect(stub.calledOnce).to.be.true
stub.restore()
})

it('search job candidates without query parameters success', async () => {
Expand All @@ -335,7 +340,6 @@ describe('jobCandidate service test', () => {
const entity = await service.searchJobCandidates({})
expect(entity.result[0]).to.deep.eql(jobCandidateResponseBody.dataValues)
expect(stub.calledOnce).to.be.true
stub.restore()
})
})
})
Loading