chore: add test for recordClientVersion (@fehmer) (#5746)

This commit is contained in:
Christian Fehmer 2024-08-08 18:27:00 +02:00 committed by GitHub
parent 0a0f175291
commit 45d27b5e00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View file

@ -1,15 +1,18 @@
import request from "supertest";
import app from "../../../src/app";
import * as PsaDal from "../../../src/dal/psa";
import * as Prometheus from "../../../src/utils/prometheus";
import { ObjectId } from "mongodb";
const mockApp = request(app);
describe("Psa Controller", () => {
describe("get psa", () => {
const getPsaMock = vi.spyOn(PsaDal, "get");
const recordClientVersionMock = vi.spyOn(Prometheus, "recordClientVersion");
afterEach(() => {
getPsaMock.mockReset();
recordClientVersionMock.mockReset();
});
it("get psas without authorization", async () => {
@ -53,6 +56,8 @@ describe("Psa Controller", () => {
},
],
});
expect(recordClientVersionMock).toHaveBeenCalledWith("unknown");
});
it("get psas with authorization", async () => {
await mockApp
@ -60,5 +65,16 @@ describe("Psa Controller", () => {
.set("authorization", `Uid 123456789`)
.expect(200);
});
it("get psas records x-client-version", async () => {
await mockApp.get("/psas").set("x-client-version", "1.0").expect(200);
expect(recordClientVersionMock).toHaveBeenCalledWith("1.0");
});
it("get psas records client-version", async () => {
await mockApp.get("/psas").set("client-version", "2.0").expect(200);
expect(recordClientVersionMock).toHaveBeenCalledWith("2.0");
});
});
});

View file

@ -34,7 +34,7 @@ export const presetsContract = c.router(
summary: "get presets",
description: "Get presets of the current user.",
method: "GET",
path: "/",
path: "",
responses: {
200: GetPresetResponseSchema,
},
@ -43,7 +43,7 @@ export const presetsContract = c.router(
summary: "add preset",
description: "Add a new preset for the current user.",
method: "POST",
path: "/",
path: "",
body: AddPresetRequestSchema.strict(),
responses: {
200: AddPresetResponseSchemna,
@ -53,7 +53,7 @@ export const presetsContract = c.router(
summary: "update preset",
description: "Update an existing preset for the current user.",
method: "PATCH",
path: "/",
path: "",
body: PresetSchema.strict(),
responses: {
200: MonkeyResponseSchema,