add more tests for coverage

This commit is contained in:
Michael C
2023-02-20 22:21:46 -05:00
parent d04230a1c4
commit 72fb4eb6ec
5 changed files with 66 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
import assert from "assert";
import { client } from "../utils/httpClient";
import sinon from "sinon";
import * as getCWSUsers from "../../src/utils/getCWSUsers";
const endpoint = "/api/getTotalStats";
@@ -7,11 +9,36 @@ describe("getTotalStats", () => {
it("Can get total stats", async () => {
const result = await client({ url: endpoint });
const data = result.data;
assert.ok(data?.userCount ?? true);
assert.ok(data.userCount >= 0);
assert.ok(data.activeUsers >= 0);
assert.ok(data.apiUsers >= 0);
assert.ok(data.viewCount >= 0);
assert.ok(data.totalSubmissions >= 0);
assert.ok(data.minutesSaved >= 0);
});
it("Can get total stats without contributing users", async () => {
const result = await client({ url: `${endpoint}?countContributingUsers=false` });
const data = result.data;
assert.strictEqual(data.userCount, 0);
assert.ok(data.activeUsers >= 0);
assert.ok(data.apiUsers >= 0);
assert.ok(data.viewCount >= 0);
assert.ok(data.totalSubmissions >= 0);
assert.ok(data.minutesSaved >= 0);
});
it("Can get total stats with old cws method", async () => {
const stub = sinon.stub(getCWSUsers, "getCWSUsers");
stub.resolves(undefined);
const result = await client({ url: `${endpoint}?countContributingUsers=false` });
const data = result.data;
assert.strictEqual(data.userCount, 0);
assert.ok(data.activeUsers >= 0);
assert.ok(data.apiUsers >= 0);
assert.ok(data.viewCount >= 0);
assert.ok(data.totalSubmissions >= 0);
assert.ok(data.minutesSaved >= 0);
stub.restore();
});
});