41 lines
1.9 KiB
JavaScript
41 lines
1.9 KiB
JavaScript
const AiSuggestionService = require('../src/services/aiSuggestionService');
|
|
|
|
const suggestionRow = {
|
|
id: 'suggestion-1', status: 'pending', input_hash: 'version-a',
|
|
operation_type: 'select_package', target_id: '4', proposed_payload: '{}'
|
|
};
|
|
|
|
describe('AiSuggestionService', () => {
|
|
test('requires selected suggestions and explicit confirmation', async () => {
|
|
const service = new AiSuggestionService({}, {});
|
|
await expect(service.decide('job', 7, { suggestionIds: ['suggestion-1'] }))
|
|
.rejects.toThrow('bekræft');
|
|
});
|
|
|
|
test('records a confirmed rejection without applying project changes', async () => {
|
|
const execute = jest.fn()
|
|
.mockResolvedValueOnce([[suggestionRow]])
|
|
.mockResolvedValueOnce([{ affectedRows: 1 }]);
|
|
const service = new AiSuggestionService({ pool: { execute } }, {});
|
|
const result = await service.decide('job', 7, {
|
|
suggestionIds: ['suggestion-1'], confirmed: true, reject: true,
|
|
expectedInputHash: 'version-a', actor: 'tester'
|
|
});
|
|
expect(result).toEqual({ applied: 0, rejected: 1 });
|
|
expect(execute).toHaveBeenLastCalledWith(expect.stringContaining("status = ?"), ['rejected', 'tester', 'suggestion-1']);
|
|
});
|
|
|
|
test('marks suggestions stale when the persisted project changed', async () => {
|
|
const execute = jest.fn()
|
|
.mockResolvedValueOnce([[suggestionRow]])
|
|
.mockResolvedValueOnce([{ affectedRows: 1 }]);
|
|
const projectAi = { buildSnapshot: jest.fn().mockResolvedValue({ stateHash: 'version-b' }) };
|
|
const service = new AiSuggestionService({ pool: { execute } }, projectAi);
|
|
await expect(service.decide('job', 7, {
|
|
suggestionIds: ['suggestion-1'], confirmed: true,
|
|
expectedInputHash: 'version-a', actor: 'tester'
|
|
})).rejects.toMatchObject({ status: 409 });
|
|
expect(execute).toHaveBeenLastCalledWith(expect.stringContaining("status = ?"), ['stale', 'tester', 'suggestion-1']);
|
|
});
|
|
});
|