Skip to content

Commit 993a19d

Browse files
author
Vikas Agarwal
committed
Added hidden and disabled field for project types
1 parent f96a7ff commit 993a19d

File tree

8 files changed

+127
-2
lines changed

8 files changed

+127
-2
lines changed

migrations/20180704_project_types_extension.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ ALTER TABLE project_types ALTER COLUMN "question" SET NOT NULL;
2424

2525
ALTER TABLE project_types ADD COLUMN "aliases" json;
2626
UPDATE project_types set aliases='{}' where aliases is null;
27-
ALTER TABLE project_types ALTER COLUMN "aliases" SET NOT NULL;
27+
ALTER TABLE project_types ALTER COLUMN "aliases" SET NOT NULL;
28+
29+
ALTER TABLE project_types ADD COLUMN "hidden" boolean DEFAULT false;
30+
ALTER TABLE project_types ADD COLUMN "disabled" boolean DEFAULT false;

src/models/projectType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module.exports = function definePhaseProduct(sequelize, DataTypes) {
88
question: { type: DataTypes.STRING(255), allowNull: false },
99
info: { type: DataTypes.STRING(255), allowNull: false },
1010
aliases: { type: DataTypes.JSON, allowNull: false },
11+
disabled: { type: DataTypes.BOOLEAN, defaultValue: false },
12+
hidden: { type: DataTypes.BOOLEAN, defaultValue: false },
1113

1214
deletedAt: { type: DataTypes.DATE, allowNull: true },
1315
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },

src/routes/projectTypes/create.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const schema = {
1919
question: Joi.string().max(255).required(),
2020
info: Joi.string().max(255).required(),
2121
aliases: Joi.array().required(),
22+
disabled: Joi.boolean().optional(),
23+
hidden: Joi.boolean().optional(),
2224
createdAt: Joi.any().strip(),
2325
updatedAt: Joi.any().strip(),
2426
deletedAt: Joi.any().strip(),

src/routes/projectTypes/create.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('CREATE project type', () => {
2020
question: 'question 1',
2121
info: 'info 1',
2222
aliases: ['key-1', 'key_1'],
23+
disabled: false,
24+
hidden: false,
2325
createdBy: 1,
2426
updatedBy: 1,
2527
})).then(() => Promise.resolve()),
@@ -35,6 +37,8 @@ describe('CREATE project type', () => {
3537
info: 'Application Development Info',
3638
question: 'What kind of devlopment you need?',
3739
aliases: ['key-1', 'key_1'],
40+
disabled: true,
41+
hidden: true,
3842
},
3943
};
4044

