@mbc-cqrs-serverless/survey-template 1.0.26 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handler/survey-answer-rds.handler.spec.d.ts +1 -0
- package/dist/handler/survey-answer-rds.handler.spec.js +278 -0
- package/dist/handler/survey-answer-rds.handler.spec.js.map +1 -0
- package/dist/handler/survey-template-rds.handler.spec.d.ts +1 -0
- package/dist/handler/survey-template-rds.handler.spec.js +227 -0
- package/dist/handler/survey-template-rds.handler.spec.js.map +1 -0
- package/dist/survey-answer.controller.spec.d.ts +1 -0
- package/dist/survey-answer.controller.spec.js +120 -0
- package/dist/survey-answer.controller.spec.js.map +1 -0
- package/dist/survey-answer.service.spec.d.ts +1 -0
- package/dist/survey-answer.service.spec.js +180 -0
- package/dist/survey-answer.service.spec.js.map +1 -0
- package/dist/survey-template.controller.spec.d.ts +1 -0
- package/dist/survey-template.controller.spec.js +225 -0
- package/dist/survey-template.controller.spec.js.map +1 -0
- package/dist/survey-template.service.spec.d.ts +1 -0
- package/dist/survey-template.service.spec.js +412 -0
- package/dist/survey-template.service.spec.js.map +1 -0
- package/dist/utils/utils.spec.d.ts +1 -0
- package/dist/utils/utils.spec.js +78 -0
- package/dist/utils/utils.spec.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const survey_answer_rds_handler_1 = require("./survey-answer-rds.handler");
|
|
5
|
+
const survey_template_module_definition_1 = require("../survey-template.module-definition");
|
|
6
|
+
describe('SurveyAnswerDataSyncRdsHandler', () => {
|
|
7
|
+
let handler;
|
|
8
|
+
let prismaService;
|
|
9
|
+
const mockPrismaService = {
|
|
10
|
+
surveyAnswer: {
|
|
11
|
+
upsert: jest.fn(),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
const module = await testing_1.Test.createTestingModule({
|
|
16
|
+
providers: [
|
|
17
|
+
survey_answer_rds_handler_1.SurveyAnswerDataSyncRdsHandler,
|
|
18
|
+
{
|
|
19
|
+
provide: survey_template_module_definition_1.PRISMA_SERVICE,
|
|
20
|
+
useValue: mockPrismaService,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}).compile();
|
|
24
|
+
handler = module.get(survey_answer_rds_handler_1.SurveyAnswerDataSyncRdsHandler);
|
|
25
|
+
prismaService = module.get(survey_template_module_definition_1.PRISMA_SERVICE);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
it('should be defined', () => {
|
|
31
|
+
expect(handler).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
describe('up', () => {
|
|
34
|
+
it('should upsert survey answer when sk starts with SURVEY_ANSWER#', async () => {
|
|
35
|
+
const cmd = {
|
|
36
|
+
id: 'answer-id-123',
|
|
37
|
+
pk: 'SURVEY#test-tenant',
|
|
38
|
+
sk: 'SURVEY_ANSWER#survey123#01HTEST@1',
|
|
39
|
+
code: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
40
|
+
type: 'SURVEY_ANSWER',
|
|
41
|
+
name: '',
|
|
42
|
+
version: 1,
|
|
43
|
+
seq: 1,
|
|
44
|
+
tenantCode: 'test-tenant',
|
|
45
|
+
attributes: {
|
|
46
|
+
surveyId: 'survey123',
|
|
47
|
+
answer: { q1: 'answer1', q2: 'answer2' },
|
|
48
|
+
email: 'test@example.com',
|
|
49
|
+
},
|
|
50
|
+
isDeleted: false,
|
|
51
|
+
createdAt: new Date('2024-01-01'),
|
|
52
|
+
createdBy: 'user1',
|
|
53
|
+
createdIp: '127.0.0.1',
|
|
54
|
+
updatedAt: new Date('2024-01-02'),
|
|
55
|
+
updatedBy: 'user2',
|
|
56
|
+
updatedIp: '127.0.0.2',
|
|
57
|
+
};
|
|
58
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
59
|
+
await handler.up(cmd);
|
|
60
|
+
expect(prismaService.surveyAnswer.upsert).toHaveBeenCalledWith({
|
|
61
|
+
where: { id: 'answer-id-123' },
|
|
62
|
+
update: {
|
|
63
|
+
csk: 'SURVEY_ANSWER#survey123#01HTEST@1',
|
|
64
|
+
name: '',
|
|
65
|
+
version: 1,
|
|
66
|
+
seq: 1,
|
|
67
|
+
isDeleted: false,
|
|
68
|
+
updatedAt: cmd.updatedAt,
|
|
69
|
+
updatedBy: 'user2',
|
|
70
|
+
updatedIp: '127.0.0.2',
|
|
71
|
+
attributes: { q1: 'answer1', q2: 'answer2' },
|
|
72
|
+
surveyId: 'survey123',
|
|
73
|
+
},
|
|
74
|
+
create: {
|
|
75
|
+
id: 'answer-id-123',
|
|
76
|
+
cpk: 'SURVEY#test-tenant',
|
|
77
|
+
csk: 'SURVEY_ANSWER#survey123#01HTEST@1',
|
|
78
|
+
pk: 'SURVEY#test-tenant',
|
|
79
|
+
sk: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
80
|
+
code: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
81
|
+
name: '',
|
|
82
|
+
version: 1,
|
|
83
|
+
tenantCode: 'test-tenant',
|
|
84
|
+
seq: 1,
|
|
85
|
+
createdAt: cmd.createdAt,
|
|
86
|
+
createdBy: 'user1',
|
|
87
|
+
createdIp: '127.0.0.1',
|
|
88
|
+
updatedAt: cmd.updatedAt,
|
|
89
|
+
updatedBy: 'user2',
|
|
90
|
+
updatedIp: '127.0.0.2',
|
|
91
|
+
attributes: { q1: 'answer1', q2: 'answer2' },
|
|
92
|
+
surveyId: 'survey123',
|
|
93
|
+
email: 'test@example.com',
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it('should skip non-SURVEY_ANSWER sk', async () => {
|
|
98
|
+
const cmd = {
|
|
99
|
+
id: 'survey-id-123',
|
|
100
|
+
pk: 'SURVEY#test-tenant',
|
|
101
|
+
sk: 'TEMPLATE#01HTEST',
|
|
102
|
+
code: 'TEMPLATE#01HTEST',
|
|
103
|
+
type: 'TEMPLATE',
|
|
104
|
+
name: 'Test Survey',
|
|
105
|
+
};
|
|
106
|
+
await handler.up(cmd);
|
|
107
|
+
expect(prismaService.surveyAnswer.upsert).not.toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
it('should skip sk that starts with SURVEY_ANSWER but not followed by #', async () => {
|
|
110
|
+
const cmd = {
|
|
111
|
+
id: 'answer-id-123',
|
|
112
|
+
pk: 'SURVEY#test-tenant',
|
|
113
|
+
sk: 'SURVEY_ANSWER_OTHER#01HTEST',
|
|
114
|
+
code: 'SURVEY_ANSWER_OTHER#01HTEST',
|
|
115
|
+
type: 'SURVEY_ANSWER_OTHER',
|
|
116
|
+
name: '',
|
|
117
|
+
};
|
|
118
|
+
await handler.up(cmd);
|
|
119
|
+
expect(prismaService.surveyAnswer.upsert).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
it('should handle deleted items', async () => {
|
|
122
|
+
const cmd = {
|
|
123
|
+
id: 'answer-id-456',
|
|
124
|
+
pk: 'SURVEY#test-tenant',
|
|
125
|
+
sk: 'SURVEY_ANSWER#survey456#01HTEST@2',
|
|
126
|
+
code: 'SURVEY_ANSWER#survey456#01HTEST',
|
|
127
|
+
type: 'SURVEY_ANSWER',
|
|
128
|
+
name: '',
|
|
129
|
+
version: 2,
|
|
130
|
+
seq: 2,
|
|
131
|
+
tenantCode: 'test-tenant',
|
|
132
|
+
attributes: {
|
|
133
|
+
surveyId: 'survey456',
|
|
134
|
+
answer: {},
|
|
135
|
+
},
|
|
136
|
+
isDeleted: true,
|
|
137
|
+
createdAt: new Date(),
|
|
138
|
+
updatedAt: new Date(),
|
|
139
|
+
};
|
|
140
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
141
|
+
await handler.up(cmd);
|
|
142
|
+
expect(prismaService.surveyAnswer.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
143
|
+
update: expect.objectContaining({
|
|
144
|
+
isDeleted: true,
|
|
145
|
+
}),
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
it('should remove version from sk for storage', async () => {
|
|
149
|
+
const cmd = {
|
|
150
|
+
id: 'answer-id-789',
|
|
151
|
+
pk: 'SURVEY#test-tenant',
|
|
152
|
+
sk: 'SURVEY_ANSWER#survey789#01HABC123@5',
|
|
153
|
+
code: 'SURVEY_ANSWER#survey789#01HABC123',
|
|
154
|
+
type: 'SURVEY_ANSWER',
|
|
155
|
+
name: '',
|
|
156
|
+
version: 5,
|
|
157
|
+
seq: 5,
|
|
158
|
+
tenantCode: 'test-tenant',
|
|
159
|
+
attributes: {
|
|
160
|
+
surveyId: 'survey789',
|
|
161
|
+
answer: {},
|
|
162
|
+
},
|
|
163
|
+
createdAt: new Date(),
|
|
164
|
+
updatedAt: new Date(),
|
|
165
|
+
};
|
|
166
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
167
|
+
await handler.up(cmd);
|
|
168
|
+
expect(prismaService.surveyAnswer.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
169
|
+
create: expect.objectContaining({
|
|
170
|
+
sk: 'SURVEY_ANSWER#survey789#01HABC123',
|
|
171
|
+
code: 'SURVEY_ANSWER#survey789#01HABC123',
|
|
172
|
+
}),
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
it('should handle undefined isDeleted as false', async () => {
|
|
176
|
+
const cmd = {
|
|
177
|
+
id: 'answer-id-def',
|
|
178
|
+
pk: 'SURVEY#test-tenant',
|
|
179
|
+
sk: 'SURVEY_ANSWER#surveydef#01HDEF@1',
|
|
180
|
+
code: 'SURVEY_ANSWER#surveydef#01HDEF',
|
|
181
|
+
type: 'SURVEY_ANSWER',
|
|
182
|
+
name: '',
|
|
183
|
+
version: 1,
|
|
184
|
+
seq: 1,
|
|
185
|
+
tenantCode: 'test-tenant',
|
|
186
|
+
attributes: {
|
|
187
|
+
surveyId: 'surveydef',
|
|
188
|
+
answer: {},
|
|
189
|
+
},
|
|
190
|
+
isDeleted: undefined,
|
|
191
|
+
createdAt: new Date(),
|
|
192
|
+
updatedAt: new Date(),
|
|
193
|
+
};
|
|
194
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
195
|
+
await handler.up(cmd);
|
|
196
|
+
expect(prismaService.surveyAnswer.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
197
|
+
update: expect.objectContaining({
|
|
198
|
+
isDeleted: false,
|
|
199
|
+
}),
|
|
200
|
+
}));
|
|
201
|
+
});
|
|
202
|
+
it('should include email in create but not in update', async () => {
|
|
203
|
+
const cmd = {
|
|
204
|
+
id: 'answer-id-email',
|
|
205
|
+
pk: 'SURVEY#test-tenant',
|
|
206
|
+
sk: 'SURVEY_ANSWER#surveyemail#01HEMAIL@1',
|
|
207
|
+
code: 'SURVEY_ANSWER#surveyemail#01HEMAIL',
|
|
208
|
+
type: 'SURVEY_ANSWER',
|
|
209
|
+
name: '',
|
|
210
|
+
version: 1,
|
|
211
|
+
seq: 1,
|
|
212
|
+
tenantCode: 'test-tenant',
|
|
213
|
+
attributes: {
|
|
214
|
+
surveyId: 'surveyemail',
|
|
215
|
+
answer: { q1: 'a1' },
|
|
216
|
+
email: 'user@domain.com',
|
|
217
|
+
},
|
|
218
|
+
createdAt: new Date(),
|
|
219
|
+
updatedAt: new Date(),
|
|
220
|
+
};
|
|
221
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
222
|
+
await handler.up(cmd);
|
|
223
|
+
const upsertCall = mockPrismaService.surveyAnswer.upsert.mock.calls[0][0];
|
|
224
|
+
// Create should have email
|
|
225
|
+
expect(upsertCall.create.email).toBe('user@domain.com');
|
|
226
|
+
// Update should NOT have email (email is only set on create)
|
|
227
|
+
expect(upsertCall.update.email).toBeUndefined();
|
|
228
|
+
});
|
|
229
|
+
it('should store answer from attributes', async () => {
|
|
230
|
+
const complexAnswer = {
|
|
231
|
+
question1: { type: 'text', value: 'answer1' },
|
|
232
|
+
question2: { type: 'choice', value: ['option1', 'option2'] },
|
|
233
|
+
question3: { type: 'rating', value: 5 },
|
|
234
|
+
};
|
|
235
|
+
const cmd = {
|
|
236
|
+
id: 'answer-id-complex',
|
|
237
|
+
pk: 'SURVEY#test-tenant',
|
|
238
|
+
sk: 'SURVEY_ANSWER#surveycomplex#01HCOMPLEX@1',
|
|
239
|
+
code: 'SURVEY_ANSWER#surveycomplex#01HCOMPLEX',
|
|
240
|
+
type: 'SURVEY_ANSWER',
|
|
241
|
+
name: '',
|
|
242
|
+
version: 1,
|
|
243
|
+
seq: 1,
|
|
244
|
+
tenantCode: 'test-tenant',
|
|
245
|
+
attributes: {
|
|
246
|
+
surveyId: 'surveycomplex',
|
|
247
|
+
answer: complexAnswer,
|
|
248
|
+
},
|
|
249
|
+
createdAt: new Date(),
|
|
250
|
+
updatedAt: new Date(),
|
|
251
|
+
};
|
|
252
|
+
mockPrismaService.surveyAnswer.upsert.mockResolvedValue({});
|
|
253
|
+
await handler.up(cmd);
|
|
254
|
+
expect(prismaService.surveyAnswer.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
255
|
+
update: expect.objectContaining({
|
|
256
|
+
attributes: complexAnswer,
|
|
257
|
+
}),
|
|
258
|
+
create: expect.objectContaining({
|
|
259
|
+
attributes: complexAnswer,
|
|
260
|
+
}),
|
|
261
|
+
}));
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
describe('down', () => {
|
|
265
|
+
it('should be defined and handle down operation', async () => {
|
|
266
|
+
const cmd = {
|
|
267
|
+
id: 'answer-id-123',
|
|
268
|
+
pk: 'SURVEY#test-tenant',
|
|
269
|
+
sk: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
270
|
+
code: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
271
|
+
type: 'SURVEY_ANSWER',
|
|
272
|
+
};
|
|
273
|
+
// down() currently just logs, so we just verify it doesn't throw
|
|
274
|
+
await expect(handler.down(cmd)).resolves.not.toThrow();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
//# sourceMappingURL=survey-answer-rds.handler.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"survey-answer-rds.handler.spec.js","sourceRoot":"","sources":["../../src/handler/survey-answer-rds.handler.spec.ts"],"names":[],"mappings":";;AAAA,6CAAqD;AAGrD,2EAA4E;AAC5E,4FAAqE;AAErE,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,IAAI,OAAuC,CAAA;IAC3C,IAAI,aAAkB,CAAA;IAEtB,MAAM,iBAAiB,GAAG;QACxB,YAAY,EAAE;YACZ,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;SAClB;KACF,CAAA;IAED,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,0DAA8B;gBAC9B;oBACE,OAAO,EAAE,kDAAc;oBACvB,QAAQ,EAAE,iBAAiB;iBAC5B;aACF;SACF,CAAC,CAAC,OAAO,EAAE,CAAA;QAEZ,OAAO,GAAG,MAAM,CAAC,GAAG,CAClB,0DAA8B,CAC/B,CAAA;QACD,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,kDAAc,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,IAAI,EAAE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AC9B,UAAU,EAAE,aAAa;iBAC1B,CAAC;gBACF,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC;oBAC9B,UAAU,EAAE,aAAa;iBAC1B,CAAC;aACH,CAAC,CACH,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,GAAG,GAAG;gBACV,EAAE,EAAE,eAAe;gBACnB,EAAE,EAAE,oBAAoB;gBACxB,EAAE,EAAE,iCAAiC;gBACrC,IAAI,EAAE,iCAAiC;gBACvC,IAAI,EAAE,eAAe;aACK,CAAA;YAE5B,iEAAiE;YACjE,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;QACxD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const survey_template_rds_handler_1 = require("./survey-template-rds.handler");
|
|
5
|
+
const survey_template_module_definition_1 = require("../survey-template.module-definition");
|
|
6
|
+
describe('SurveyTemplateDataSyncRdsHandler', () => {
|
|
7
|
+
let handler;
|
|
8
|
+
let prismaService;
|
|
9
|
+
const mockPrismaService = {
|
|
10
|
+
surveyTemplate: {
|
|
11
|
+
upsert: jest.fn(),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
const module = await testing_1.Test.createTestingModule({
|
|
16
|
+
providers: [
|
|
17
|
+
survey_template_rds_handler_1.SurveyTemplateDataSyncRdsHandler,
|
|
18
|
+
{
|
|
19
|
+
provide: survey_template_module_definition_1.PRISMA_SERVICE,
|
|
20
|
+
useValue: mockPrismaService,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}).compile();
|
|
24
|
+
handler = module.get(survey_template_rds_handler_1.SurveyTemplateDataSyncRdsHandler);
|
|
25
|
+
prismaService = module.get(survey_template_module_definition_1.PRISMA_SERVICE);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
it('should be defined', () => {
|
|
31
|
+
expect(handler).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
describe('up', () => {
|
|
34
|
+
it('should upsert survey template when sk starts with TEMPLATE', async () => {
|
|
35
|
+
const cmd = {
|
|
36
|
+
id: 'survey-id-123',
|
|
37
|
+
pk: 'SURVEY#test-tenant',
|
|
38
|
+
sk: 'TEMPLATE#01HTEST@1',
|
|
39
|
+
code: 'TEMPLATE#01HTEST',
|
|
40
|
+
type: 'TEMPLATE',
|
|
41
|
+
name: 'Test Survey',
|
|
42
|
+
version: 1,
|
|
43
|
+
seq: 1,
|
|
44
|
+
tenantCode: 'test-tenant',
|
|
45
|
+
attributes: {
|
|
46
|
+
description: 'Test description',
|
|
47
|
+
surveyTemplate: { questions: [] },
|
|
48
|
+
additionalProperties: { key: 'value' },
|
|
49
|
+
},
|
|
50
|
+
isDeleted: false,
|
|
51
|
+
createdAt: new Date('2024-01-01'),
|
|
52
|
+
createdBy: 'user1',
|
|
53
|
+
createdIp: '127.0.0.1',
|
|
54
|
+
updatedAt: new Date('2024-01-02'),
|
|
55
|
+
updatedBy: 'user2',
|
|
56
|
+
updatedIp: '127.0.0.2',
|
|
57
|
+
};
|
|
58
|
+
mockPrismaService.surveyTemplate.upsert.mockResolvedValue({});
|
|
59
|
+
await handler.up(cmd);
|
|
60
|
+
expect(prismaService.surveyTemplate.upsert).toHaveBeenCalledWith({
|
|
61
|
+
where: { id: 'survey-id-123' },
|
|
62
|
+
update: {
|
|
63
|
+
csk: 'TEMPLATE#01HTEST@1',
|
|
64
|
+
name: 'Test Survey',
|
|
65
|
+
version: 1,
|
|
66
|
+
seq: 1,
|
|
67
|
+
description: 'Test description',
|
|
68
|
+
surveyTemplate: { questions: [] },
|
|
69
|
+
additionalProperties: { key: 'value' },
|
|
70
|
+
isDeleted: false,
|
|
71
|
+
updatedAt: cmd.updatedAt,
|
|
72
|
+
updatedBy: 'user2',
|
|
73
|
+
updatedIp: '127.0.0.2',
|
|
74
|
+
},
|
|
75
|
+
create: {
|
|
76
|
+
id: 'survey-id-123',
|
|
77
|
+
cpk: 'SURVEY#test-tenant',
|
|
78
|
+
csk: 'TEMPLATE#01HTEST@1',
|
|
79
|
+
pk: 'SURVEY#test-tenant',
|
|
80
|
+
sk: 'TEMPLATE#01HTEST',
|
|
81
|
+
code: 'TEMPLATE#01HTEST',
|
|
82
|
+
name: 'Test Survey',
|
|
83
|
+
version: 1,
|
|
84
|
+
tenantCode: 'test-tenant',
|
|
85
|
+
seq: 1,
|
|
86
|
+
description: 'Test description',
|
|
87
|
+
surveyTemplate: { questions: [] },
|
|
88
|
+
additionalProperties: { key: 'value' },
|
|
89
|
+
createdAt: cmd.createdAt,
|
|
90
|
+
createdBy: 'user1',
|
|
91
|
+
createdIp: '127.0.0.1',
|
|
92
|
+
updatedAt: cmd.updatedAt,
|
|
93
|
+
updatedBy: 'user2',
|
|
94
|
+
updatedIp: '127.0.0.2',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
it('should skip non-TEMPLATE sk', async () => {
|
|
99
|
+
const cmd = {
|
|
100
|
+
id: 'survey-id-123',
|
|
101
|
+
pk: 'SURVEY#test-tenant',
|
|
102
|
+
sk: 'SURVEY_ANSWER#01HTEST',
|
|
103
|
+
code: 'SURVEY_ANSWER#01HTEST',
|
|
104
|
+
type: 'SURVEY_ANSWER',
|
|
105
|
+
name: 'Test Answer',
|
|
106
|
+
};
|
|
107
|
+
await handler.up(cmd);
|
|
108
|
+
expect(prismaService.surveyTemplate.upsert).not.toHaveBeenCalled();
|
|
109
|
+
});
|
|
110
|
+
it('should handle empty additionalProperties', async () => {
|
|
111
|
+
const cmd = {
|
|
112
|
+
id: 'survey-id-456',
|
|
113
|
+
pk: 'SURVEY#test-tenant',
|
|
114
|
+
sk: 'TEMPLATE#01HTEST2@1',
|
|
115
|
+
code: 'TEMPLATE#01HTEST2',
|
|
116
|
+
type: 'TEMPLATE',
|
|
117
|
+
name: 'Survey without props',
|
|
118
|
+
version: 1,
|
|
119
|
+
seq: 1,
|
|
120
|
+
tenantCode: 'test-tenant',
|
|
121
|
+
attributes: {
|
|
122
|
+
description: 'Description',
|
|
123
|
+
surveyTemplate: {},
|
|
124
|
+
},
|
|
125
|
+
isDeleted: false,
|
|
126
|
+
createdAt: new Date(),
|
|
127
|
+
updatedAt: new Date(),
|
|
128
|
+
};
|
|
129
|
+
mockPrismaService.surveyTemplate.upsert.mockResolvedValue({});
|
|
130
|
+
await handler.up(cmd);
|
|
131
|
+
expect(prismaService.surveyTemplate.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
132
|
+
update: expect.objectContaining({
|
|
133
|
+
additionalProperties: {},
|
|
134
|
+
}),
|
|
135
|
+
create: expect.objectContaining({
|
|
136
|
+
additionalProperties: {},
|
|
137
|
+
}),
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
it('should handle deleted items', async () => {
|
|
141
|
+
const cmd = {
|
|
142
|
+
id: 'survey-id-789',
|
|
143
|
+
pk: 'SURVEY#test-tenant',
|
|
144
|
+
sk: 'TEMPLATE#01HTEST3@2',
|
|
145
|
+
code: 'TEMPLATE#01HTEST3',
|
|
146
|
+
type: 'TEMPLATE',
|
|
147
|
+
name: 'Deleted Survey',
|
|
148
|
+
version: 2,
|
|
149
|
+
seq: 2,
|
|
150
|
+
tenantCode: 'test-tenant',
|
|
151
|
+
attributes: {},
|
|
152
|
+
isDeleted: true,
|
|
153
|
+
createdAt: new Date(),
|
|
154
|
+
updatedAt: new Date(),
|
|
155
|
+
};
|
|
156
|
+
mockPrismaService.surveyTemplate.upsert.mockResolvedValue({});
|
|
157
|
+
await handler.up(cmd);
|
|
158
|
+
expect(prismaService.surveyTemplate.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
159
|
+
update: expect.objectContaining({
|
|
160
|
+
isDeleted: true,
|
|
161
|
+
}),
|
|
162
|
+
}));
|
|
163
|
+
});
|
|
164
|
+
it('should remove version from sk for storage', async () => {
|
|
165
|
+
const cmd = {
|
|
166
|
+
id: 'survey-id-abc',
|
|
167
|
+
pk: 'SURVEY#test-tenant',
|
|
168
|
+
sk: 'TEMPLATE#01HABC123@5',
|
|
169
|
+
code: 'TEMPLATE#01HABC123',
|
|
170
|
+
type: 'TEMPLATE',
|
|
171
|
+
name: 'Versioned Survey',
|
|
172
|
+
version: 5,
|
|
173
|
+
seq: 5,
|
|
174
|
+
tenantCode: 'test-tenant',
|
|
175
|
+
attributes: {},
|
|
176
|
+
createdAt: new Date(),
|
|
177
|
+
updatedAt: new Date(),
|
|
178
|
+
};
|
|
179
|
+
mockPrismaService.surveyTemplate.upsert.mockResolvedValue({});
|
|
180
|
+
await handler.up(cmd);
|
|
181
|
+
expect(prismaService.surveyTemplate.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
182
|
+
create: expect.objectContaining({
|
|
183
|
+
sk: 'TEMPLATE#01HABC123',
|
|
184
|
+
code: 'TEMPLATE#01HABC123',
|
|
185
|
+
}),
|
|
186
|
+
}));
|
|
187
|
+
});
|
|
188
|
+
it('should handle undefined isDeleted as false', async () => {
|
|
189
|
+
const cmd = {
|
|
190
|
+
id: 'survey-id-def',
|
|
191
|
+
pk: 'SURVEY#test-tenant',
|
|
192
|
+
sk: 'TEMPLATE#01HDEF@1',
|
|
193
|
+
code: 'TEMPLATE#01HDEF',
|
|
194
|
+
type: 'TEMPLATE',
|
|
195
|
+
name: 'Survey without isDeleted',
|
|
196
|
+
version: 1,
|
|
197
|
+
seq: 1,
|
|
198
|
+
tenantCode: 'test-tenant',
|
|
199
|
+
attributes: {},
|
|
200
|
+
isDeleted: undefined,
|
|
201
|
+
createdAt: new Date(),
|
|
202
|
+
updatedAt: new Date(),
|
|
203
|
+
};
|
|
204
|
+
mockPrismaService.surveyTemplate.upsert.mockResolvedValue({});
|
|
205
|
+
await handler.up(cmd);
|
|
206
|
+
expect(prismaService.surveyTemplate.upsert).toHaveBeenCalledWith(expect.objectContaining({
|
|
207
|
+
update: expect.objectContaining({
|
|
208
|
+
isDeleted: false,
|
|
209
|
+
}),
|
|
210
|
+
}));
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe('down', () => {
|
|
214
|
+
it('should be defined and handle down operation', async () => {
|
|
215
|
+
const cmd = {
|
|
216
|
+
id: 'survey-id-123',
|
|
217
|
+
pk: 'SURVEY#test-tenant',
|
|
218
|
+
sk: 'TEMPLATE#01HTEST',
|
|
219
|
+
code: 'TEMPLATE#01HTEST',
|
|
220
|
+
type: 'TEMPLATE',
|
|
221
|
+
};
|
|
222
|
+
// down() currently just logs, so we just verify it doesn't throw
|
|
223
|
+
await expect(handler.down(cmd)).resolves.not.toThrow();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
//# sourceMappingURL=survey-template-rds.handler.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"survey-template-rds.handler.spec.js","sourceRoot":"","sources":["../../src/handler/survey-template-rds.handler.spec.ts"],"names":[],"mappings":";;AAAA,6CAAqD;AAGrD,+EAAgF;AAChF,4FAAqE;AAErE,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,OAAyC,CAAA;IAC7C,IAAI,aAAkB,CAAA;IAEtB,MAAM,iBAAiB,GAAG;QACxB,cAAc,EAAE;YACd,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;SAClB;KACF,CAAA;IA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AAC,CAAA;YAErB,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAC9D,MAAM,CAAC,gBAAgB,CAAC;gBACtB,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC;oBAC9B,SAAS,EAAE,KAAK;iBACjB,CAAC;aACH,CAAC,CACH,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,GAAG,GAAG;gBACV,EAAE,EAAE,eAAe;gBACnB,EAAE,EAAE,oBAAoB;gBACxB,EAAE,EAAE,kBAAkB;gBACtB,IAAI,EAAE,kBAAkB;gBACxB,IAAI,EAAE,UAAU;aACU,CAAA;YAE5B,iEAAiE;YACjE,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;QACxD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const survey_answer_controller_1 = require("./survey-answer.controller");
|
|
5
|
+
const survey_answer_service_1 = require("./survey-answer.service");
|
|
6
|
+
const survey_answer_data_entity_1 = require("./entity/survey-answer-data.entity");
|
|
7
|
+
describe('SurveyAnswerController', () => {
|
|
8
|
+
let controller;
|
|
9
|
+
let service;
|
|
10
|
+
const mockInvokeContext = {
|
|
11
|
+
event: {
|
|
12
|
+
requestContext: {
|
|
13
|
+
authorizer: {
|
|
14
|
+
jwt: {
|
|
15
|
+
claims: {
|
|
16
|
+
'custom:tenant': 'test-tenant',
|
|
17
|
+
'cognito:username': 'test-user',
|
|
18
|
+
name: 'Test User',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const mockService = {
|
|
26
|
+
create: jest.fn(),
|
|
27
|
+
};
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
const module = await testing_1.Test.createTestingModule({
|
|
30
|
+
controllers: [survey_answer_controller_1.SurveyAnswerController],
|
|
31
|
+
providers: [
|
|
32
|
+
{
|
|
33
|
+
provide: survey_answer_service_1.SurveyAnswerService,
|
|
34
|
+
useValue: mockService,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}).compile();
|
|
38
|
+
controller = module.get(survey_answer_controller_1.SurveyAnswerController);
|
|
39
|
+
service = module.get(survey_answer_service_1.SurveyAnswerService);
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
jest.clearAllMocks();
|
|
43
|
+
});
|
|
44
|
+
it('should be defined', () => {
|
|
45
|
+
expect(controller).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
describe('create', () => {
|
|
48
|
+
it('should create survey answer successfully', async () => {
|
|
49
|
+
const createDto = {
|
|
50
|
+
attributes: {
|
|
51
|
+
surveyId: 'survey123',
|
|
52
|
+
answer: { q1: 'answer1', q2: 'answer2' },
|
|
53
|
+
email: 'test@example.com',
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const mockResult = new survey_answer_data_entity_1.SurveyAnswerDataEntity({
|
|
57
|
+
pk: 'SURVEY#test-tenant',
|
|
58
|
+
sk: 'SURVEY_ANSWER#survey123#01HTEST',
|
|
59
|
+
name: '',
|
|
60
|
+
version: 1,
|
|
61
|
+
attributes: createDto.attributes,
|
|
62
|
+
});
|
|
63
|
+
mockService.create.mockResolvedValue(mockResult);
|
|
64
|
+
const result = await controller.create(mockInvokeContext, createDto);
|
|
65
|
+
expect(service.create).toHaveBeenCalledWith(createDto, {
|
|
66
|
+
invokeContext: mockInvokeContext,
|
|
67
|
+
});
|
|
68
|
+
expect(result).toEqual(mockResult);
|
|
69
|
+
});
|
|
70
|
+
it('should handle creation errors', async () => {
|
|
71
|
+
const createDto = {
|
|
72
|
+
attributes: {
|
|
73
|
+
surveyId: 'survey456',
|
|
74
|
+
answer: {},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const error = new Error('Creation failed');
|
|
78
|
+
mockService.create.mockRejectedValue(error);
|
|
79
|
+
await expect(controller.create(mockInvokeContext, createDto)).rejects.toThrow('Creation failed');
|
|
80
|
+
});
|
|
81
|
+
it('should pass all attributes to service', async () => {
|
|
82
|
+
const createDto = {
|
|
83
|
+
attributes: {
|
|
84
|
+
surveyId: 'survey789',
|
|
85
|
+
answer: { q1: 'a1', q2: 'a2', q3: 'a3' },
|
|
86
|
+
email: 'user@domain.com',
|
|
87
|
+
customField: 'custom value',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const mockResult = new survey_answer_data_entity_1.SurveyAnswerDataEntity({
|
|
91
|
+
pk: 'SURVEY#test-tenant',
|
|
92
|
+
sk: 'SURVEY_ANSWER#survey789#01HTEST',
|
|
93
|
+
attributes: createDto.attributes,
|
|
94
|
+
});
|
|
95
|
+
mockService.create.mockResolvedValue(mockResult);
|
|
96
|
+
await controller.create(mockInvokeContext, createDto);
|
|
97
|
+
expect(service.create).toHaveBeenCalledWith(createDto, {
|
|
98
|
+
invokeContext: mockInvokeContext,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('should return SurveyAnswerDataEntity', async () => {
|
|
102
|
+
const createDto = {
|
|
103
|
+
attributes: {
|
|
104
|
+
surveyId: 'survey-abc',
|
|
105
|
+
answer: {},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const mockResult = new survey_answer_data_entity_1.SurveyAnswerDataEntity({
|
|
109
|
+
pk: 'SURVEY#test-tenant',
|
|
110
|
+
sk: 'SURVEY_ANSWER#survey-abc#01HTEST',
|
|
111
|
+
id: 'test-id',
|
|
112
|
+
version: 1,
|
|
113
|
+
});
|
|
114
|
+
mockService.create.mockResolvedValue(mockResult);
|
|
115
|
+
const result = await controller.create(mockInvokeContext, createDto);
|
|
116
|
+
expect(result).toBeInstanceOf(survey_answer_data_entity_1.SurveyAnswerDataEntity);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=survey-answer.controller.spec.js.map
|