forked from cap-js-community/odata-v2-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit.test.js
112 lines (104 loc) · 3.45 KB
/
audit.test.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"use strict";
const cds = require("@sap/cds");
const supertest = require("supertest");
// eslint-disable-next-line no-restricted-modules
const fs = require("fs");
const util = require("./_env/util/request");
cds.test(__dirname + "/_env");
let request;
describe("auth", () => {
beforeAll(async () => {
await global._init;
request = supertest(cds.app.server);
});
it("POST audit", async () => {
let response = await util.callWrite(request, "/odata/v2/audit/Audits", {
audit_type_ID: 1,
work_activity_ID: 1,
});
expect(response.statusCode).toEqual(201);
expect(response.body).toBeDefined();
expect(response.body.d).toBeDefined();
const id = response.body.d.ID;
expect(id).toBeDefined();
expect(response.body.d).toMatchObject({
ID: id,
start_date: null,
end_date: null,
auditor: null,
audit_status: null,
review_status: null,
audit_type_ID: 1,
work_activity_ID: 1,
audit_type: {
__deferred: {
uri: `http://${response.request.host.replace(
"127.0.0.1",
"localhost",
)}/odata/v2/audit/Audits(guid'${id}')/audit_type`,
},
},
work_activity: {
__deferred: {
uri: `http://${response.request.host.replace(
"127.0.0.1",
"localhost",
)}/odata/v2/audit/Audits(guid'${id}')/work_activity`,
},
},
__metadata: {
uri: `http://${response.request.host.replace("127.0.0.1", "localhost")}/odata/v2/audit/Audits(guid'${id}')`,
type: "audit.AuditService.Audits",
},
});
});
it("POST audit in batch", async () => {
const requestBoundary = "batch_709b8b9352ac4342a0efb1e012d_1";
let payload = fs.readFileSync(__dirname + "/_env/util/batch/Batch-POST-Audit.txt", "utf8");
payload = payload.replace(/\r\n/g, "\n");
let response = await util.callMultipart(request, "/odata/v2/audit/$batch", payload, requestBoundary);
expect(response.statusCode).toEqual(202);
const responseBoundary = response.headers["content-type"].split("boundary=")[1];
const responses = util.splitMultipartResponse(response.body, responseBoundary);
expect(responses.length).toEqual(1);
const [first] = responses;
first.forEach((part) => {
expect(part.statusCode).toEqual(201);
expect(part.contentTransferEncoding).toEqual("binary");
expect(part.body).toBeDefined();
expect(part.body.d).toBeDefined();
const id = part.body.d.ID;
expect(id).toBeDefined();
expect(part.body.d).toMatchObject({
ID: id,
start_date: null,
end_date: null,
auditor: null,
audit_status: null,
review_status: null,
audit_type_ID: 1,
work_activity_ID: 1,
audit_type: {
__deferred: {
uri: `http://${response.request.host.replace(
"127.0.0.1",
"localhost",
)}/odata/v2/audit/Audits(guid'${id}')/audit_type`,
},
},
work_activity: {
__deferred: {
uri: `http://${response.request.host.replace(
"127.0.0.1",
"localhost",
)}/odata/v2/audit/Audits(guid'${id}')/work_activity`,
},
},
__metadata: {
uri: `http://${response.request.host.replace("127.0.0.1", "localhost")}/odata/v2/audit/Audits(guid'${id}')`,
type: "audit.AuditService.Audits",
},
});
});
});
});