test(23-05): add failing tests for getCompanyAutomationGate reader
- covers absent-row, present-row mapping, null/NaN companyId short-circuit
This commit is contained in:
parent
b69558aae8
commit
0d7974cdd9
1 changed files with 52 additions and 0 deletions
52
lib/services/phishing-automation-gate.test.ts
Normal file
52
lib/services/phishing-automation-gate.test.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
// Mock postgresClient BEFORE importing the module under test — mirrors
|
||||||
|
// campaign-classifier.test.ts's vi.mock() factory-mocking discipline.
|
||||||
|
const queryMock = vi.fn();
|
||||||
|
vi.mock('./postgres-client', () => ({
|
||||||
|
postgresClient: {
|
||||||
|
query: (...args: unknown[]) => queryMock(...args),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/first -- imported after vi.mock hoisting
|
||||||
|
import { getCompanyAutomationGate } from './phishing-automation-gate';
|
||||||
|
|
||||||
|
describe('getCompanyAutomationGate', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
queryMock.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves to all-false when no row exists for the company', async () => {
|
||||||
|
queryMock.mockResolvedValueOnce({ rows: [] });
|
||||||
|
|
||||||
|
const gate = await getCompanyAutomationGate(123);
|
||||||
|
|
||||||
|
expect(gate).toEqual({ autoParse: false, autoClassify: false, autoReport: false });
|
||||||
|
expect(queryMock).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves to the mapped camelCase values when a row exists', async () => {
|
||||||
|
queryMock.mockResolvedValueOnce({
|
||||||
|
rows: [{ auto_parse: true, auto_classify: false, auto_report: true }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const gate = await getCompanyAutomationGate(456);
|
||||||
|
|
||||||
|
expect(gate).toEqual({ autoParse: true, autoClassify: false, autoReport: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves to all-false without querying when companyId is null', async () => {
|
||||||
|
const gate = await getCompanyAutomationGate(null);
|
||||||
|
|
||||||
|
expect(gate).toEqual({ autoParse: false, autoClassify: false, autoReport: false });
|
||||||
|
expect(queryMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves to all-false without querying when companyId is NaN', async () => {
|
||||||
|
const gate = await getCompanyAutomationGate(NaN);
|
||||||
|
|
||||||
|
expect(gate).toEqual({ autoParse: false, autoClassify: false, autoReport: false });
|
||||||
|
expect(queryMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue