-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcreate-manifest-handler.test.ts
51 lines (44 loc) · 1.53 KB
/
create-manifest-handler.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, expect, it, vi } from "vitest";
import { SALEOR_SCHEMA_VERSION } from "@/const";
import { createManifestHandler, CreateManifestHandlerOptions } from "./create-manifest-handler";
describe("Fetch API createManifestHandler", () => {
it("Creates a handler that responds with manifest, includes a request and baseUrl in factory method", async () => {
const baseUrl = "https://some-app-host.cloud";
const request = new Request(baseUrl, {
headers: {
host: "some-app-host.cloud",
"x-forwarded-proto": "https",
[SALEOR_SCHEMA_VERSION]: "3.20",
},
method: "GET",
});
const mockManifestFactory = vi
.fn<CreateManifestHandlerOptions["manifestFactory"]>()
.mockImplementation(({ appBaseUrl }) => ({
name: "Test app",
tokenTargetUrl: `${appBaseUrl}/api/register`,
appUrl: appBaseUrl,
permissions: [],
id: "app-id",
version: "1",
}));
const handler = createManifestHandler({
manifestFactory: mockManifestFactory,
});
const response = await handler(request);
expect(mockManifestFactory).toHaveBeenCalledWith({
appBaseUrl: baseUrl,
request,
schemaVersion: [3, 20],
});
expect(response.status).toBe(200);
await expect(response.json()).resolves.toStrictEqual({
appUrl: "https://some-app-host.cloud",
id: "app-id",
name: "Test app",
permissions: [],
tokenTargetUrl: "https://some-app-host.cloud/api/register",
version: "1",
});
});
});