Skip to content

Commit 9c48123

Browse files
feat: allow any case for user tags filter
1 parent 598f921 commit 9c48123

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/probe/sockets-location-filter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class SocketsLocationFilter {
5151
}
5252

5353
static hasTag (socket: RemoteProbeSocket, tag: string) {
54-
return socket.data.probe.tags.some(({ value }) => value === tag);
54+
return socket.data.probe.tags.some(({ value }) => value.toLowerCase() === tag);
5555
}
5656

5757
public filterGloballyDistibuted (sockets: RemoteProbeSocket[], limit: number): RemoteProbeSocket[] {

test/tests/integration/measurement/create-measurement.test.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('Create measurement', () => {
378378
ip: '1.2.3.4',
379379
uuid: '1-1-1-1-1',
380380
isCustomCity: 1,
381-
tags: '["dashboard-tag"]',
381+
tags: '["Dashboard-Tag"]',
382382
status: 'ready',
383383
version: '0.26.0',
384384
country: 'US',
@@ -429,6 +429,22 @@ describe('Create measurement', () => {
429429
});
430430
});
431431

432+
it('should create measurement with adopted "tags: ["u-jimaek-Dashboard-Tag"]" in any letter case', async () => {
433+
await requestAgent.post('/v1/measurements')
434+
.send({
435+
type: 'ping',
436+
target: 'example.com',
437+
locations: [{ tags: [ 'u-jimaek-Dashboard-Tag' ], limit: 2 }],
438+
})
439+
.expect(202)
440+
.expect((response) => {
441+
expect(response.body.id).to.exist;
442+
expect(response.header.location).to.exist;
443+
expect(response.body.probesCount).to.equal(1);
444+
expect(response).to.matchApiSchema();
445+
});
446+
});
447+
432448
it('should not use create measurement with adopted tag in magic field "magic: ["u-jimaek-dashboard-tag"]" location', async () => {
433449
await requestAgent.post('/v1/measurements')
434450
.send({

test/tests/unit/measurement/schema/schema.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ describe('command schema', async () => {
245245
expect(valid.value![0].region).to.equal('Northern America');
246246
});
247247

248+
it('should correct tag value (lowercase)', () => {
249+
const input = [
250+
{
251+
tags: [ 'DifferentCase-tag' ],
252+
limit: 1,
253+
},
254+
];
255+
256+
const valid = locationSchema.validate(input);
257+
258+
expect(valid.value![0].tags).to.not.equal(input[0]!.tags);
259+
expect(valid.value![0].tags).to.deep.equal([ 'differentcase-tag' ]);
260+
});
261+
248262
it('should fail (wrong region)', () => {
249263
const input = [
250264
{

test/tests/unit/probe/router.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,13 @@ describe('probe router', () => {
822822
const socket = await buildSocket(String(Date.now()), location);
823823
socket.data.probe.tags = [
824824
...socket.data.probe.tags,
825-
{ type: 'user', value: 'u-jimaek-dashboardtag' },
825+
{ type: 'user', value: 'u-MartinKolarik-DashboardTag' },
826826
];
827827

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

830830
const locations: Location[] = [
831-
{ tags: [ 'u-jimaek-dashboardtag' ] },
831+
{ tags: [ 'u-martinkolarik-dashboardtag' ] },
832832
];
833833

834834
fetchSocketsMock.resolves(sockets as never);

0 commit comments

Comments
 (0)