test: harden MVP QA gate
This commit is contained in:
parent
081d6085a5
commit
bdb02daa96
11 changed files with 479 additions and 44 deletions
|
|
@ -1,7 +1,22 @@
|
|||
import { describe, expect, test } from "vitest";
|
||||
import { setupServer } from "msw/node";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest";
|
||||
import { externalApiHandlers } from "./external-api-mocks";
|
||||
|
||||
const server = setupServer(...externalApiHandlers);
|
||||
|
||||
describe("external API mocks", () => {
|
||||
beforeAll(() => {
|
||||
server.listen({ onUnhandledRequest: "error" });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
test("defines deterministic handlers for deferred datasource adapters", () => {
|
||||
expect(externalApiHandlers).toHaveLength(3);
|
||||
expect(externalApiHandlers.map((handler) => handler.info.header)).toEqual([
|
||||
|
|
@ -10,4 +25,31 @@ describe("external API mocks", () => {
|
|||
"GET https://api.open-meteo.com/v1/forecast",
|
||||
]);
|
||||
});
|
||||
|
||||
test("intercepts deferred datasource requests without live services", async () => {
|
||||
const prometheus = await fetch(
|
||||
"https://prometheus.dimensionlab.net/api/v1/query",
|
||||
).then((response) => response.json());
|
||||
const status = await fetch(
|
||||
"https://uptime.dimensionlab.net/api/status-page/dimensionlab",
|
||||
).then((response) => response.json());
|
||||
const weather = await fetch(
|
||||
"https://api.open-meteo.com/v1/forecast?latitude=52.37&longitude=4.9",
|
||||
).then((response) => response.json());
|
||||
|
||||
expect(prometheus).toMatchObject({
|
||||
status: "success",
|
||||
data: { result: [{ value: [1771430400, "1"] }] },
|
||||
});
|
||||
expect(status).toMatchObject({
|
||||
status: "ok",
|
||||
incidents: [],
|
||||
});
|
||||
expect(weather).toMatchObject({
|
||||
current: {
|
||||
temperature_2m: 21.4,
|
||||
weather_code: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue