Skip to content

Commit 1602c6c

Browse files
architectt1gondzo
authored andcommitted
Added metadata JSON field. (#115)
1 parent 380fddf commit 1602c6c

File tree

11 files changed

+97
-0
lines changed

11 files changed

+97
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--
2+
-- UPDATE EXISTING TABLES:
3+
-- project_types
4+
-- metadata column: added
5+
--
6+
7+
--
8+
-- project_types
9+
--
10+
11+
ALTER TABLE project_types ADD COLUMN "metadata" json;
12+
UPDATE project_types set metadata='{}' where metadata is null;
13+
ALTER TABLE project_types ALTER COLUMN "metadata" SET NOT NULL;

src/models/projectType.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = function definePhaseProduct(sequelize, DataTypes) {
1010
aliases: { type: DataTypes.JSON, allowNull: false },
1111
disabled: { type: DataTypes.BOOLEAN, defaultValue: false },
1212
hidden: { type: DataTypes.BOOLEAN, defaultValue: false },
13+
metadata: { type: DataTypes.JSON, allowNull: false },
1314

1415
deletedAt: { type: DataTypes.DATE, allowNull: true },
1516
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },

src/routes/projectTypes/create.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const schema = {
2121
aliases: Joi.array().required(),
2222
disabled: Joi.boolean().optional(),
2323
hidden: Joi.boolean().optional(),
24+
metadata: Joi.object().required(),
2425
createdAt: Joi.any().strip(),
2526
updatedAt: Joi.any().strip(),
2627
deletedAt: Joi.any().strip(),

src/routes/projectTypes/create.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('CREATE project type', () => {
2222
aliases: ['key-1', 'key_1'],
2323
disabled: false,
2424
hidden: false,
25+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
2526
createdBy: 1,
2627
updatedBy: 1,
2728
})).then(() => Promise.resolve()),
@@ -39,6 +40,7 @@ describe('CREATE project type', () => {
3940
aliases: ['key-1', 'key_1'],
4041
disabled: true,
4142
hidden: true,
43+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
4244
},
4345
};
4446

@@ -149,6 +151,20 @@ describe('CREATE project type', () => {
149151
.expect(422, done);
150152
});
151153

154+
it('should return 422 for missing metadata', (done) => {
155+
const invalidBody = _.cloneDeep(body);
156+
delete invalidBody.param.metadata;
157+
158+
request(server)
159+
.post('/v4/projectTypes')
160+
.set({
161+
Authorization: `Bearer ${testUtil.jwts.admin}`,
162+
})
163+
.send(invalidBody)
164+
.expect('Content-Type', /json/)
165+
.expect(422, done);
166+
});
167+
152168
it('should return 422 for duplicated key', (done) => {
153169
const invalidBody = _.cloneDeep(body);
154170
invalidBody.param.key = 'key1';
@@ -182,6 +198,7 @@ describe('CREATE project type', () => {
182198
resJson.aliases.should.be.eql(body.param.aliases);
183199
resJson.disabled.should.be.eql(body.param.disabled);
184200
resJson.hidden.should.be.eql(body.param.hidden);
201+
resJson.metadata.should.be.eql(body.param.metadata);
185202

186203
resJson.createdBy.should.be.eql(40051333); // admin
187204
should.exist(resJson.createdAt);
@@ -213,6 +230,7 @@ describe('CREATE project type', () => {
213230
resJson.aliases.should.be.eql(body.param.aliases);
214231
resJson.disabled.should.be.eql(body.param.disabled);
215232
resJson.hidden.should.be.eql(body.param.hidden);
233+
resJson.metadata.should.be.eql(body.param.metadata);
216234
resJson.createdBy.should.be.eql(40051336); // connect admin
217235
resJson.updatedBy.should.be.eql(40051336); // connect admin
218236
done();

src/routes/projectTypes/delete.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('DELETE project type', () => {
1919
question: 'question 1',
2020
info: 'info 1',
2121
aliases: ['key-1', 'key_1'],
22+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
2223
createdBy: 1,
2324
updatedBy: 1,
2425
})).then(() => Promise.resolve()),

src/routes/projectTypes/get.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('GET project type', () => {
2020
aliases: ['key-1', 'key_1'],
2121
disabled: true,
2222
hidden: true,
23+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
2324
createdBy: 1,
2425
updatedBy: 1,
2526
};
@@ -71,6 +72,7 @@ describe('GET project type', () => {
7172
resJson.aliases.should.be.eql(type.aliases);
7273
resJson.disabled.should.be.eql(type.disabled);
7374
resJson.hidden.should.be.eql(type.hidden);
75+
resJson.metadata.should.be.eql(type.metadata);
7476
resJson.createdBy.should.be.eql(type.createdBy);
7577
should.exist(resJson.createdAt);
7678
resJson.updatedBy.should.be.eql(type.updatedBy);

src/routes/projectTypes/list.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('LIST project types', () => {
2121
aliases: ['key-1', 'key_1'],
2222
disabled: true,
2323
hidden: true,
24+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
2425
createdBy: 1,
2526
updatedBy: 1,
2627
},
@@ -33,6 +34,7 @@ describe('LIST project types', () => {
3334
aliases: ['key-2', 'key_2'],
3435
disabled: true,
3536
hidden: true,
37+
metadata: { 'slack-notification-mappings': { color: '#b47dd6', label: 'Full App 2' } },
3638
createdBy: 1,
3739
updatedBy: 1,
3840
},
@@ -67,6 +69,7 @@ describe('LIST project types', () => {
6769
resJson[0].createdBy.should.be.eql(type.createdBy);
6870
resJson[0].disabled.should.be.eql(type.disabled);
6971
resJson[0].hidden.should.be.eql(type.hidden);
72+
resJson[0].metadata.should.be.eql(type.metadata);
7073
should.exist(resJson[0].createdAt);
7174
resJson[0].updatedBy.should.be.eql(type.updatedBy);
7275
should.exist(resJson[0].updatedAt);

src/routes/projectTypes/update.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const schema = {
2424
aliases: Joi.array().optional(),
2525
disabled: Joi.boolean().optional(),
2626
hidden: Joi.boolean().optional(),
27+
metadata: Joi.object().optional(),
2728
createdAt: Joi.any().strip(),
2829
updatedAt: Joi.any().strip(),
2930
deletedAt: Joi.any().strip(),

src/routes/projectTypes/update.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('UPDATE project type', () => {
2121
aliases: ['key-1', 'key_1'],
2222
disabled: false,
2323
hidden: false,
24+
metadata: { 'slack-notification-mappings': { color: '#96d957', label: 'Full App' } },
2425
createdBy: 1,
2526
updatedBy: 1,
2627
};
@@ -42,6 +43,7 @@ describe('UPDATE project type', () => {
4243
aliases: ['key-1-updated', 'key_1_updated'],
4344
disabled: true,
4445
hidden: true,
46+
metadata: { 'slack-notification-mappings': { color: '#b47dd6', label: 'Full App 2' } },
4547
},
4648
};
4749

@@ -113,6 +115,7 @@ describe('UPDATE project type', () => {
113115
delete partialBody.param.aliases;
114116
delete partialBody.param.disabled;
115117
delete partialBody.param.hidden;
118+
delete partialBody.param.metadata;
116119
request(server)
117120
.patch(`/v4/projectTypes/${key}`)
118121
.set({
@@ -130,6 +133,7 @@ describe('UPDATE project type', () => {
130133
resJson.aliases.should.be.eql(type.aliases);
131134
resJson.disabled.should.be.eql(type.disabled);
132135
resJson.hidden.should.be.eql(type.hidden);
136+
resJson.metadata.should.be.eql(type.metadata);
133137
resJson.createdBy.should.be.eql(type.createdBy);
134138
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
135139
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -149,6 +153,7 @@ describe('UPDATE project type', () => {
149153
delete partialBody.param.aliases;
150154
delete partialBody.param.disabled;
151155
delete partialBody.param.hidden;
156+
delete partialBody.param.metadata;
152157
request(server)
153158
.patch(`/v4/projectTypes/${key}`)
154159
.set({
@@ -166,6 +171,7 @@ describe('UPDATE project type', () => {
166171
resJson.aliases.should.be.eql(type.aliases);
167172
resJson.disabled.should.be.eql(type.disabled);
168173
resJson.hidden.should.be.eql(type.hidden);
174+
resJson.metadata.should.be.eql(type.metadata);
169175
resJson.createdBy.should.be.eql(type.createdBy);
170176
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
171177
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -185,6 +191,7 @@ describe('UPDATE project type', () => {
185191
delete partialBody.param.aliases;
186192
delete partialBody.param.disabled;
187193
delete partialBody.param.hidden;
194+
delete partialBody.param.metadata;
188195
request(server)
189196
.patch(`/v4/projectTypes/${key}`)
190197
.set({
@@ -202,6 +209,7 @@ describe('UPDATE project type', () => {
202209
resJson.aliases.should.be.eql(type.aliases);
203210
resJson.disabled.should.be.eql(type.disabled);
204211
resJson.hidden.should.be.eql(type.hidden);
212+
resJson.metadata.should.be.eql(type.metadata);
205213
resJson.createdBy.should.be.eql(type.createdBy);
206214
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
207215
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -221,6 +229,7 @@ describe('UPDATE project type', () => {
221229
delete partialBody.param.aliases;
222230
delete partialBody.param.disabled;
223231
delete partialBody.param.hidden;
232+
delete partialBody.param.metadata;
224233
request(server)
225234
.patch(`/v4/projectTypes/${key}`)
226235
.set({
@@ -238,6 +247,7 @@ describe('UPDATE project type', () => {
238247
resJson.aliases.should.be.eql(type.aliases);
239248
resJson.disabled.should.be.eql(type.disabled);
240249
resJson.hidden.should.be.eql(type.hidden);
250+
resJson.metadata.should.be.eql(type.metadata);
241251
resJson.createdBy.should.be.eql(type.createdBy);
242252
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
243253
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -257,6 +267,7 @@ describe('UPDATE project type', () => {
257267
delete partialBody.param.displayName;
258268
delete partialBody.param.disabled;
259269
delete partialBody.param.hidden;
270+
delete partialBody.param.metadata;
260271
request(server)
261272
.patch(`/v4/projectTypes/${key}`)
262273
.set({
@@ -274,6 +285,7 @@ describe('UPDATE project type', () => {
274285
resJson.aliases.should.be.eql(partialBody.param.aliases);
275286
resJson.disabled.should.be.eql(type.disabled);
276287
resJson.hidden.should.be.eql(type.hidden);
288+
resJson.metadata.should.be.eql(type.metadata);
277289
resJson.createdBy.should.be.eql(type.createdBy);
278290
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
279291
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -293,6 +305,7 @@ describe('UPDATE project type', () => {
293305
delete partialBody.param.displayName;
294306
delete partialBody.param.aliases;
295307
delete partialBody.param.hidden;
308+
delete partialBody.param.metadata;
296309
request(server)
297310
.patch(`/v4/projectTypes/${key}`)
298311
.set({
@@ -310,6 +323,7 @@ describe('UPDATE project type', () => {
310323
resJson.aliases.should.be.eql(type.aliases);
311324
resJson.disabled.should.be.eql(partialBody.param.disabled);
312325
resJson.hidden.should.be.eql(type.hidden);
326+
resJson.metadata.should.be.eql(type.metadata);
313327
resJson.createdBy.should.be.eql(type.createdBy);
314328
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
315329
resJson.updatedBy.should.be.eql(40051333); // admin
@@ -329,6 +343,7 @@ describe('UPDATE project type', () => {
329343
delete partialBody.param.displayName;
330344
delete partialBody.param.disabled;
331345
delete partialBody.param.aliases;
346+
delete partialBody.param.metadata;
332347
request(server)
333348
.patch(`/v4/projectTypes/${key}`)
334349
.set({
@@ -346,6 +361,44 @@ describe('UPDATE project type', () => {
346361
resJson.aliases.should.be.eql(type.aliases);
347362
resJson.disabled.should.be.eql(type.disabled);
348363
resJson.hidden.should.be.eql(partialBody.param.hidden);
364+
resJson.metadata.should.be.eql(type.metadata);
365+
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
366+
resJson.updatedBy.should.be.eql(40051333); // admin
367+
should.exist(resJson.updatedAt);
368+
should.not.exist(resJson.deletedBy);
369+
should.not.exist(resJson.deletedAt);
370+
371+
done();
372+
});
373+
});
374+
375+
it('should return 200 for admin metadata updated', (done) => {
376+
const partialBody = _.cloneDeep(body);
377+
delete partialBody.param.icon;
378+
delete partialBody.param.info;
379+
delete partialBody.param.question;
380+
delete partialBody.param.displayName;
381+
delete partialBody.param.disabled;
382+
delete partialBody.param.aliases;
383+
delete partialBody.param.hidden;
384+
request(server)
385+
.patch(`/v4/projectTypes/${key}`)
386+
.set({
387+
Authorization: `Bearer ${testUtil.jwts.admin}`,
388+
})
389+
.send(partialBody)
390+
.expect(200)
391+
.end((err, res) => {
392+
const resJson = res.body.result.content;
393+
resJson.key.should.be.eql(key);
394+
resJson.displayName.should.be.eql(type.displayName);
395+
resJson.icon.should.be.eql(type.icon);
396+
resJson.info.should.be.eql(type.info);
397+
resJson.question.should.be.eql(type.question);
398+
resJson.aliases.should.be.eql(type.aliases);
399+
resJson.disabled.should.be.eql(type.disabled);
400+
resJson.hidden.should.be.eql(type.hidden);
401+
resJson.metadata.should.be.eql(partialBody.param.metadata);
349402
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
350403
resJson.updatedBy.should.be.eql(40051333); // admin
351404
should.exist(resJson.updatedAt);
@@ -374,6 +427,7 @@ describe('UPDATE project type', () => {
374427
resJson.aliases.should.be.eql(body.param.aliases);
375428
resJson.disabled.should.be.eql(body.param.disabled);
376429
resJson.hidden.should.be.eql(body.param.hidden);
430+
resJson.metadata.should.be.eql(body.param.metadata);
377431
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
378432
resJson.updatedBy.should.be.eql(40051333); // admin
379433
should.exist(resJson.updatedAt);
@@ -402,6 +456,7 @@ describe('UPDATE project type', () => {
402456
resJson.aliases.should.be.eql(body.param.aliases);
403457
resJson.disabled.should.be.eql(body.param.disabled);
404458
resJson.hidden.should.be.eql(body.param.hidden);
459+
resJson.metadata.should.be.eql(body.param.metadata);
405460
resJson.createdBy.should.be.eql(type.createdBy); // should not update createdAt
406461
resJson.updatedBy.should.be.eql(40051336); // connect admin
407462
done();

src/routes/projects/create.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Project create', () => {
2626
question: 'question 1',
2727
info: 'info 1',
2828
aliases: ['key-1', 'key_1'],
29+
metadata: {},
2930
createdBy: 1,
3031
updatedBy: 1,
3132
},

src/routes/projects/update.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('Project', () => {
3030
aliases: ['key-1', 'key_1'],
3131
createdBy: 1,
3232
updatedBy: 1,
33+
metadata: {},
3334
},
3435
]))
3536
.then(() => done());

0 commit comments

Comments
 (0)