-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,182 additions
and
664 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { SurveyMeta } from '../surveyMeta.entity'; | ||
import { RECORD_STATUS, RECORD_SUB_STATUS } from 'src/enums'; | ||
|
||
// 模拟日期 | ||
const mockDateNow = Date.now(); | ||
|
||
describe('SurveyMeta Entity', () => { | ||
let surveyMeta: SurveyMeta; | ||
|
||
// 在每个测试之前,初始化 SurveyMeta 实例 | ||
beforeEach(() => { | ||
surveyMeta = new SurveyMeta(); | ||
// 模拟 Date.now() 返回固定的时间 | ||
jest.spyOn(Date, 'now').mockReturnValue(mockDateNow); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); // 每次测试后还原所有 mock | ||
}); | ||
|
||
it('should set default curStatus and subStatus on insert when they are not provided', () => { | ||
surveyMeta.initDefaultInfo(); | ||
|
||
// 验证 curStatus 是否被初始化为默认值 | ||
expect(surveyMeta.curStatus).toEqual({ | ||
status: RECORD_STATUS.NEW, | ||
date: mockDateNow, | ||
}); | ||
|
||
// 验证 statusList 是否包含 curStatus | ||
expect(surveyMeta.statusList).toEqual([ | ||
{ | ||
status: RECORD_STATUS.NEW, | ||
date: mockDateNow, | ||
}, | ||
]); | ||
|
||
// 验证 subStatus 是否被初始化为默认值 | ||
expect(surveyMeta.subStatus).toEqual({ | ||
status: RECORD_SUB_STATUS.DEFAULT, | ||
date: mockDateNow, | ||
}); | ||
}); | ||
|
||
it('should initialize statusList if curStatus is provided but statusList is empty', () => { | ||
surveyMeta.curStatus = null; | ||
|
||
surveyMeta.initDefaultInfo(); | ||
|
||
expect(surveyMeta.statusList).toEqual([ | ||
{ | ||
status: RECORD_STATUS.NEW, | ||
date: expect.any(Number), | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.