Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Nov 22, 2023
1 parent c342a55 commit 094fda4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 8 additions & 0 deletions config/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ CREATE TABLE IF NOT EXISTS directus_users (
github VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS directus_notifications (
id CHAR(10),
recipient CHAR(36),
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
subject VARCHAR(255),
message TEXT
);

INSERT IGNORE INTO adopted_probes (
userId,
lastSyncDate,
Expand Down
16 changes: 7 additions & 9 deletions test/tests/unit/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const defaultConnectedProbe: Probe = {
location: {
continent: 'EU',
region: 'Northern Europe',
normalizedRegion: 'northern europe',
country: 'IE',
city: 'Dublin',
normalizedCity: 'dublin',
Expand All @@ -59,7 +58,7 @@ const defaultConnectedProbe: Probe = {
const selectStub = sinon.stub();
const updateStub = sinon.stub();
const deleteStub = sinon.stub();
const insertStub = sinon.stub();
const rawStub = sinon.stub();
const whereStub = sinon.stub().returns({
update: updateStub,
delete: deleteStub,
Expand All @@ -70,8 +69,8 @@ const joinStub = sinon.stub().returns({
const sqlStub = sinon.stub().returns({
join: joinStub,
where: whereStub,
insert: insertStub,
});
}) as sinon.SinonStub<any[], any> & {raw: any};
sqlStub.raw = rawStub;
const fetchSocketsStub = sinon.stub().resolves([]);
let sandbox: sinon.SinonSandbox;

Expand Down Expand Up @@ -280,13 +279,13 @@ describe('AdoptedProbes', () => {

await adoptedProbes.syncDashboardData();

expect(insertStub.callCount).to.equal(1);
expect(rawStub.callCount).to.equal(1);

expect(insertStub.args[0]).to.deep.equal([{
expect(rawStub.args[0]![1]).to.deep.equal({
recipient: '3cff97ae-4a0a-4f34-9f1a-155e6def0a45',
subject: 'Adopted probe country change',
message: 'Globalping API detected that your adopted probe with ip: 1.1.1.1 is located at "GB". So its country value changed from "IE" to "GB", and previous custom city value "Dublin" is not applied right now.\n\nIf this change is not right please report in [that issue](https://github.com/jsdelivr/globalping/issues/268).',
}]);
message: 'Globalping API detected that your adopted probe with ip: 1.1.1.1 is located at "GB". So its country value changed from "IE" to "GB", and custom city value "Dublin" is not applied right now.\n\nIf this change is not right please report in [that issue](https://github.com/jsdelivr/globalping/issues/268).',
});

expect(whereStub.callCount).to.equal(1);
expect(whereStub.args[0]).to.deep.equal([{ ip: '1.1.1.1' }]);
Expand Down Expand Up @@ -390,7 +389,6 @@ describe('AdoptedProbes', () => {
expect(updatedLocation).to.deep.equal({
continent: 'EU',
region: 'Northern Europe',
normalizedRegion: 'northern europe',
country: 'IE',
city: 'Dundalk',
normalizedCity: 'dundalk',
Expand Down
1 change: 0 additions & 1 deletion test/tests/unit/probe/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ describe('probe router', () => {
const location = {
continent: 'NA',
region: getRegionByCountry('US'),
normalizedRegion: 'northern america',
country: 'US',
state: 'NY',
city: 'The New York City',
Expand Down
3 changes: 0 additions & 3 deletions test/tests/unit/ws/fetch-sockets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('fetchSockets', () => {
location: {
continent: 'EU',
region: 'Western Europe',
normalizedRegion: 'western europe',
country: 'FR',
state: undefined,
city: 'Paris',
Expand Down Expand Up @@ -94,7 +93,6 @@ describe('fetchSockets', () => {
getUpdatedLocation.returns({
continent: 'EU',
region: 'Western Europe',
normalizedRegion: 'western europe',
country: 'FR',
state: undefined,
city: 'Marseille',
Expand Down Expand Up @@ -122,7 +120,6 @@ describe('fetchSockets', () => {
location: {
continent: 'EU',
region: 'Western Europe',
normalizedRegion: 'western europe',
country: 'FR',
state: undefined,
city: 'Marseille',
Expand Down

0 comments on commit 094fda4

Please sign in to comment.