1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-27 13:49:10 +02:00

feat: more tests

This commit is contained in:
Thomas Heartman 2023-11-20 11:44:28 +01:00
parent 706019cd9e
commit a549f9a017
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78
2 changed files with 76 additions and 38 deletions

View File

@ -134,42 +134,78 @@ describe.each([
); );
}); });
describe.each([ describe('addStrategy events should show up in used strategies correctly', () => {
[ test.each([
'updateStrategy', ['Draft', true],
(segmentId: number) => ['In Review', true],
updateStrategyInCr(randomId(), segmentId, FLAG_NAME), ['Scheduled', true],
], ['Approved', true],
[ ['Rejected', false],
'addStrategy', ['Cancelled', false],
(segmentId: number) => addStrategyToCr(segmentId, FLAG_NAME), ['Applied', false],
], ])(
])( 'addStrategy events in %s CRs should show up',
'%s events should show up in used strategies correctly', async (state, shouldShow) => {
(_, addOrUpdateStrategy) => { await createCR(state);
test.each([
['Draft', true],
['In Review', true],
['Scheduled', true],
['Approved', true],
['Rejected', false],
['Cancelled', false],
['Applied', false],
])(
'Changes in %s CRs should make it %s',
async (state, expectedOutcome) => {
await createCR(state);
const segmentId = 3; const segmentId = 3;
await addOrUpdateStrategy(segmentId);
expect(readModel).get; await addStrategyToCr(segmentId, FLAG_NAME);
expect(
await readModel.isSegmentUsedInActiveChangeRequests( const result = await readModel.isSegmentUsedInActiveChangeRequests(
segmentId, segmentId,
), );
).toBe(expectedOutcome); if (shouldShow) {
}, expect(result).toBe({
); projectId: 'default',
}, strategyName: 'flexibleRollout',
); environment: 'default',
featureName: FLAG_NAME,
});
} else {
expect(result).toBe([]);
}
},
);
});
describe('updateStrategy events should show up in used strategies correctly', () => {
test.each([
['Draft', true],
['In Review', true],
['Scheduled', true],
['Approved', true],
['Rejected', false],
['Cancelled', false],
['Applied', false],
])(
'updateStrategy events in %s CRs should show up',
async (state, shouldShow) => {
await createCR(state);
const segmentId = 3;
const strategyId = randomId();
await updateStrategyInCr(strategyId, segmentId, FLAG_NAME);
const result =
await readModel.getStrategiesUsedInActiveChangeRequests(
segmentId,
);
if (shouldShow) {
expect(result).toMatchObject([
{
id: strategyId,
projectId: 'default',
strategyName: 'flexibleRollout',
environment: 'default',
featureName: FLAG_NAME,
},
]);
} else {
expect(result).toBe([]);
}
},
);
});

View File

@ -11,5 +11,7 @@ type ChangeRequestStrategy = NewStrategy | ExistingStrategy;
export interface IChangeRequestSegmentUsageReadModel { export interface IChangeRequestSegmentUsageReadModel {
isSegmentUsedInActiveChangeRequests(segmentId: number): Promise<boolean>; isSegmentUsedInActiveChangeRequests(segmentId: number): Promise<boolean>;
getSegmentsUsedInActiveChangeRequests(): Promise<ChangeRequestStrategy[]>; getStrategiesUsedInActiveChangeRequests(
segmentId: number,
): Promise<ChangeRequestStrategy[]>;
} }