Skip to content

Commit

Permalink
fix: default adopted values overriding admin location
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Apr 11, 2024
1 parent ba1b917 commit 7aa27c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/lib/admin-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class AdminData {
}

async syncDashboardData () {
console.log('syncDashboardData');
const overrides = await this.sql(LOCATION_OVERRIDES_TABLE).select<LocationOverride[]>();

this.rangesToUpdatedFields = new Map(overrides.map(override => [ ipaddr.parseCIDR(override.ip_range), {
Expand Down Expand Up @@ -96,11 +95,11 @@ export class AdminData {
});
}

getUpdatedLocation (probe: Probe): ProbeLocation {
getUpdatedLocation (probe: Probe): ProbeLocation | null {
const updatedFields = this.getUpdatedFields(probe);

if (!updatedFields) {
return probe.location;
return null;
}

return {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/adopted-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export class AdoptedProbes {
return this.adoptedIpToProbe.get(ip);
}

getUpdatedLocation (probe: Probe): ProbeLocation {
getUpdatedLocation (probe: Probe): ProbeLocation | null {
const adoptedProbe = this.getByIp(probe.ipAddress);

if (!adoptedProbe || !adoptedProbe.isCustomCity || adoptedProbe.countryOfCustomCity !== probe.location.country) {
return probe.location;
return null;
}

return {
Expand Down Expand Up @@ -141,7 +141,7 @@ export class AdoptedProbes {
return probe;
}

const newLocation = this.getUpdatedLocation(probe);
const newLocation = this.getUpdatedLocation(probe) || probe.location;

const newTags = this.getUpdatedTags(probe);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/probe-override.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ProbeOverride {
getUpdatedLocation (probe: Probe) {
const adminLocation = this.adminData.getUpdatedLocation(probe);
const adoptedLocation = this.adoptedProbes.getUpdatedLocation(probe);
return { ...adminLocation, ...adoptedLocation };
return { ...probe.location, ...adminLocation, ...adoptedLocation };
}

addAdminData (probes: Probe[]) {
Expand Down
8 changes: 4 additions & 4 deletions test/tests/unit/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe('AdoptedProbes', () => {
});
});

it('getUpdatedLocation method should return same location object if connected.country !== adopted.countryOfCustomCity', async () => {
it('getUpdatedLocation method should return null if connected.country !== adopted.countryOfCustomCity', async () => {
const adoptedProbes = new AdoptedProbes(sqlStub as unknown as Knex, fetchSocketsStub);
selectStub.resolves([{
...defaultAdoptedProbe,
Expand All @@ -407,10 +407,10 @@ describe('AdoptedProbes', () => {

await adoptedProbes.syncDashboardData();
const updatedLocation = adoptedProbes.getUpdatedLocation(defaultConnectedProbe);
expect(updatedLocation).to.equal(defaultConnectedProbe.location);
expect(updatedLocation).to.equal(null);
});

it('getUpdatedLocation method should return same location object if "isCustomCity: false"', async () => {
it('getUpdatedLocation method should return null if "isCustomCity: false"', async () => {
const adoptedProbes = new AdoptedProbes(sqlStub as unknown as Knex, fetchSocketsStub);
selectStub.resolves([{
...defaultAdoptedProbe,
Expand All @@ -422,7 +422,7 @@ describe('AdoptedProbes', () => {

await adoptedProbes.syncDashboardData();
const updatedLocation = adoptedProbes.getUpdatedLocation(defaultConnectedProbe);
expect(updatedLocation).to.equal(defaultConnectedProbe.location);
expect(updatedLocation).to.equal(null);
});

it('getUpdatedTags method should return updated tags', async () => {
Expand Down

0 comments on commit 7aa27c0

Please sign in to comment.