Skip to content

Commit 9eef45f

Browse files
authored
Remove mock project api (#8)
* Update unit tests dependency * remove mock project api
1 parent 4f31d4e commit 9eef45f

File tree

11 files changed

+48
-3372
lines changed

11 files changed

+48
-3372
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ The following parameters can be set in config files or in env variables:
5656
- App is running at `http://localhost:3000`
5757

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

Verification.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Topcoder Bookings API
22

33
## Postman test
4-
- Refer `tools/mock-project-service/ReadMe.md` to start the mock app
54
- Refer `ReadMe.md` to start the app and postgreSQL database
65
- Run `npm run init-db` to init db before testing.
76
- Run `npm run create-index` to create es index before testing

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717

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

2222
esConfig: {
2323
HOST: process.env.ES_HOST || 'http://localhost:9200',

test/unit/JobCandidateService.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,16 @@ describe('jobCandidate service test', () => {
125125
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
126126
return _.cloneDeep(jobResponseBody)
127127
})
128+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
129+
return true
130+
})
131+
128132
const entity = await service.fullyUpdateJobCandidate(connectUser, jobCandidateResponseBody.dataValues.id, fullyUpdateJobCandidateRequestBody)
129133
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
130134
expect(stubJobCandidateFindOne.calledOnce).to.be.true
131135
expect(stubJobFindOne.calledOnce).to.be.true
132136
expect(stubESUpdate.calledOnce).to.be.true
137+
expect(stubConnect.calledOnce).to.be.true
133138
})
134139

135140
it('fully update job candidate test with topcoder user success', async () => {
@@ -210,11 +215,16 @@ describe('jobCandidate service test', () => {
210215
const stubJobFindOne = sinon.stub(Job, 'findOne').callsFake(() => {
211216
return _.cloneDeep(jobResponseBody)
212217
})
218+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
219+
return true
220+
})
221+
213222
const entity = await service.partiallyUpdateJobCandidate(connectUser, jobCandidateResponseBody.dataValues.id, partiallyUpdateJobCandidateRequestBody)
214223
expect(entity).to.deep.eql(jobCandidateRes.dataValues)
215224
expect(stubJobCandidateFindOne.calledOnce).to.be.true
216225
expect(stubJobFindOne.calledOnce).to.be.true
217226
expect(stubESUpdate.calledOnce).to.be.true
227+
expect(stubConnect.calledOnce).to.be.true
218228
})
219229

220230
it('partially update job candidate test with topcoder user failed', async () => {

test/unit/JobService.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,27 @@ describe('job service test', () => {
4343
const stubDBCreate = sinon.stub(Job, 'create').callsFake(() => {
4444
return _.cloneDeep(jobResponseBody)
4545
})
46-
46+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
47+
return true
48+
})
4749
const entity = await service.createJob(connectUser, jobRequestBody)
4850
expect(entity).to.deep.eql(jobResponseBody.dataValues)
4951
expect(stubDBCreate.calledOnce).to.be.true
5052
expect(stubESCreate.calledOnce).to.be.true
53+
expect(stubConnect.calledOnce).to.be.true
5154
})
5255

5356
it('create job with connect user failed user id not exist ', async () => {
57+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
58+
return true
59+
})
5460
try {
5561
await service.createJob(_.assign({}, connectUser, { userId: 'not_exist' }), jobRequestBody)
5662
unexpected()
5763
} catch (err) {
5864
expect(err.message).to.equal('user id not found')
5965
}
66+
expect(stubConnect.calledOnce).to.be.true
6067
})
6168

6269
it('create job with connect user failed ', async () => {
@@ -135,11 +142,15 @@ describe('job service test', () => {
135142
}).onSecondCall().callsFake(() => {
136143
return jobResBody
137144
})
145+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
146+
return true
147+
})
138148

