Skip to content

Commit

Permalink
start adding telemetry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmachado committed Oct 9, 2023
1 parent 788076d commit 5b1e4e5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/unit-tests/services/telemetry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const sinon = require("sinon");
const chai = require("chai");
const fs = require("fs");
const Telemetry = require("../../../src/services/telemetry");

const { expect } = chai;

describe("Telemetry", () => {
let appMock, telemetry, fsReadStub, fsWriteStub, uuidStub;

beforeEach(() => {
// Mocking app object
appMock = {
_isShutdown: false,
logger: {
info: sinon.stub(),
debug: sinon.stub(),
error: sinon.stub()
},
config: {
TELEMETRY_URL: "http://fake.telemetry",
},
healthReport: {
fullReport: sinon.stub().resolves({}),
},
};

fsReadStub = sinon.stub(fs, "readFileSync");
fsWriteStub = sinon.stub(fs, "writeFileSync");

telemetry = new Telemetry(appMock);
});

afterEach(() => {
sinon.restore();
});

it("should read uuid from file", async () => {
fsReadStub.returns("existing-uuid");
await telemetry.start();
expect(fsReadStub.calledOnceWith("data/uuid.txt", "utf8")).to.be.true;
});

it("should write uuid to file if not exists", async () => {
fsReadStub.throws(new Error("File not found"));
await telemetry.start();
expect(fsWriteStub.calledOnceWith("data/uuid.txt", sinon.match.string)).to.be.true;
});
});

0 comments on commit 5b1e4e5

Please sign in to comment.