feat: add logto auth and backend metrics integration
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { DEFAULT_BACKEND_METRICS_BASE_URL } from "../src/shared/backend-metrics-config";
|
||||
import {
|
||||
buildBackendMetricsSearchRequestBody,
|
||||
buildBackendMetricsSearchUrl,
|
||||
createBackendMetricsClient,
|
||||
mapBackendMetricsSearchResponse
|
||||
} from "../src/shared/backend-metrics-client";
|
||||
|
||||
describe("backend-metrics-client", () => {
|
||||
test("exports the default backend metrics base url", () => {
|
||||
expect(DEFAULT_BACKEND_METRICS_BASE_URL).toBe("http://192.168.31.29:8083");
|
||||
});
|
||||
|
||||
test("builds the backend search url", () => {
|
||||
expect(buildBackendMetricsSearchUrl("http://192.168.31.29:8083")).toBe(
|
||||
"http://192.168.31.29:8083/api/v1/history/talents/search"
|
||||
);
|
||||
});
|
||||
|
||||
test("builds a star_id batch request body", () => {
|
||||
expect(
|
||||
buildBackendMetricsSearchRequestBody(["7252982749131178039", "7290491710910496809"])
|
||||
).toEqual({
|
||||
page: 1,
|
||||
size: 20,
|
||||
type: "star_id",
|
||||
values: ["7252982749131178039", "7290491710910496809"]
|
||||
});
|
||||
});
|
||||
|
||||
test("maps backend metrics rows into display-ready values", () => {
|
||||
expect(
|
||||
mapBackendMetricsSearchResponse({
|
||||
data: {
|
||||
data: [
|
||||
{
|
||||
avg_a3_increase_cnt: 78366.22448979592,
|
||||
avg_after_view_search_cnt: 9689.959183673469,
|
||||
avg_after_view_search_rate: 0.0036203703369054683,
|
||||
avg_new_a3_rate: 0.034428135017531614,
|
||||
cp_search: 14.460581961550774,
|
||||
cpa3: 1.788046443373538,
|
||||
star_id: "7252982749131178039"
|
||||
}
|
||||
]
|
||||
},
|
||||
success: true
|
||||
})
|
||||
).toEqual([
|
||||
{
|
||||
a3IncreaseCount: "78,366.22",
|
||||
afterViewSearchCount: "9,689.96",
|
||||
afterViewSearchRate: "0.36%",
|
||||
cpSearch: "14.46",
|
||||
cpa3: "1.79",
|
||||
newA3Rate: "3.44%",
|
||||
starId: "7252982749131178039"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test("posts star ids with bearer auth when searching backend metrics", async () => {
|
||||
const fetchImpl = async (_input: string, init?: RequestInit) => ({
|
||||
json: async () => ({
|
||||
data: {
|
||||
data: []
|
||||
},
|
||||
success: true
|
||||
}),
|
||||
ok: true,
|
||||
status: 200,
|
||||
url: "http://192.168.31.29:8083/api/v1/history/talents/search"
|
||||
});
|
||||
const fetchSpy = vi.fn(fetchImpl);
|
||||
const client = createBackendMetricsClient({
|
||||
fetchImpl: fetchSpy,
|
||||
getAccessToken: async () => "test-token"
|
||||
});
|
||||
|
||||
await client.searchByStarIds(["111", "222"]);
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalledWith(
|
||||
"http://192.168.31.29:8083/api/v1/history/talents/search",
|
||||
expect.objectContaining({
|
||||
body: JSON.stringify({
|
||||
page: 1,
|
||||
size: 20,
|
||||
type: "star_id",
|
||||
values: ["111", "222"]
|
||||
}),
|
||||
headers: {
|
||||
Authorization: "Bearer test-token",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
method: "POST"
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user