SponsorBlockServer/test/cases/userCounter.ts

27 lines
1 KiB
TypeScript
Raw Normal View History

2021-09-23 07:21:10 +02:00
import axios from "axios";
import assert from "assert";
import { config } from "../../src/config";
import { getHash } from "../../src/utils/getHash";
2023-02-21 04:21:53 +01:00
import { client } from "../utils/httpClient";
2021-09-23 07:21:10 +02:00
describe("userCounter", () => {
it("Should return 200", function () {
if (!config.userCounterURL) this.skip(); // skip if no userCounterURL is set
return axios.request({
2021-09-23 07:21:10 +02:00
method: "POST",
baseURL: config.userCounterURL,
url: "/api/v1/addIP",
params: {
hashedIP: getHash("127.0.0.1",1)
}
}).then(res => assert.strictEqual(res.status, 200));
2021-09-23 07:21:10 +02:00
});
it("Should not incremeent counter on OPTIONS", function () {
2023-02-21 04:21:53 +01:00
/* cannot spy test */
if (!config.userCounterURL) this.skip(); // skip if no userCounterURL is set
//const spy = sinon.spy(UserCounter);
return client({ method: "OPTIONS", url: "/api/status" })
2023-02-21 04:21:53 +01:00
.then(() => client({ method: "GET", url: "/api/status" }));
//assert.strictEqual(spy.callCount, 1);
});
2021-09-23 07:21:10 +02:00
});