Skip to content

Commit

Permalink
fix: 更新单测
Browse files Browse the repository at this point in the history
  • Loading branch information
skique committed Dec 31, 2024
1 parent 5019523 commit 35b174c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions server/src/modules/survey/__test/survey.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ describe('SurveyController', () => {
const reqBody = {
surveyId: surveyId.toString(),
configData: {
dataConf: {
dataList: [{ question: 'Test Question' }],
},
/* ... your config data here ... */
},
sessionId: 'mock-session-id',
Expand All @@ -159,6 +162,28 @@ describe('SurveyController', () => {
controller.updateConf(reqBody, { user: {} }),
).rejects.toThrow(HttpException);
});
it('should throw an error when missing question data', async () => {
const surveyId = new ObjectId();
const reqBody = {
surveyId: surveyId.toString(),
configData: {
dataConf: {
dataList: [], // Empty dataList
},
},
sessionId: 'mock-session-id',
};

try {
await controller.updateConf(reqBody, {
user: { username: 'testUser', _id: 'testUserId' },
surveyMeta: { _id: surveyId },
});
} catch (error) {
expect(error).toBeInstanceOf(HttpException);
expect(error.message).toBe('请添加题目后重新保存问卷');
}
});
});

describe('deleteSurvey', () => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/survey/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class SurveyController {
this.logger.error(error.message);
throw new HttpException('参数有误', EXCEPTION_CODE.PARAMETER_ERROR);
}
if(!surveyInfo.configData.dataConf.dataList.length){
if(!surveyInfo?.configData?.dataConf?.dataList?.length){
this.logger.error('确少题目数据');
throw new HttpException('请添加题目后重新保存问卷', EXCEPTION_CODE.PARAMETER_ERROR);
}
Expand Down

0 comments on commit 35b174c

Please sign in to comment.