41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it } from 'vitest';
|
|
import { useIntegrationConfigStore } from './integrationConfigStore';
|
|
|
|
const { getState } = useIntegrationConfigStore;
|
|
|
|
const readCache = () => {
|
|
const { loaded, config, verified, formValues, dirty } = getState();
|
|
return { loaded, config, verified, formValues, dirty };
|
|
};
|
|
|
|
describe('DingTalk integration config page cache', () => {
|
|
beforeEach(() => getState().reset());
|
|
|
|
it('keeps an unsaved secret when a background refresh returns', () => {
|
|
getState().cacheDraft({ corpId: 'draft-corp', agentId: 'draft-key', appSecret: 'draft-secret' });
|
|
getState().cacheServerSnapshot({ corpId: 'saved-corp', agentId: 'saved-key' }, true);
|
|
|
|
expect(readCache()).toMatchObject({
|
|
loaded: true,
|
|
dirty: true,
|
|
config: { corpId: 'saved-corp', agentId: 'saved-key' },
|
|
formValues: {
|
|
corpId: 'draft-corp',
|
|
agentId: 'draft-key',
|
|
appSecret: 'draft-secret',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('clears the secret after a successful save', () => {
|
|
getState().cacheDraft({ corpId: 'corp', agentId: 'key', appSecret: 'secret' });
|
|
getState().commitConfig({ corpId: 'corp', agentId: 'key' });
|
|
|
|
expect(readCache()).toMatchObject({
|
|
loaded: true,
|
|
dirty: false,
|
|
formValues: { corpId: 'corp', agentId: 'key', appSecret: undefined },
|
|
});
|
|
});
|
|
});
|