Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Sep 25, 2024
1 parent aadb0bd commit aba2d64
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions migrations/create-tables.js.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS gp_adopted_probes (
lastSyncDate DATE NOT NULL,
isCustomCity TINYINT(1) DEFAULT 0,
tags LONGTEXT COLLATE utf8mb4_bin DEFAULT '[]' NOT NULL,
systemTags LONGTEXT COLLATE utf8mb4_bin DEFAULT '[]' NOT NULL,
status VARCHAR(255) NOT NULL,
isIPv4Supported BOOLEAN,
isIPv6Supported BOOLEAN,
Expand Down
1 change: 1 addition & 0 deletions test/tests/integration/adoption-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Adoption code', () => {
nodeVersion: 'v18.17.0',
hardwareDevice: null,
status: 'initializing',
systemTags: [ 'datacenter-network' ],
city: 'Dallas',
state: 'TX',
country: 'US',
Expand Down
45 changes: 35 additions & 10 deletions test/tests/unit/override/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ describe('AdoptedProbes', () => {
uuid: '1-1-1-1-1',
lastSyncDate: new Date(),
tags: '[{"prefix":"jimaek","value":"dashboardtag"}]',
systemTags: '["datacenter-network"]',
isCustomCity: 0,
status: 'ready',
isIPv4Supported: true,
isIPv6Supported: true,
isIPv4Supported: 1,
isIPv6Supported: 1,
version: '0.26.0',
nodeVersion: 'v18.17.0',
hardwareDevice: null,
Expand Down Expand Up @@ -55,7 +56,10 @@ describe('AdoptedProbes', () => {
},
isHardware: false,
hardwareDevice: null,
tags: [],
tags: [{
type: 'system',
value: 'datacenter-network',
}],
index: [],
client: '',
host: '',
Expand Down Expand Up @@ -234,6 +238,9 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.1',
isHardware: true,
hardwareDevice: 'v1',
tags: [
{ type: 'system', value: 'eyeball-network' },
],
location: {
continent: 'EU',
region: 'Northern Europe',
Expand Down Expand Up @@ -261,6 +268,7 @@ describe('AdoptedProbes', () => {
version: '0.27.0',
nodeVersion: 'v18.17.1',
hardwareDevice: 'v1',
systemTags: '["eyeball-network"]',
asn: 20473,
network: 'The Constant Company, LLC',
country: 'GB',
Expand All @@ -272,7 +280,7 @@ describe('AdoptedProbes', () => {

it('class should update country and send notification if country of the probe changes', async () => {
const adoptedProbes = new AdoptedProbes(sqlStub as unknown as Knex, fetchProbesWithAdminData);
selectStub.resolves([{ ...defaultAdoptedProbe, countryOfCustomCity: 'IE', isCustomCity: true }]);
selectStub.resolves([{ ...defaultAdoptedProbe, countryOfCustomCity: 'IE', isCustomCity: 1 }]);

fetchProbesWithAdminData.resolves([
{
Expand All @@ -286,6 +294,9 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
location: {
continent: 'EU',
region: 'Northern Europe',
Expand Down Expand Up @@ -329,7 +340,7 @@ describe('AdoptedProbes', () => {

it('class should partially update probe meta info if it is outdated and "isCustomCity: true"', async () => {
const adoptedProbes = new AdoptedProbes(sqlStub as unknown as Knex, fetchProbesWithAdminData);
selectStub.resolves([{ ...defaultAdoptedProbe, countryOfCustomCity: 'IE', isCustomCity: true }]);
selectStub.resolves([{ ...defaultAdoptedProbe, countryOfCustomCity: 'IE', isCustomCity: 1 }]);

fetchProbesWithAdminData.resolves([
{
Expand All @@ -343,6 +354,9 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
location: {
continent: 'EU',
region: 'Northern Europe',
Expand Down Expand Up @@ -401,7 +415,15 @@ describe('AdoptedProbes', () => {
await adoptedProbes.syncDashboardData();

const adoptedProbe = adoptedProbes.getByIp('1.1.1.1');
expect(adoptedProbe).to.deep.equal({ ...defaultAdoptedProbe, altIps: [], tags: [{ type: 'user', value: 'u-jimaek-dashboardtag' }], isCustomCity: false });
expect(adoptedProbe).to.deep.equal({
...defaultAdoptedProbe,
altIps: [],
systemTags: [ 'datacenter-network' ],
tags: [{ type: 'user', value: 'u-jimaek-dashboardtag' }],
isCustomCity: false,
isIPv4Supported: true,
isIPv6Supported: true,
});
});

it('getUpdatedLocation method should return updated location', async () => {
Expand All @@ -410,7 +432,7 @@ describe('AdoptedProbes', () => {
...defaultAdoptedProbe,
city: 'Dundalk',
countryOfCustomCity: 'IE',
isCustomCity: true,
isCustomCity: 1,
latitude: 54,
longitude: -6.41667,
}]);
Expand Down Expand Up @@ -439,7 +461,7 @@ describe('AdoptedProbes', () => {
country: 'IE',
countryOfCustomCity: 'GB',
city: 'London',
isCustomCity: true,
isCustomCity: 1,
latitude: 51.50853,
longitude: -0.12574,
}]);
Expand All @@ -454,7 +476,7 @@ describe('AdoptedProbes', () => {
selectStub.resolves([{
...defaultAdoptedProbe,
city: 'Dundalk',
isCustomCity: false,
isCustomCity: 0,
latitude: 54,
longitude: -6.41667,
}]);
Expand All @@ -469,7 +491,10 @@ describe('AdoptedProbes', () => {

await adoptedProbes.syncDashboardData();
const updatedTags = adoptedProbes.getUpdatedTags(defaultConnectedProbe);
expect(updatedTags).to.deep.equal([{ type: 'user', value: 'u-jimaek-dashboardtag' }]);
expect(updatedTags).to.deep.equal([
{ type: 'system', value: 'datacenter-network' },
{ type: 'user', value: 'u-jimaek-dashboardtag' },
]);
});

it('getUpdatedTags method should return same tags array if user tags are empty', async () => {
Expand Down

0 comments on commit aba2d64

Please sign in to comment.