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", () => {
|
2023-09-28 02:18:35 +02:00
|
|
|
it("Should return 200", function () {
|
2022-09-21 07:14:22 +02:00
|
|
|
if (!config.userCounterURL) this.skip(); // skip if no userCounterURL is set
|
2023-09-28 02:18:35 +02:00
|
|
|
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)
|
|
|
|
}
|
2023-09-28 02:18:35 +02:00
|
|
|
}).then(res => assert.strictEqual(res.status, 200));
|
2021-09-23 07:21:10 +02:00
|
|
|
});
|
2023-09-28 02:18:35 +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);
|
2023-09-28 02:18:35 +02:00
|
|
|
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
|
|
|
});
|