Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 缺陷修复回流 #466

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: 更新单测
  • Loading branch information
skique committed Dec 31, 2024
commit 35b174c611914cce2d7c57ff6cd86082ba79623f
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
Loading