Skip to content

Commit 3d04c68

Browse files
authored
Merge pull request #881 from govuk-one-login/bau-strkyer-config
BAU: Stryker config
2 parents cbd68fa + 0a37907 commit 3d04c68

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

src/services/test/send-sqs-message.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ describe('sendSqsMessage', () => {
4242

4343
expect(SQSClient).toHaveBeenCalledWith({ region: 'eu-west-2' });
4444
expect(sendFn).toHaveBeenCalledWith(expect.any(SendMessageCommand));
45+
expect(sendFn).toHaveBeenCalledWith(
46+
expect.objectContaining({
47+
input: { QueueUrl: queueUrl, MessageBody: messageBody },
48+
}),
49+
);
4550
});
4651

4752
it('throws an error if sending the message fails', async () => {
@@ -80,6 +85,11 @@ describe('sendBatchSqsMessage', () => {
8085

8186
expect(SQSClient).toHaveBeenCalledWith({ region: 'eu-west-2' });
8287
expect(sendFn).toHaveBeenCalledWith(expect.any(SendMessageBatchCommand));
88+
expect(sendFn).toHaveBeenCalledWith(
89+
expect.objectContaining({
90+
input: { QueueUrl: queueUrl, Entries: entries },
91+
}),
92+
);
8393
});
8494

8595
it('throws an error if sending the message fails', async () => {

src/services/test/validate-event.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
validateEventIsNotStale,
66
validateInterventionEvent,
77
validateIfIdentityAcquired,
8+
attemptToParseJson,
89
} from '../validate-event';
910
import logger from '../../commons/logger';
1011
import { addMetric } from '../../commons/metrics';
@@ -203,6 +204,46 @@ describe('event-validation', () => {
203204
});
204205
});
205206

207+
it('should throw an error if event is stale', async () => {
208+
const staleEvent = {
209+
timestamp: timestamp.seconds - 5000,
210+
event_timestamp_ms: timestamp.milliseconds - 5000,
211+
event_name: TriggerEventsEnum.TICF_ACCOUNT_INTERVENTION,
212+
event_id: '123',
213+
component_id: 'TICF_CRI',
214+
user: { user_id: 'urn:fdc:gov.uk:2022:USER_ONE' },
215+
extensions: {
216+
intervention: {
217+
intervention_code: '01' as InterventionCodeEnum1,
218+
intervention_reason: 'something',
219+
originating_component_id: 'CMS',
220+
originator_reference_id: '1234567',
221+
requester_id: '1234567',
222+
},
223+
},
224+
};
225+
226+
await expect(async () => {
227+
await validateEventIsNotStale(
228+
EventsEnum.FRAUD_SUSPEND_ACCOUNT,
229+
staleEvent,
230+
{
231+
blocked: false,
232+
suspended: false,
233+
resetPassword: false,
234+
reproveIdentity: false,
235+
},
236+
dynamoDBResult,
237+
);
238+
}).rejects.toThrow(new ValidationError('Event received predates last applied event for this user.'));
239+
expect(addMetric).toHaveBeenCalledWith(MetricNames.INTERVENTION_EVENT_STALE);
240+
expect(sendAuditEvent).toHaveBeenCalledWith('AIS_EVENT_IGNORED_STALE', 'FRAUD_SUSPEND_ACCOUNT', staleEvent, {
241+
stateResult: { blocked: false, reproveIdentity: false, resetPassword: false, suspended: false },
242+
interventionName: 'AIS_NO_INTERVENTION',
243+
nextAllowableInterventions: ['01', '03', '04', '05', '06'],
244+
});
245+
});
246+
206247
it('should not throw if event is not stale', async () => {
207248
const nonStaleEvent = {
208249
timestamp: timestamp.seconds,
@@ -361,3 +402,16 @@ describe('event-validation', () => {
361402
expect(addMetric).toHaveBeenCalledWith(MetricNames.IDENTITY_NOT_SUFFICIENTLY_PROVED);
362403
});
363404
});
405+
406+
describe('attemptToParseJson', () => {
407+
it('should parse valid JSON', () => {
408+
const jsonString = '{"key": "value"}';
409+
const result = attemptToParseJson(jsonString);
410+
expect(result).toEqual({ key: 'value' });
411+
});
412+
413+
it('should return null for invalid JSON', () => {
414+
const jsonString = '{"key": "value"';
415+
expect(() => attemptToParseJson(jsonString)).toThrow('record body could not be parsed to valid JSON.');
416+
});
417+
});

stryker.config.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
],
1010
"testRunner": "vitest",
1111
"testRunner_comment": "Take a look at https://stryker-mutator.io/docs/stryker-js/vitest-runner for information about the vitest plugin.",
12-
"coverageAnalysis": "perTest"
13-
}
12+
"coverageAnalysis": "perTest",
13+
"ignorePatterns": [
14+
"**/contract-testing/**"
15+
]
16+
}

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
reporter: ['text', 'lcov'],
1010
reportsDirectory: './coverage',
1111
},
12-
exclude: ['**/node_modules/**', 'src/contract-testing/**'],
12+
exclude: ['**/node_modules/**', 'src/contract-testing/**', '.stryker-tmp/**'],
1313
env: {
1414
CLOUDWATCH_METRICS_NAMESPACE: 'test_namespace',
1515
METRIC_SERVICE_NAME: 'test',

0 commit comments

Comments
 (0)