1
1
import { expect } from 'chai' ;
2
2
import * as sinon from 'sinon' ;
3
3
import relativeDayUtc from 'relative-day-utc' ;
4
- import { AdoptedProbes } from '../../../../src/lib/override/adopted-probes.js' ;
4
+ import { AdoptedProbes , Row } from '../../../../src/lib/override/adopted-probes.js' ;
5
5
import type { Probe } from '../../../../src/probe/types.js' ;
6
6
7
7
describe ( 'AdoptedProbes' , ( ) => {
8
- const defaultAdoptedProbe = {
8
+ const defaultAdoptedProbe : Row = {
9
9
id : 'p-1' ,
10
+ name : 'probe-1' ,
10
11
userId : '3cff97ae-4a0a-4f34-9f1a-155e6def0a45' ,
11
- username : 'jimaek' ,
12
12
ip : '1.1.1.1' ,
13
13
altIps : '[]' ,
14
14
uuid : '1-1-1-1-1' ,
@@ -30,6 +30,8 @@ describe('AdoptedProbes', () => {
30
30
longitude : - 6.25 ,
31
31
asn : 16509 ,
32
32
network : 'Amazon.com, Inc.' ,
33
+ githubUsername : 'jimaek' ,
34
+ publicProbes : 0 ,
33
35
} ;
34
36
35
37
const defaultConnectedProbe : Probe = {
@@ -87,6 +89,7 @@ describe('AdoptedProbes', () => {
87
89
where : sandbox . stub ( ) ,
88
90
orWhere : sandbox . stub ( ) ,
89
91
whereIn : sandbox . stub ( ) ,
92
+ leftJoin : sandbox . stub ( ) ,
90
93
orderByRaw : sandbox . stub ( ) ,
91
94
} as any ;
92
95
const sqlStub = sandbox . stub ( ) as any ;
@@ -102,6 +105,7 @@ describe('AdoptedProbes', () => {
102
105
sql . where . returns ( sql ) ;
103
106
sql . orWhere . returns ( sql ) ;
104
107
sql . whereIn . returns ( sql ) ;
108
+ sql . leftJoin . returns ( sql ) ;
105
109
sql . orderByRaw . returns ( sql ) ;
106
110
sql . select . resolves ( [ defaultAdoptedProbe ] ) ;
107
111
sqlStub . returns ( sql ) ;
@@ -412,16 +416,14 @@ describe('AdoptedProbes', () => {
412
416
413
417
expect ( sql . raw . callCount ) . to . equal ( 2 ) ;
414
418
415
- expect ( sql . raw . args [ 0 ] ! [ 1 ] ) . to . deep . equal ( {
419
+ expect ( sql . raw . args [ 0 ] ! [ 1 ] ) . to . deep . include ( {
416
420
recipient : '3cff97ae-4a0a-4f34-9f1a-155e6def0a45' ,
417
- subject : `Your probe's location has changed` ,
418
- message : 'Globalping detected that your [probe with IP address **1.1.1.1**](/probes/p-1) has changed its location from Ireland to United Kingdom. The custom city value "Dublin" is not applied anymore.\n\nIf this change is not right, please report it in [this issue](https://github.com/jsdelivr/globalping/issues/268).' ,
421
+ subject : 'Your probe\'s location has changed' ,
419
422
} ) ;
420
423
421
- expect ( sql . raw . args [ 1 ] ! [ 1 ] ) . to . deep . equal ( {
424
+ expect ( sql . raw . args [ 1 ] ! [ 1 ] ) . to . deep . include ( {
422
425
recipient : '3cff97ae-4a0a-4f34-9f1a-155e6def0a45' ,
423
426
subject : `Your probe's location has changed` ,
424
- message : 'Globalping detected that your probe [**probe-gb-london-01**](/probes/p-9) with IP address **9.9.9.9** has changed its location from Ireland to United Kingdom. The custom city value "Dublin" is not applied anymore.\n\nIf this change is not right, please report it in [this issue](https://github.com/jsdelivr/globalping/issues/268).' ,
425
427
} ) ;
426
428
427
429
expect ( sql . where . callCount ) . to . equal ( 2 ) ;
@@ -514,10 +516,9 @@ describe('AdoptedProbes', () => {
514
516
515
517
expect ( sql . raw . callCount ) . to . equal ( 4 ) ;
516
518
517
- expect ( sql . raw . args [ 2 ] ! [ 1 ] ) . to . deep . equal ( {
519
+ expect ( sql . raw . args [ 2 ] ! [ 1 ] ) . to . deep . include ( {
518
520
recipient : '3cff97ae-4a0a-4f34-9f1a-155e6def0a45' ,
519
521
subject : `Your probe's location has changed back` ,
520
- message : 'Globalping detected that your [probe with IP address **1.1.1.1**](/probes/p-1) has changed its location back from United Kingdom to Ireland. The custom city value "Dublin" is now applied again.' ,
521
522
} ) ;
522
523
523
524
expect ( sql . raw . args [ 3 ] ! [ 1 ] ) . to . deep . equal ( {
@@ -761,6 +762,7 @@ describe('AdoptedProbes', () => {
761
762
isCustomCity : false ,
762
763
isIPv4Supported : true ,
763
764
isIPv6Supported : true ,
765
+ publicProbes : false ,
764
766
} ) ;
765
767
} ) ;
766
768
@@ -827,7 +829,17 @@ describe('AdoptedProbes', () => {
827
829
expect ( updatedLocation ) . to . equal ( null ) ;
828
830
} ) ;
829
831
830
- it ( 'getUpdatedTags method should return updated tags' , async ( ) => {
832
+ it ( 'getUpdatedTags method should return same tags array' , async ( ) => {
833
+ delete process . env [ 'SHOULD_SYNC_ADOPTIONS' ] ;
834
+ const adoptedProbes = new AdoptedProbes ( sqlStub , getProbesWithAdminData ) ;
835
+ sql . select . resolves ( [ { ...defaultAdoptedProbe , tags : '[]' } ] ) ;
836
+
837
+ await adoptedProbes . syncDashboardData ( ) ;
838
+ const updatedTags = adoptedProbes . getUpdatedTags ( defaultConnectedProbe ) ;
839
+ expect ( updatedTags ) . to . equal ( defaultConnectedProbe . tags ) ;
840
+ } ) ;
841
+
842
+ it ( 'getUpdatedTags method should return user tags' , async ( ) => {
831
843
delete process . env [ 'SHOULD_SYNC_ADOPTIONS' ] ;
832
844
const adoptedProbes = new AdoptedProbes ( sqlStub , getProbesWithAdminData ) ;
833
845
@@ -839,13 +851,16 @@ describe('AdoptedProbes', () => {
839
851
] ) ;
840
852
} ) ;
841
853
842
- it ( 'getUpdatedTags method should return same tags array if user tags are empty ' , async ( ) => {
854
+ it ( 'getUpdatedTags method should include user tag if public_probes: true ' , async ( ) => {
843
855
delete process . env [ 'SHOULD_SYNC_ADOPTIONS' ] ;
844
856
const adoptedProbes = new AdoptedProbes ( sqlStub , getProbesWithAdminData ) ;
845
- sql . select . resolves ( [ { ...defaultAdoptedProbe , tags : '[]' } ] ) ;
857
+ sql . select . resolves ( [ { ...defaultAdoptedProbe , tags : '[]' , publicProbes : 1 } ] ) ;
846
858
847
859
await adoptedProbes . syncDashboardData ( ) ;
848
860
const updatedTags = adoptedProbes . getUpdatedTags ( defaultConnectedProbe ) ;
849
- expect ( updatedTags ) . to . equal ( defaultConnectedProbe . tags ) ;
861
+ expect ( updatedTags ) . to . deep . equal ( [
862
+ { type : 'system' , value : 'datacenter-network' } ,
863
+ { type : 'user' , value : 'u-jimaek' } ,
864
+ ] ) ;
850
865
} ) ;
851
866
} ) ;
0 commit comments