kundencenter/packages/connector-mock/test/contract.test.ts

17 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import { describe, expect, it } from 'vitest';
import { runContract } from '@kc/connector-sdk/dist/contract.js';
import { mockConnector, resetMock } from '../src/index.js';
const ctx = (c: Record<string, unknown> = {}) => ({ config: { instance: 't', ...c }, secrets: {}, correlationId: 'c' });
describe('Mock-Connector', () => {
it('erfüllt den Vertrag', async () => { resetMock(); expect((await runContract(expect as never, mockConnector, ctx())).length).toBe(3); });
it('sperrt und entsperrt', async () => {
resetMock();
expect((await mockConnector.execute!(ctx(), { action: 'suspend', externalRef: 'm-1', idempotencyKey: 'a' })).resource?.state).toBe('suspended');
expect((await mockConnector.execute!(ctx(), { action: 'unsuspend', externalRef: 'm-1', idempotencyKey: 'b' })).resource?.state).toBe('active');
});
it('simuliert Ausfall', async () => {
expect((await mockConnector.healthCheck(ctx({ simulateOutage: 'true' }))).ok).toBe(false);
await expect(mockConnector.listResources(ctx({ simulateOutage: 'true' }))).rejects.toMatchObject({ code: 'UNREACHABLE', retryable: true });
});
});