Skip to content

Commit 8d4c36c

Browse files
author
Vikas Agarwal
committed
fixed issue with backward compatibility code
1 parent d0cdd1e commit 8d4c36c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/routes/projects/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function createProjectAndPhases(req, project, projectTemplate, productTemplates)
135135
function validateAndFetchTemplates(templateId) {
136136
// backward compatibility for releasing the service before releasing the front end
137137
// we ignore missing template id field and create a project without phase/products
138-
if (!templateId) return Promise.resolve(null);
138+
if (!templateId) return Promise.resolve({});
139139
return models.ProjectTemplate.findById(templateId, { raw: true })
140140
.then((existingProjectTemplate) => {
141141
if (!existingProjectTemplate) {

src/routes/projects/create.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,61 @@ describe('Project create', () => {
329329
});
330330
});
331331

332+
it('should return 201 if valid user and data (without template id: backward compatibility)', (done) => {
333+
const validBody = _.cloneDeep(body);
334+
const mockHttpClient = _.merge(testUtil.mockHttpClient, {
335+
post: () => Promise.resolve({
336+
status: 200,
337+
data: {
338+
id: 'requesterId',
339+
version: 'v3',
340+
result: {
341+
success: true,
342+
status: 200,
343+
content: {
344+
projectId: 128,
345+
},
346+
},
347+
},
348+
}),
349+
});
350+
sandbox.stub(util, 'getHttpClient', () => mockHttpClient);
351+
request(server)
352+
.post('/v4/projects')
353+
.set({
354+
Authorization: `Bearer ${testUtil.jwts.member}`,
355+
})
356+
.send(validBody)
357+
.expect('Content-Type', /json/)
358+
.expect(201)
359+
.end((err, res) => {
360+
if (err) {
361+
done(err);
362+
} else {
363+
const resJson = res.body.result.content;
364+
should.exist(resJson);
365+
should.exist(resJson.billingAccountId);
366+
should.exist(resJson.name);
367+
resJson.directProjectId.should.be.eql(128);
368+
resJson.status.should.be.eql('draft');
369+
resJson.type.should.be.eql(body.param.type);
370+
resJson.version.should.be.eql('v3');
371+
resJson.members.should.have.lengthOf(1);
372+
resJson.members[0].role.should.be.eql('customer');
373+
resJson.members[0].userId.should.be.eql(40051331);
374+
resJson.members[0].projectId.should.be.eql(resJson.id);
375+
resJson.members[0].isPrimary.should.be.truthy;
376+
resJson.bookmarks.should.have.lengthOf(1);
377+
resJson.bookmarks[0].title.should.be.eql('title1');
378+
resJson.bookmarks[0].address.should.be.eql('http://www.address.com');
379+
server.services.pubsub.publish.calledWith('project.draft-created').should.be.true;
380+
// should not create phases without a template id
381+
resJson.phases.should.have.lengthOf(0);
382+
done();
383+
}
384+
});
385+
});
386+
332387
it('should return 201 if valid user and data (with templateId)', (done) => {
333388
const mockHttpClient = _.merge(testUtil.mockHttpClient, {
334389
post: () => Promise.resolve({

0 commit comments

Comments
 (0)