-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCode.test.ts
More file actions
154 lines (147 loc) · 4.19 KB
/
Copy pathCode.test.ts
File metadata and controls
154 lines (147 loc) · 4.19 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* JavaScript tests to test the code functionality
*/
import { cb, platformUrl, mockRequest } from "./utils";
describe("ClearBlade code", function () {
it("create code service", function () {
var code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
var serviceBody = {
code: "return null;",
parameters: [],
name: "fakeNewService",
dependencies: "",
};
var expectedData = {
method: "POST",
endpoint: "api/v/3/code/fakeSystemKey/service/fakeNewService",
URI: platformUrl,
body: serviceBody,
user: {
authToken: "testUserToken",
},
};
code.create("fakeNewService", serviceBody, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("update code service", function () {
var code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
var serviceBody = {
code: "return null;",
parameters: [],
name: "fakeNewService",
dependencies: "",
};
var expectedData = {
method: "PUT",
endpoint: "api/v/3/code/fakeSystemKey/service/fakeNewService",
URI: platformUrl,
body: serviceBody,
user: {
authToken: "testUserToken",
},
};
code.update("fakeNewService", serviceBody, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("delete code service", function () {
var code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
var expectedData = {
method: "DELETE",
endpoint: "api/v/3/code/fakeSystemKey/service/fakeNewService",
URI: platformUrl,
user: {
authToken: "testUserToken",
},
};
code.delete("fakeNewService", function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("executes given code service with params", function () {
var code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
var params = {
name: "charlie",
age: 23,
};
var expectedData = {
method: "POST",
endpoint: "api/v/1/code/fakeSystemKey/fakeCodeService",
URI: platformUrl,
body: {
name: "charlie",
age: 23,
},
user: {
authToken: "testUserToken",
},
timeout: 30000,
};
code.execute("fakeCodeService", params, function (err, data) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual(expectedData);
});
});
it("code.execute accepts id in options", function () {
const code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
code.execute(
"fakeCodeService",
{},
function (err) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual({
method: "POST",
endpoint: "api/v/1/code/fakeSystemKey/fakeCodeService?id=myUniqueId",
URI: platformUrl,
body: {},
user: {
authToken: "testUserToken",
},
timeout: 30000,
});
},
{
id: "myUniqueId",
}
);
});
it("code.execute accepts requestTimeout in options", function () {
const code = cb.Code();
var callNum = mockRequest.mock.calls.length; // we need this for later
code.execute(
"fakeCodeService",
{},
function (err) {
expect(err).toBeNull();
expect(mockRequest.mock.calls[callNum][0]).toEqual({
method: "POST",
endpoint: "api/v/1/code/fakeSystemKey/fakeCodeService",
URI: platformUrl,
body: {},
user: {
authToken: "testUserToken",
},
timeout: 420000,
});
},
{
requestTimeout: 420000,
}
);
});
});