fix permissions and teacher attendance workflows

This commit is contained in:
2026-07-10 20:40:52 +08:00
parent 247879f276
commit 8ed1682b90
95 changed files with 4745 additions and 1237 deletions

View File

@@ -0,0 +1,59 @@
import { DingTalkService } from '../integration/dingtalk.service';
describe('DingTalkService — attendance records', () => {
const originalAppKey = process.env.DINGTALK_APP_KEY;
const originalAppSecret = process.env.DINGTALK_APP_SECRET;
let service: DingTalkService;
beforeEach(() => {
process.env.DINGTALK_APP_KEY = 'test-app-key';
process.env.DINGTALK_APP_SECRET = 'test-app-secret';
service = new DingTalkService({} as never, {} as never);
Object.assign(service, {
accessToken: 'test-token',
tokenExpiresAt: Date.now() + 3_600_000,
});
});
afterEach(() => {
jest.restoreAllMocks();
global.fetch = undefined as unknown as typeof fetch;
});
afterAll(() => {
if (originalAppKey === undefined) delete process.env.DINGTALK_APP_KEY;
else process.env.DINGTALK_APP_KEY = originalAppKey;
if (originalAppSecret === undefined) delete process.env.DINGTALK_APP_SECRET;
else process.env.DINGTALK_APP_SECRET = originalAppSecret;
});
it('sends the required userIds and does not send unsupported offset/limit fields', async () => {
global.fetch = jest.fn().mockResolvedValue({
json: jest.fn().mockResolvedValue({ errcode: 0, errmsg: 'ok', recordresult: [] }),
}) as jest.MockedFunction<typeof fetch>;
await service.fetchAttendanceResults({
startDate: '2026-07-01',
endDate: '2026-07-07',
userIds: ['ding-1', 'ding-2'],
});
expect(JSON.parse((global.fetch as jest.Mock).mock.calls[0][1].body)).toEqual({
checkDateFrom: '2026-07-01 00:00:00',
checkDateTo: '2026-07-07 23:59:59',
userIds: ['ding-1', 'ding-2'],
});
});
it('rejects missing userIds before calling DingTalk', async () => {
await expect(
service.fetchAttendanceResults({
startDate: '2026-07-01',
endDate: '2026-07-01',
}),
).rejects.toThrow('userIds');
expect(global.fetch).toBeUndefined();
});
});