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 8b19efb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 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
14 changes: 7 additions & 7 deletions test/tests/unit/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 +70,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 +280,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

0 comments on commit 8b19efb

Please sign in to comment.