fix(integration): simplify manual DingTalk sync setup

This commit is contained in:
2026-07-13 14:01:45 +08:00
parent effa34434b
commit 0515e6ed27
6 changed files with 203 additions and 88 deletions

View File

@@ -0,0 +1,49 @@
import { IntegrationConfigService } from './integration-config.service';
describe('IntegrationConfigService.testConnection', () => {
const originalFetch = global.fetch;
afterEach(() => {
global.fetch = originalFetch;
jest.restoreAllMocks();
});
it('uses the saved AppSecret when testing an existing configuration with a blank secret', async () => {
const configRepo = {
findOne: jest.fn().mockResolvedValue({ id: 1, type: 'THIRD' }),
};
const detailRepo = {
findOne: jest.fn().mockResolvedValue({
configId: 1,
type: 'DINGTALK_SYNC',
content: JSON.stringify({
config: {
corpId: 'ding-corp',
agentId: 'saved-key',
appSecret: 'saved-secret',
},
}),
}),
};
global.fetch = jest.fn().mockResolvedValue({
json: jest.fn().mockResolvedValue({ accessToken: 'token' }),
}) as never;
const service = new IntegrationConfigService(configRepo as never, detailRepo as never);
await expect(
service.testConnection('DINGTALK', {
corpId: 'ding-corp',
agentId: 'saved-key',
appSecret: '',
}),
).resolves.toBe(true);
expect(global.fetch).toHaveBeenCalledWith(
'https://api.dingtalk.com/v1.0/oauth2/accessToken',
expect.objectContaining({
body: JSON.stringify({ appKey: 'saved-key', appSecret: 'saved-secret' }),
}),
);
});
});