-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter.test.js
More file actions
73 lines (62 loc) · 2.81 KB
/
Copy pathstarter.test.js
File metadata and controls
73 lines (62 loc) · 2.81 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Integration test for the minimal starter — boots the real CAP server
* (in-memory SQLite) and exercises all three layers end-to-end:
*
* (1) frontend — GET /index.html (starter page) and the z2ui5
* bootstrap HTML at GET /rest/root/z2ui5
* (2) service — POST /rest/root/z2ui5 roundtrip returning a draft id
* and the backend-built view XML
* (3) database — the draft row lands in cap2ui5.z2ui5_t_01, readable
* through the AdminService OData endpoint
*/
const path = require("path");
const cds = require("@sap/cds");
const { GET, POST } = cds.test(path.join(__dirname, ".."));
// The z2ui5 roundtrip action and the AdminService are now restricted to
// authenticated users (see z2ui5-service.cds). Under the mocked dev auth the
// requests run as the configured user (package.json cds.requires.auth).
const AUTH = { auth: { username: "alice", password: "alice" } };
const roundtripBody = {
value: {
S_FRONT: {
ORIGIN: "http://localhost",
PATHNAME: "/index.html",
SEARCH: "",
HASH: "",
},
},
};
describe("minimal starter — frontend / service / database", () => {
test("(1) serves the starter page and the z2ui5 bootstrap HTML", async () => {
const page = await GET("/index.html");
expect(page.status).toBe(200);
expect(page.data).toContain("sap-ui-bootstrap");
const bootstrap = await GET("/rest/root/z2ui5");
expect(bootstrap.status).toBe(200);
expect(bootstrap.data).toContain("<!DOCTYPE html>");
});
test("(2) roundtrip POST returns the startup app, a draft id and view XML", async () => {
const { status, data } = await POST("/rest/root/z2ui5", roundtripBody, AUTH);
expect(status).toBe(200);
expect(data.S_FRONT.APP).toBe("z2ui5_cl_ui5_app_start");
expect(data.S_FRONT.ID).toMatch(/^[0-9a-f-]{36}$/);
expect(data.S_FRONT.PARAMS.S_VIEW.XML).toContain("<mvc:View");
});
test("(3) every roundtrip persists a draft row in cap2ui5.z2ui5_t_01", async () => {
const before = Number((await GET("/odata/v4/admin/z2ui5_t_01/$count", AUTH)).data);
const { data } = await POST("/rest/root/z2ui5", roundtripBody, AUTH);
const after = Number((await GET("/odata/v4/admin/z2ui5_t_01/$count", AUTH)).data);
expect(after).toBe(before + 1);
const row = await GET(`/odata/v4/admin/z2ui5_t_01(${data.S_FRONT.ID})`, AUTH);
expect(row.status).toBe(200);
expect(row.data.data).toContain("z2ui5_cl_ui5_app_start");
});
test("(4) the roundtrip and the draft table reject unauthenticated access", async () => {
await expect(POST("/rest/root/z2ui5", roundtripBody)).rejects.toMatchObject({
response: { status: 401 },
});
await expect(GET("/odata/v4/admin/z2ui5_t_01/$count")).rejects.toMatchObject({
response: { status: 401 },
});
});
});