Skip to content

Commit

Permalink
test: api test for referenceId as number (#5915)
Browse files Browse the repository at this point in the history
* test: api test for correctly interpeting referenceId that could be interpreted as number AB#30721

* test: added separate tests for $ilike and $in
  • Loading branch information
jannisvisser authored Oct 11, 2024
1 parent 9e25cbe commit 1746de5
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,71 @@ describe('Load PA table', () => {
}
expect(meta.totalItems).toBe(1);
});

it('should filter with $eq using a referenceId string that could be interpreted as number', async () => {
// Arrange
const referenceIdInterpretableAsNumber = '651581942751358e5'; // A just-number string like '1234567890' is somehow not sufficiently covering the edge case, as this would not lead to the same bug prior to bugfix AB#30713
const newRegistration = structuredClone(registrationOCW1);
newRegistration.referenceId = referenceIdInterpretableAsNumber;
await importRegistrations(programIdOCW, [newRegistration], accessToken);

// Act
const getRegistrationsResponse = await getRegistrations({
programId: programIdOCW,
accessToken,
filter: {
'filter.referenceId': `$eq:${referenceIdInterpretableAsNumber}`,
},
});
const meta = getRegistrationsResponse.body.meta;

// Assert
expect(getRegistrationsResponse.status).toBe(200);
expect(meta.totalItems).toBe(1);
});

it('should filter with $ilike using a referenceId string that could be interpreted as number', async () => {
// Arrange
const referenceIdInterpretableAsNumber = '751581942751358e5';
const newRegistration = structuredClone(registrationOCW1);
newRegistration.referenceId = referenceIdInterpretableAsNumber;
await importRegistrations(programIdOCW, [newRegistration], accessToken);

// Act
const getRegistrationsResponse = await getRegistrations({
programId: programIdOCW,
accessToken,
filter: {
'filter.referenceId': `$ilike:${referenceIdInterpretableAsNumber}`,
},
});
const meta = getRegistrationsResponse.body.meta;

// Assert
expect(getRegistrationsResponse.status).toBe(200);
expect(meta.totalItems).toBe(1);
});

it('should filter with $in using a referenceId string that could be interpreted as number', async () => {
// Arrange
const referenceIdInterpretableAsNumber = '851581942751358e5';
const newRegistration = structuredClone(registrationOCW1);
newRegistration.referenceId = referenceIdInterpretableAsNumber;
await importRegistrations(programIdOCW, [newRegistration], accessToken);

// Act
const getRegistrationsResponse = await getRegistrations({
programId: programIdOCW,
accessToken,
filter: {
'filter.referenceId': `$in:${referenceIdInterpretableAsNumber}`,
},
});
const meta = getRegistrationsResponse.body.meta;

// Assert
expect(getRegistrationsResponse.status).toBe(200);
expect(meta.totalItems).toBe(1);
});
});
});

0 comments on commit 1746de5

Please sign in to comment.