mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 16:37:12 +03:00
clean up getCWSUsers
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
|
|
||||||
export const getCWSUsers = (extID: string) =>
|
export const getCWSUsers = (extID: string): Promise<number | undefined> =>
|
||||||
axios.post(`https://chrome.google.com/webstore/ajax/detail?pv=20210820&id=${extID}`)
|
axios.post(`https://chrome.google.com/webstore/ajax/detail?pv=20210820&id=${extID}`)
|
||||||
.then((res) => res.data.split("\n")[2])
|
.then(res => res.data.split("\n")[2])
|
||||||
.then((data) => JSON.parse(data))
|
.then(data => JSON.parse(data))
|
||||||
.then((data) => (data[1][1][0][23]).replaceAll(/,|\+/g,""))
|
.then(data => (data[1][1][0][23]).replaceAll(/,|\+/g,""))
|
||||||
.then((data) => parseInt(data))
|
.then(data => parseInt(data))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
Logger.error(`Error getting chrome users - ${err}`);
|
Logger.error(`Error getting chrome users - ${err}`);
|
||||||
return undefined;
|
return 0;
|
||||||
});
|
});
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { client } from "../utils/httpClient";
|
import { client } from "../utils/httpClient";
|
||||||
import sinon from "sinon";
|
|
||||||
import * as getCWSUsers from "../../src/utils/getCWSUsers";
|
|
||||||
|
|
||||||
const endpoint = "/api/getTotalStats";
|
const endpoint = "/api/getTotalStats";
|
||||||
|
|
||||||
@@ -28,9 +26,7 @@ describe("getTotalStats", () => {
|
|||||||
assert.ok(data.minutesSaved >= 0);
|
assert.ok(data.minutesSaved >= 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Can get total stats with old cws method", async () => {
|
it("Can get total stats with contributing users", async () => {
|
||||||
const stub = sinon.stub(getCWSUsers, "getCWSUsers");
|
|
||||||
stub.resolves(undefined);
|
|
||||||
const result = await client({ url: `${endpoint}?countContributingUsers=true` });
|
const result = await client({ url: `${endpoint}?countContributingUsers=true` });
|
||||||
const data = result.data;
|
const data = result.data;
|
||||||
assert.ok(data.userCount >= 0);
|
assert.ok(data.userCount >= 0);
|
||||||
@@ -39,6 +35,5 @@ describe("getTotalStats", () => {
|
|||||||
assert.ok(data.viewCount >= 0);
|
assert.ok(data.viewCount >= 0);
|
||||||
assert.ok(data.totalSubmissions >= 0);
|
assert.ok(data.totalSubmissions >= 0);
|
||||||
assert.ok(data.minutesSaved >= 0);
|
assert.ok(data.minutesSaved >= 0);
|
||||||
stub.restore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user