Skip to content

Commit 1a2e995

Browse files
authored
Merge pull request #660 from eisbilir/feature/new-milestone-concept
Updated maxPhaseProductCount to 100 and fix tests accordingly. Include members in the phase update.
2 parents 7f02ec1 + fc7c959 commit 1a2e995

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

config/default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"messageApiUrl": "http://api.topcoder-dev.com/v5",
4646
"busApiToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoicHJvamVjdC1zZXJ2aWNlIiwiaWF0IjoxNTEyNzQ3MDgyLCJleHAiOjE1MjEzODcwODJ9.PHuNcFDaotGAL8RhQXQMdpL8yOKXxjB5DbBIodmt7RE",
4747
"HEALTH_CHECK_URL": "_health",
48-
"maxPhaseProductCount": 1,
48+
"maxPhaseProductCount": 100,
4949
"TOKEN_CACHE_TIME": "86000",
5050
"whitelistedOriginsForUserIdAuth": "[\"https:\/\/topcoder-newauth.auth0.com\/\",\"https:\/\/api.topcoder-dev.com\"]",
5151
"EMAIL_INVITE_FROM_NAME": "Topcoder",

src/routes/phases/update.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ const updateProjectPhaseValidation = {
2626
order: Joi.number().integer().optional(),
2727
}).required(),
2828
};
29-
29+
const populateMemberDetails = async (phase, req) => {
30+
const members = _.map(phase.members, member => _.pick(member, 'userId'));
31+
try {
32+
const detailedMembers = await util.getObjectsWithMemberDetails(members, ['userId', 'handle', 'photoURL'], req);
33+
return _.assign(phase, { members: detailedMembers });
34+
} catch (err) {
35+
return _.assign(phase, { members });
36+
}
37+
};
3038

3139
module.exports = [
3240
// validate request payload
@@ -102,8 +110,14 @@ module.exports = [
102110
updatedValue,
103111
previousValue,
104112
ROUTES.PHASES.UPDATE);
105-
106-
res.json(updated);
113+
return models.ProjectPhase.findOne({
114+
where: { id: phaseId, projectId },
115+
include: [{
116+
model: models.ProjectPhaseMember,
117+
as: 'members',
118+
}],
119+
}).then(phaseWithMembers => populateMemberDetails(phaseWithMembers.toJSON(), req)
120+
.then(result => res.json(result)));
107121
})
108122
.catch(err => next(err));
109123
},

src/routes/projects/create.spec.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const should = chai.should();
1616
const expect = chai.expect;
1717

1818
describe('Project create', () => {
19-
before((done) => {
19+
before(function beforeHook(done) {
20+
this.timeout(20000);
2021
testUtil.clearDb()
2122
.then(() => testUtil.clearES())
2223
.then(() => models.ProjectType.bulkCreate([
@@ -76,8 +77,16 @@ describe('Project create', () => {
7677
updatedBy: 4,
7778
},
7879
]))
79-
.then(() => models.ProjectTemplate.bulkCreate([
80-
{
80+
.then(() => {
81+
const exceededProducts = [];
82+
for (let i = 1; i <= _.parseInt(config.get('maxPhaseProductCount')) + 1; i += 1) {
83+
exceededProducts.push({
84+
id: i,
85+
name: `product ${i}`,
86+
productKey: `visual_design_prod${i}`,
87+
});
88+
}
89+
return models.ProjectTemplate.bulkCreate([{
8190
id: 1,
8291
name: 'template 1',
8392
key: 'key 1',
@@ -91,18 +100,7 @@ describe('Project create', () => {
91100
phase1: {
92101
name: 'phase 1',
93102
duration: 5,
94-
products: [
95-
{
96-
id: 21,
97-
name: 'product 1',
98-
productKey: 'visual_design_prod1',
99-
},
100-
{
101-
id: 22,
102-
name: 'product 2',
103-
productKey: 'visual_design_prod2',
104-
},
105-
],
103+
products: exceededProducts,
106104
},
107105
},
108106
createdBy: 1,
@@ -206,8 +204,8 @@ describe('Project create', () => {
206204
},
207205
createdBy: 1,
208206
updatedBy: 2,
209-
},
210-
]))
207+
}]);
208+
})
211209
.then(() => models.BuildingBlock.bulkCreate([
212210
{
213211
id: 1,

0 commit comments

Comments
 (0)