add 4xx tests

This commit is contained in:
Michael C
2022-09-25 03:31:25 -04:00
parent a469f2f382
commit c34de1baa4
5 changed files with 164 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
import assert from "assert";
import { client } from "../utils/httpClient";
import sinon from "sinon";
import { db } from "../../src/databases/databases";
const endpoint = "/api/getDaysSavedFormatted";
@@ -8,4 +10,18 @@ describe("getDaysSavedFormatted", () => {
const result = await client({ url: endpoint });
assert.ok(result.data.daysSaved >= 0);
});
it("returns 0 days saved if no segments", async () => {
const stub = sinon.stub(db, "prepare").resolves(undefined);
const result = await client({ url: endpoint });
assert.ok(result.data.daysSaved >= 0);
stub.restore();
});
it("returns days saved to 2 fixed points", async () => {
const stub = sinon.stub(db, "prepare").resolves({ daysSaved: 1.23456789 });
const result = await client({ url: endpoint });
assert.strictEqual(result.data.daysSaved, "1.23");
stub.restore();
});
});