@@ -176,6 +180,8 @@ describe('CREATE project type', () => {
176180
resJson.info.should.be.eql(body.param.info);
177181
resJson.question.should.be.eql(body.param.question);
178182
resJson.aliases.should.be.eql(body.param.aliases);
183+
resJson.disabled.should.be.eql(body.param.disabled);
184+
resJson.hidden.should.be.eql(body.param.hidden);
179185

180186
resJson.createdBy.should.be.eql(40051333); // admin
181187
should.exist(resJson.createdAt);
@@ -205,6 +211,8 @@ describe('CREATE project type', () => {
205211
resJson.info.should.be.eql(body.param.info);
206212
resJson.question.should.be.eql(body.param.question);
207213
resJson.aliases.should.be.eql(body.param.aliases);
214+
resJson.disabled.should.be.eql(body.param.disabled);
215+
resJson.hidden.should.be.eql(body.param.hidden);
208216
resJson.createdBy.should.be.eql(40051336); // connect admin
209217
resJson.updatedBy.should.be.eql(40051336); // connect admin
210218
done();

src/routes/projectTypes/get.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe('GET project type', () => {
1818
question: 'question 1',
1919
info: 'info 1',
2020
aliases: ['key-1', 'key_1'],
21+
disabled: true,
22+
hidden: true,
2123
createdBy: 1,
2224
updatedBy: 1,
2325
};
@@ -73,6 +75,8 @@ describe('GET project type', () => {
7375
resJson.info.should.be.eql(type.info);
7476
resJson.question.should.be.eql(type.question);
7577
resJson.aliases.should.be.eql(type.aliases);
78+
resJson.disabled.should.be.eql(type.disabled);
79+
resJson.hidden.should.be.eql(type.hidden);
7680
resJson.createdBy.should.be.eql(type.createdBy);
7781
should.exist(resJson.createdAt);
7882
resJson.updatedBy.should.be.eql(type.updatedBy);

src/routes/projectTypes/list.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('LIST project types', () => {
1919
question: 'question 1',
2020
info: 'info 1',
2121
aliases: ['key-1', 'key_1'],
22+
disabled: true,
23+
hidden: true,
2224
createdBy: 1,
2325
updatedBy: 1,
2426
},
@@ -29,6 +31,8 @@ describe('LIST project types', () => {
2931
question: 'question 2',
3032
info: 'info 2',
3133
aliases: ['key-2', 'key_2'],
34+
disabled: true,
35+
hidden: true,
3236
createdBy: 1,
3337
updatedBy: 1,
3438
},
@@ -67,6 +71,8 @@ describe('LIST project types', () => {
6771
resJson[0].question.should.be.eql(type.question);
6872
resJson[0].aliases.should.be.eql(type.aliases);
6973
resJson[0].createdBy.should.be.eql(type.createdBy);
74+
resJson[0].disabled.should.be.eql(type.disabled);
75+
resJson[0].hidden.should.be.eql(type.hidden);
7076
should.exist(resJson[0].createdAt);
7177
resJson[0].updatedBy.should.be.eql(type.updatedBy);
7278
should.exist(resJson[0].updatedAt);

src/routes/projectTypes/update.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const schema = {
2222
question: Joi.string().max(255).optional(),
2323
info: Joi.string().max(255).optional(),
2424
aliases: Joi.array().optional(),
25+
disabled: Joi.boolean().optional(),
26+
hidden: Joi.boolean().optional(),
2527
createdAt: Joi.any().strip(),
2628
updatedAt: Joi.any().strip(),
2729
deletedAt: Joi.any().strip(),

src/routes/projectTypes/update.spec.js

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('UPDATE project type', () => {
1919
question: 'question 1',
2020
info: 'info 1',
2121
aliases: ['key-1', 'key_1'],
22+
disabled: false,
23+
hidden: false,
2224
createdBy: 1,
2325
updatedBy: 1,
2426
};
@@ -38,6 +40,8 @@ describe('UPDATE project type', () => {
3840
question: 'question 1 - update',
3941
info: 'info 1 - update',
4042
aliases: ['key-1-updated', 'key_1_updated'],
43+
disabled: true,
44+
hidden: true,
4145
},
4246
};
4347

@@ -107,6 +111,8 @@ describe('UPDATE project type', () => {
107111
delete partialBody.param.info;
108112
delete partialBody.param.question;
109113
delete partialBody.param.aliases;
114+
delete partialBody.param.disabled;
115+
delete partialBody.param.hidden;
110116
request(server)
111117
.patch(`/v4/projectTypes/${key}`)
112118
.set({
@@ -122,6 +128,8 @@ describe('UPDATE project type', () => {
122128
resJson.info.should.be.eql(type.info);
123129
resJson.question.should.be.eql(type.question);
124130
resJson.aliases.should.be.eql(type.aliases);
131+
resJson.disabled.should.be.eql(type.disabled);
132+
resJson.hidden.should.be.eql(type.hidden);
125133
resJson.createdBy.should.be.eql(type.createdBy);
126134
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
127135
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -139,6 +147,8 @@ describe('UPDATE project type', () => {
139147
delete partialBody.param.displayName;
140148
delete partialBody.param.question;
141149
delete partialBody.param.aliases;
150+
delete partialBody.param.disabled;
151+
delete partialBody.param.hidden;
142152
request(server)
143153
.patch(`/v4/projectTypes/${key}`)
144154
.set({
@@ -154,6 +164,8 @@ describe('UPDATE project type', () => {
154164
resJson.info.should.be.eql(type.info);
155165
resJson.question.should.be.eql(type.question);
156166
resJson.aliases.should.be.eql(type.aliases);
167+
resJson.disabled.should.be.eql(type.disabled);
168+
resJson.hidden.should.be.eql(type.hidden);
157169
resJson.createdBy.should.be.eql(type.createdBy);
158170
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
159171
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -171,6 +183,8 @@ describe('UPDATE project type', () => {
171183
delete partialBody.param.displayName;
172184
delete partialBody.param.question;
173185
delete partialBody.param.aliases;
186+
delete partialBody.param.disabled;
187+
delete partialBody.param.hidden;
174188
request(server)
175189
.patch(`/v4/projectTypes/${key}`)
176190
.set({
@@ -186,6 +200,8 @@ describe('UPDATE project type', () => {
186200
resJson.info.should.be.eql(partialBody.param.info);
187201
resJson.question.should.be.eql(type.question);
188202
resJson.aliases.should.be.eql(type.aliases);
203+
resJson.disabled.should.be.eql(type.disabled);
204+
resJson.hidden.should.be.eql(type.hidden);
189205
resJson.createdBy.should.be.eql(type.createdBy);
190206
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
191207
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -203,6 +219,8 @@ describe('UPDATE project type', () => {
203219
delete partialBody.param.info;
204220
delete partialBody.param.displayName;
205221
delete partialBody.param.aliases;
222+
delete partialBody.param.disabled;
223+
delete partialBody.param.hidden;
206224
request(server)
207225
.patch(`/v4/projectTypes/${key}`)
208226
.set({
@@ -218,6 +236,8 @@ describe('UPDATE project type', () => {
218236
resJson.info.should.be.eql(type.info);
219237
resJson.question.should.be.eql(partialBody.param.question);
220238
resJson.aliases.should.be.eql(type.aliases);
239+
resJson.disabled.should.be.eql(type.disabled);
240+
resJson.hidden.should.be.eql(type.hidden);
221241
resJson.createdBy.should.be.eql(type.createdBy);
222242
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
223243
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -235,6 +255,8 @@ describe('UPDATE project type', () => {
235255
delete partialBody.param.info;
236256
delete partialBody.param.question;
237257
delete partialBody.param.displayName;
258+
delete partialBody.param.disabled;
259+
delete partialBody.param.hidden;
238260
request(server)
239261
.patch(`/v4/projectTypes/${key}`)
240262
.set({
@@ -250,6 +272,8 @@ describe('UPDATE project type', () => {
250272
resJson.info.should.be.eql(type.info);
251273
resJson.question.should.be.eql(type.question);
252274
resJson.aliases.should.be.eql(partialBody.param.aliases);
275+
resJson.disabled.should.be.eql(type.disabled);
276+
resJson.hidden.should.be.eql(type.hidden);
253277
resJson.createdBy.should.be.eql(type.createdBy);
254278
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
255279
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -261,6 +285,77 @@ describe('UPDATE project type', () => {
261285
});
262286
});
263287

288+
it('should return 200 for admin disabled updated', (done) => {
289+
const partialBody = _.cloneDeep(body);
290+
delete partialBody.param.icon;
291+
delete partialBody.param.info;
292+
delete partialBody.param.question;
293+
delete partialBody.param.displayName;
294+
delete partialBody.param.aliases;
295+
delete partialBody.param.hidden;
296+
request(server)
297+
.patch(`/v4/projectTypes/${key}`)
298+
.set({
299+
Authorization: `Bearer ${testUtil.jwts.admin}`,
300+
})
301+
.send(partialBody)
302+
.expect(200)
303+
.end((err, res) => {
304+
const resJson = res.body.result.content;
305+
resJson.key.should.be.eql(key);
306+
resJson.displayName.should.be.eql(type.displayName);
307+
resJson.icon.should.be.eql(type.icon);
308+
resJson.info.should.be.eql(type.info);
309+
resJson.question.should.be.eql(type.question);
310+
resJson.aliases.should.be.eql(type.aliases);
311+
resJson.disabled.should.be.eql(partialBody.param.disabled);
312+
resJson.hidden.should.be.eql(type.hidden);
313+
resJson.createdBy.should.be.eql(type.createdBy);
314+
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
315+
resJson.updatedBy.should.be.eql(40051333); // admin
316+
should.exist(resJson.updatedAt);
317+
should.not.exist(resJson.deletedBy);
318+
should.not.exist(resJson.deletedAt);
319+
320+
done();
321+
});
322+
});
323+
324+
it('should return 200 for admin hidden updated', (done) => {
325+
const partialBody = _.cloneDeep(body);
326+
delete partialBody.param.icon;
327+
delete partialBody.param.info;
328+
delete partialBody.param.question;
329+
delete partialBody.param.displayName;
330+
delete partialBody.param.disabled;
331+
delete partialBody.param.aliases;
332+
request(server)
333+
.patch(`/v4/projectTypes/${key}`)
334+
.set({
335+
Authorization: `Bearer ${testUtil.jwts.admin}`,
336+
})
337+
.send(partialBody)
338+
.expect(200)
339+
.end((err, res) => {
340+
const resJson = res.body.result.content;
341+
resJson.key.should.be.eql(key);
342+
resJson.displayName.should.be.eql(type.displayName);
343+
resJson.icon.should.be.eql(type.icon);
344+
resJson.info.should.be.eql(type.info);
345+
resJson.question.should.be.eql(type.question);
346+
resJson.aliases.should.be.eql(type.aliases);
347+
resJson.disabled.should.be.eql(type.disabled);
348+
resJson.hidden.should.be.eql(partialBody.param.hidden);
349+
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
350+
resJson.updatedBy.should.be.eql(40051333); // admin
351+
should.exist(resJson.updatedAt);
352+
should.not.exist(resJson.deletedBy);
353+
should.not.exist(resJson.deletedAt);
354+
355+
done();
356+
});
357+
});
358+
264359
it('should return 200 for admin all fields updated', (done) => {
265360
request(server)
266361
.patch(`/v4/projectTypes/${key}`)
@@ -277,7 +372,8 @@ describe('UPDATE project type', () => {
277372
resJson.info.should.be.eql(body.param.info);
278373
resJson.question.should.be.eql(body.param.question);
279374
resJson.aliases.should.be.eql(body.param.aliases);
280-
resJson.createdBy.should.be.eql(type.createdBy);
375+
resJson.disabled.should.be.eql(body.param.disabled);
376+
resJson.hidden.should.be.eql(body.param.hidden);
281377
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
282378
resJson.updatedBy.should.be.eql(40051333); // admin
283379
should.exist(resJson.updatedAt);
@@ -304,6 +400,8 @@ describe('UPDATE project type', () => {
304400
resJson.info.should.be.eql(body.param.info);
305401
resJson.question.should.be.eql(body.param.question);
306402
resJson.aliases.should.be.eql(body.param.aliases);
403+
resJson.disabled.should.be.eql(body.param.disabled);
404+
resJson.hidden.should.be.eql(body.param.hidden);
307405
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
308406
resJson.updatedBy.should.be.eql(40051336); // connect admin
309407
done();

0 commit comments

Comments
 (0)