139149
const entity = await service.fullyUpdateJob(connectUser, jobResponseBody.dataValues.id, fullyUpdateJobRequestBody)
140150
expect(entity).to.deep.eql(jobResBody.dataValues)
141151
expect(stub.calledTwice).to.be.true
142152
expect(stubESUpdate.calledOnce).to.be.true
153+
expect(stubConnect.calledOnce).to.be.true
143154
})
144155

145156
it('fully update job test with topcoder user failed', async () => {
@@ -201,10 +212,15 @@ describe('job service test', () => {
201212
}).onSecondCall().callsFake(() => {
202213
return jobResBody
203214
})
215+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
216+
return true
217+
})
218+
204219
const entity = await service.partiallyUpdateJob(connectUser, jobResponseBody.dataValues.id, partiallyUpdateJobRequestBody)
205220
expect(entity).to.deep.eql(jobResBody.dataValues)
206221
expect(stub.calledTwice).to.be.true
207222
expect(stubESUpdate.calledOnce).to.be.true
223+
expect(stubConnect.calledOnce).to.be.true
208224
})
209225

210226
it('partially update job with topcoder user failed', async () => {

test/unit/ResourceBookingService.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ describe('resourceBooking service test', () => {
4545
const stubDBCreate = sinon.stub(ResourceBooking, 'create').callsFake(() => {
4646
return resourceBookingResponseBody
4747
})
48+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
49+
return true
50+
})
51+
4852
const entity = await service.createResourceBooking(connectUser, resourceBookingRequestBody)
4953
expect(entity).to.deep.eql(resourceBookingResponseBody.dataValues)
5054
expect(stubDBCreate.calledOnce).to.be.true
5155
expect(stubESCreate.calledOnce).to.be.true
56+
expect(stubConnect.calledOnce).to.be.true
5257
})
5358

5459
it('create resource booking with topcoder user failed ', async () => {
@@ -76,9 +81,14 @@ describe('resourceBooking service test', () => {
7681
const stub = sinon.stub(ResourceBooking, 'findOne').callsFake(() => {
7782
return resourceBookingRes
7883
})
84+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
85+
return true
86+
})
87+
7988
const entity = await service.getResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id)
8089
expect(entity).to.deep.eql(_.omit(resourceBookingRes.dataValues, ['memberRate']))
8190
expect(stub.calledOnce).to.be.true
91+
expect(stubConnect.calledOnce).to.be.true
8292
})
8393

8494
it('get resource booking with topcoder user success', async () => {
@@ -132,10 +142,15 @@ describe('resourceBooking service test', () => {
132142
update: () => { return null }
133143
}
134144
})
145+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
146+
return true
147+
})
148+
135149
const entity = await service.fullyUpdateResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id, fullyUpdateResourceBookingRequestBody)
136150
expect(entity).to.deep.eql(resourceBookingRes.dataValues)
137151
expect(stubResourceBookingFindOne.calledOnce).to.be.true
138152
expect(stubESUpdate.calledOnce).to.be.true
153+
expect(stubConnect.calledOnce).to.be.true
139154
})
140155

141156
it('fully update resource booking test with topcoder user failed', async () => {
@@ -184,10 +199,15 @@ describe('resourceBooking service test', () => {
184199
update: () => { return null }
185200
}
186201
})
202+
const stubConnect = sinon.stub(helper, 'isConnectMember').callsFake(() => {
203+
return true
204+
})
205+
187206
const entity = await service.partiallyUpdateResourceBooking(connectUser, resourceBookingResponseBody.dataValues.id, partiallyUpdateResourceBookingRequestBody)
188207
expect(entity).to.deep.eql(resourceBookingRes.dataValues)
189208
expect(stubResourceBookingFindOne.calledOnce).to.be.true
190209
expect(stubESUpdate.calledOnce).to.be.true
210+
expect(stubConnect.calledOnce).to.be.true
191211
})
192212

193213
it('partially update resource booking test with topcoder user failed', async () => {

tools/mock-project-service/README.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

tools/mock-project-service/app.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

tools/mock-project-service/config/default.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)