Skip to content

Commit e701d71

Browse files
authored
Merge pull request #522 from xxcxy/develop
Fix random tests failures
2 parents 0783002 + ee365c9 commit e701d71

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

src/routes/attachments/delete.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Project Attachments delete', () => {
1919
beforeEach((done) => {
2020
attachments = [];
2121
testUtil.clearDb()
22+
.then(() => testUtil.clearES())
2223
.then(() => {
2324
models.Project.create({
2425
type: 'generic',

src/routes/attachments/get.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('Get Project attachments Tests', () => {
2020

2121
beforeEach((done) => {
2222
testUtil.clearDb()
23+
.then(() => testUtil.clearES())
2324
.then(() => {
2425
models.Project.create({
2526
type: 'generic',

src/routes/attachments/list.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Project Attachments download', () => {
1414

1515
beforeEach((done) => {
1616
testUtil.clearDb()
17+
.then(() => testUtil.clearES())
1718
.then(() => {
1819
models.Project.create({
1920
type: 'generic',

src/routes/projects/list.spec.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ describe('LIST Project', () => {
299299
});
300300

301301
return Promise.all([p1, p2, p3]).then(() => {
302+
data[0].id = project1.id;
303+
data[1].id = project2.id;
304+
data[2].id = project3.id;
302305
const esp1 = server.services.es.index({
303306
index: ES_PROJECT_INDEX,
304307
type: ES_PROJECT_TYPE,
@@ -377,7 +380,7 @@ describe('LIST Project', () => {
377380
should.exist(resJson);
378381
resJson.should.have.lengthOf(1);
379382
// since project 2 is indexed with id 2
380-
resJson[0].id.should.equal(2);
383+
resJson[0].id.should.equal(project2.id);
381384
done();
382385
}
383386
});
@@ -484,9 +487,10 @@ describe('LIST Project', () => {
484487
const resJson = res.body;
485488
should.exist(resJson);
486489
resJson.should.have.lengthOf(3);
487-
resJson[0].should.have.property('attachments');
488-
resJson[0].should.have.property('description');
489-
resJson[0].should.have.property('billingAccountId');
490+
const project = _.find(resJson, p => p.id === project1.id);
491+
project.should.have.property('attachments');
492+
project.should.have.property('description');
493+
project.should.have.property('billingAccountId');
490494
done();
491495
}
492496
});
@@ -507,16 +511,17 @@ describe('LIST Project', () => {
507511
const resJson = res.body;
508512
should.exist(resJson);
509513
resJson.should.have.lengthOf(3);
510-
resJson[0].should.have.property('id');
511-
resJson[0].should.have.property('type');
512-
resJson[0].should.have.property('billingAccountId');
513-
resJson[0].should.have.property('description');
514-
resJson[0].should.have.property('status');
515-
resJson[0].should.have.property('details');
516-
resJson[0].should.have.property('createdBy');
517-
resJson[0].should.have.property('updatedBy');
518-
resJson[0].should.have.property('members');
519-
resJson[0].should.have.property('attachments');
514+
const project = _.find(resJson, p => p.id === project1.id);
515+
project.should.have.property('id');
516+
project.should.have.property('type');
517+
project.should.have.property('billingAccountId');
518+
project.should.have.property('description');
519+
project.should.have.property('status');
520+
project.should.have.property('details');
521+
project.should.have.property('createdBy');
522+
project.should.have.property('updatedBy');
523+
project.should.have.property('members');
524+
project.should.have.property('attachments');
520525
done();
521526
}
522527
});
@@ -606,7 +611,7 @@ describe('LIST Project', () => {
606611

607612
it('should return project that match when filtering by id (exact)', (done) => {
608613
request(server)
609-
.get('/v5/projects/?id=1')
614+
.get(`/v5/projects/?id=${project1.id}`)
610615
.set({
611616
Authorization: `Bearer ${testUtil.jwts.admin}`,
612617
})
@@ -619,7 +624,7 @@ describe('LIST Project', () => {
619624
const resJson = res.body;
620625
should.exist(resJson);
621626
resJson.should.have.lengthOf(1);
622-
resJson[0].id.should.equal(1);
627+
resJson[0].id.should.equal(project1.id);
623628
resJson[0].name.should.equal('test1');
624629
done();
625630
}
@@ -1216,7 +1221,7 @@ describe('LIST Project', () => {
12161221
} else {
12171222
const resJson = res.body;
12181223
should.exist(resJson);
1219-
const project = _.find(resJson, p => p.id === 1);
1224+
const project = _.find(resJson, p => p.id === project1.id);
12201225
const member = _.find(project.members, m => m.id === 1);
12211226
member.should.not.have.property('email');
12221227
done();
@@ -1239,7 +1244,7 @@ describe('LIST Project', () => {
12391244
} else {
12401245
const resJson = res.body;
12411246
should.exist(resJson);
1242-
const project = _.find(resJson, p => p.id === 1);
1247+
const project = _.find(resJson, p => p.id === project1.id);
12431248
const member = _.find(project.members, m => m.id === 1);
12441249
member.should.have.property('email');
12451250
member.email.should.be.eq('test@test.com');
@@ -1283,8 +1288,9 @@ describe('LIST Project', () => {
12831288
} else {
12841289
const resJson = res.body;
12851290
should.exist(resJson);
1286-
resJson[0].invites[0].should.have.property('userId');
1287-
_.keys(resJson[0].invites[0]).length.should.be.eq(1);
1291+
const project = _.find(resJson, p => p.id === project1.id);
1292+
project.invites[0].should.have.property('userId');
1293+
_.keys(project.invites[0]).length.should.be.eq(1);
12881294
done();
12891295
}
12901296
});
@@ -1304,8 +1310,9 @@ describe('LIST Project', () => {
13041310
} else {
13051311
const resJson = res.body;
13061312
should.exist(resJson);
1307-
resJson[0].members[0].should.have.property('role');
1308-
_.keys(resJson[0].members[0]).length.should.be.eq(1);
1313+
const project = _.find(resJson, p => p.id === project1.id);
1314+
project.members[0].should.have.property('role');
1315+
_.keys(project.members[0]).length.should.be.eq(1);
13091316
done();
13101317
}
13111318
});
@@ -1325,8 +1332,9 @@ describe('LIST Project', () => {
13251332
} else {
13261333
const resJson = res.body;
13271334
should.exist(resJson);
1328-
resJson[0].attachments[0].should.have.property('title');
1329-
_.keys(resJson[0].attachments[0]).length.should.be.eq(1);
1335+
const project = _.find(resJson, p => p.id === project1.id);
1336+
project.attachments[0].should.have.property('title');
1337+
_.keys(project.attachments[0]).length.should.be.eq(1);
13301338
done();
13311339
}
13321340
});
@@ -1346,7 +1354,7 @@ describe('LIST Project', () => {
13461354
} else {
13471355
const resJson = res.body;
13481356
should.exist(resJson);
1349-
const project = _.find(resJson, p => p.id === 1);
1357+
const project = _.find(resJson, p => p.id === project1.id);
13501358
project.phases[0].should.have.property('name');
13511359
_.keys(project.phases[0]).length.should.be.eq(1);
13521360
done();
@@ -1368,7 +1376,7 @@ describe('LIST Project', () => {
13681376
} else {
13691377
const resJson = res.body;
13701378
should.exist(resJson);
1371-
const project = _.find(resJson, p => p.id === 1);
1379+
const project = _.find(resJson, p => p.id === project1.id);
13721380
project.phases[0].products[0].should.have.property('name');
13731381
_.keys(project.phases[0].products[0]).length.should.be.eq(1);
13741382
done();

0 commit comments

Comments
 (0)