forked from cap-js-community/odata-v2-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask-provider.test.js
82 lines (72 loc) · 2.75 KB
/
task-provider.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
"use strict";
const cds = require("@sap/cds");
const supertest = require("supertest");
const util = require("./_env/util/request");
cds.test(__dirname + "/_env");
let request;
describe("task-provider", () => {
beforeAll(async () => {
await global._init;
request = supertest(cds.app.server);
});
it("Index page including V2 links", async () => {
expect(cds.services["test.MainService"].$linkProviders.length).toEqual(2);
const provider = cds.services["test.TaskProviderService"].$linkProviders[0];
const link = provider("tasks");
expect(link).toEqual({
href: "/task-provider/v2/tasks",
name: "tasks (V2)",
title: "OData V2",
});
});
it("GET service via default path", async () => {
const response = await util.callRead(request, "/odata/v2/task-provider", {
accept: "application/json",
});
expect(response.body).toBeDefined();
expect(response.body).toEqual({
d: {
EntitySets: ["tasks"],
},
});
});
it("GET service data via default path", async () => {
const response = await util.callRead(request, "/odata/v2/task-provider/tasks", {
accept: "application/json",
});
expect(response.body).toBeDefined();
expect(response.body.d.results.length > 0).toEqual(true);
expect(response.body.d.results[0].urn).toEqual(
"urn:sap.odm.bpm.task:4711:task-approval$ea99df92-6225-4d75-bbd0-9b11f73c7f60",
);
expect(response.body.d.results[0].__metadata).toEqual({
type: "test.TaskProviderService.tasks",
uri: `http://${response.request.host.replace("127.0.0.1", "localhost")}/odata/v2/task-provider/tasks('urn:sap.odm.bpm.task:4711:task-approval%24ea99df92-6225-4d75-bbd0-9b11f73c7f60')`,
});
});
it("GET service via protocl odata-v2 path", async () => {
const response = await util.callRead(request, "/task-provider/v2", {
accept: "application/json",
});
expect(response.body).toBeDefined();
expect(response.body).toEqual({
d: {
EntitySets: ["tasks"],
},
});
});
it("GET service data via protocol odata-v2 path", async () => {
const response = await util.callRead(request, "/task-provider/v2/tasks", {
accept: "application/json",
});
expect(response.body).toBeDefined();
expect(response.body.d.results.length > 0).toEqual(true);
expect(response.body.d.results[0].urn).toEqual(
"urn:sap.odm.bpm.task:4711:task-approval$ea99df92-6225-4d75-bbd0-9b11f73c7f60",
);
expect(response.body.d.results[0].__metadata).toEqual({
type: "test.TaskProviderService.tasks",
uri: `http://${response.request.host.replace("127.0.0.1", "localhost")}/task-provider/v2/tasks('urn:sap.odm.bpm.task:4711:task-approval%24ea99df92-6225-4d75-bbd0-9b11f73c7f60')`,
});
});
});