From 4b8bc418ba4c8a55d1ab4392fbdc514efd7ac609 Mon Sep 17 00:00:00 2001 From: Michael C Date: Tue, 21 Feb 2023 20:09:38 -0500 Subject: [PATCH] clean up getCWSUsers --- src/utils/getCWSUsers.ts | 12 ++++++------ test/cases/getTotalStats.ts | 7 +------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/utils/getCWSUsers.ts b/src/utils/getCWSUsers.ts index 78c9eb7..35aeaf0 100644 --- a/src/utils/getCWSUsers.ts +++ b/src/utils/getCWSUsers.ts @@ -1,13 +1,13 @@ import axios from "axios"; import { Logger } from "../utils/logger"; -export const getCWSUsers = (extID: string) => +export const getCWSUsers = (extID: string): Promise => axios.post(`https://chrome.google.com/webstore/ajax/detail?pv=20210820&id=${extID}`) - .then((res) => res.data.split("\n")[2]) - .then((data) => JSON.parse(data)) - .then((data) => (data[1][1][0][23]).replaceAll(/,|\+/g,"")) - .then((data) => parseInt(data)) + .then(res => res.data.split("\n")[2]) + .then(data => JSON.parse(data)) + .then(data => (data[1][1][0][23]).replaceAll(/,|\+/g,"")) + .then(data => parseInt(data)) .catch((err) => { Logger.error(`Error getting chrome users - ${err}`); - return undefined; + return 0; }); \ No newline at end of file diff --git a/test/cases/getTotalStats.ts b/test/cases/getTotalStats.ts index bf09653..775be29 100644 --- a/test/cases/getTotalStats.ts +++ b/test/cases/getTotalStats.ts @@ -1,7 +1,5 @@ import assert from "assert"; import { client } from "../utils/httpClient"; -import sinon from "sinon"; -import * as getCWSUsers from "../../src/utils/getCWSUsers"; const endpoint = "/api/getTotalStats"; @@ -28,9 +26,7 @@ describe("getTotalStats", () => { assert.ok(data.minutesSaved >= 0); }); - it("Can get total stats with old cws method", async () => { - const stub = sinon.stub(getCWSUsers, "getCWSUsers"); - stub.resolves(undefined); + it("Can get total stats with contributing users", async () => { const result = await client({ url: `${endpoint}?countContributingUsers=true` }); const data = result.data; assert.ok(data.userCount >= 0); @@ -39,6 +35,5 @@ describe("getTotalStats", () => { assert.ok(data.viewCount >= 0); assert.ok(data.totalSubmissions >= 0); assert.ok(data.minutesSaved >= 0); - stub.restore(); }); }); \ No newline at end of file