Skip to content

Commit

Permalink
feat: allow any case for user tags filter (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh authored Nov 27, 2023
1 parent 598f921 commit de52c31
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/probe/sockets-location-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SocketsLocationFilter {
}

static hasTag (socket: RemoteProbeSocket, tag: string) {
return socket.data.probe.tags.some(({ value }) => value === tag);
return socket.data.probe.tags.some(({ value }) => value.toLowerCase() === tag);
}

public filterGloballyDistibuted (sockets: RemoteProbeSocket[], limit: number): RemoteProbeSocket[] {
Expand Down
18 changes: 17 additions & 1 deletion test/tests/integration/measurement/create-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('Create measurement', () => {
ip: '1.2.3.4',
uuid: '1-1-1-1-1',
isCustomCity: 1,
tags: '["dashboard-tag"]',
tags: '["Dashboard-Tag"]',
status: 'ready',
version: '0.26.0',
country: 'US',
Expand Down Expand Up @@ -429,6 +429,22 @@ describe('Create measurement', () => {
});
});

it('should create measurement with adopted "tags: ["u-jimaek-Dashboard-Tag"]" in any letter case', async () => {
await requestAgent.post('/v1/measurements')
.send({
type: 'ping',
target: 'example.com',
locations: [{ tags: [ 'u-jimaek-Dashboard-Tag' ], limit: 2 }],
})
.expect(202)
.expect((response) => {
expect(response.body.id).to.exist;
expect(response.header.location).to.exist;
expect(response.body.probesCount).to.equal(1);
expect(response).to.matchApiSchema();
});
});

it('should not use create measurement with adopted tag in magic field "magic: ["u-jimaek-dashboard-tag"]" location', async () => {
await requestAgent.post('/v1/measurements')
.send({
Expand Down
14 changes: 14 additions & 0 deletions test/tests/unit/measurement/schema/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ describe('command schema', async () => {
expect(valid.value![0].region).to.equal('Northern America');
});

it('should correct tag value (lowercase)', () => {
const input = [
{
tags: [ 'DifferentCase-tag' ],
limit: 1,
},
];

const valid = locationSchema.validate(input);

expect(valid.value![0].tags).to.not.equal(input[0]!.tags);
expect(valid.value![0].tags).to.deep.equal([ 'differentcase-tag' ]);
});

it('should fail (wrong region)', () => {
const input = [
{
Expand Down
4 changes: 2 additions & 2 deletions test/tests/unit/probe/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,13 @@ describe('probe router', () => {
const socket = await buildSocket(String(Date.now()), location);
socket.data.probe.tags = [
...socket.data.probe.tags,
{ type: 'user', value: 'u-jimaek-dashboardtag' },
{ type: 'user', value: 'u-MartinKolarik-DashboardTag' },
];

const sockets: DeepPartial<RemoteProbeSocket[]> = [ socket ];

const locations: Location[] = [
{ tags: [ 'u-jimaek-dashboardtag' ] },
{ tags: [ 'u-martinkolarik-dashboardtag' ] },
];

fetchSocketsMock.resolves(sockets as never);
Expand Down

0 comments on commit de52c31

Please sign in to comment.