@kintone/rest-api-client 5.0.3 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/esm/package.json +13 -9
  2. package/esm/src/KintoneFields/exportTypes/__checks__/usecases/layout.js.map +1 -1
  3. package/esm/src/KintoneRequestConfigBuilder.js.map +1 -1
  4. package/esm/src/KintoneResponseHandler.js.map +1 -1
  5. package/esm/src/KintoneRestAPIClient.js.map +1 -1
  6. package/esm/src/client/BulkRequestClient.js.map +1 -1
  7. package/esm/src/client/FileClient.js.map +1 -1
  8. package/esm/src/client/RecordClient.js.map +1 -1
  9. package/esm/src/error/KintoneAbortSearchError.js.map +1 -1
  10. package/esm/src/error/KintoneAllRecordsError.js.map +1 -1
  11. package/esm/src/error/KintoneRestAPIError.js.map +1 -1
  12. package/esm/src/http/index.d.ts +1 -1
  13. package/esm/src/platform/UnsupportedPlatformError.js.map +1 -1
  14. package/esm/src/platform/browser.js.map +1 -1
  15. package/esm/src/platform/index.js.map +1 -1
  16. package/esm/src/platform/node.js.map +1 -1
  17. package/esm/tsconfig.build.esm.tsbuildinfo +1 -0
  18. package/lib/package.json +13 -9
  19. package/lib/src/KintoneFields/exportTypes/__checks__/usecases/layout.js.map +1 -1
  20. package/lib/src/KintoneRequestConfigBuilder.js.map +1 -1
  21. package/lib/src/KintoneResponseHandler.js.map +1 -1
  22. package/lib/src/KintoneRestAPIClient.js.map +1 -1
  23. package/lib/src/client/BulkRequestClient.js.map +1 -1
  24. package/lib/src/client/FileClient.js.map +1 -1
  25. package/lib/src/client/RecordClient.js.map +1 -1
  26. package/lib/src/error/KintoneAbortSearchError.js.map +1 -1
  27. package/lib/src/error/KintoneAllRecordsError.js.map +1 -1
  28. package/lib/src/error/KintoneRestAPIError.js.map +1 -1
  29. package/lib/src/http/index.d.ts +1 -1
  30. package/lib/src/platform/UnsupportedPlatformError.js.map +1 -1
  31. package/lib/src/platform/browser.js.map +1 -1
  32. package/lib/src/platform/index.js.map +1 -1
  33. package/lib/src/platform/node.js.map +1 -1
  34. package/lib/tsconfig.build.tsbuildinfo +1 -0
  35. package/lib/tsconfig.typecheck.node.tsbuildinfo +1 -0
  36. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  37. package/package.json +13 -9
  38. package/umd/KintoneRestAPIClient.js +128 -62
  39. package/umd/KintoneRestAPIClient.min.js +3 -3
  40. package/esm/src/__tests__/KintoneRequestConfigBuilder.test.d.ts +0 -1
  41. package/esm/src/__tests__/KintoneRequestConfigBuilder.test.js +0 -759
  42. package/esm/src/__tests__/KintoneRequestConfigBuilder.test.js.map +0 -1
  43. package/esm/src/__tests__/KintoneResponseHandler.test.d.ts +0 -1
  44. package/esm/src/__tests__/KintoneResponseHandler.test.js +0 -182
  45. package/esm/src/__tests__/KintoneResponseHandler.test.js.map +0 -1
  46. package/esm/src/__tests__/KintoneRestAPIClient.test.d.ts +0 -1
  47. package/esm/src/__tests__/KintoneRestAPIClient.test.js +0 -138
  48. package/esm/src/__tests__/KintoneRestAPIClient.test.js.map +0 -1
  49. package/esm/src/__tests__/index.browser.test.d.ts +0 -1
  50. package/esm/src/__tests__/index.browser.test.js +0 -15
  51. package/esm/src/__tests__/index.browser.test.js.map +0 -1
  52. package/esm/src/__tests__/index.test.d.ts +0 -1
  53. package/esm/src/__tests__/index.test.js +0 -15
  54. package/esm/src/__tests__/index.test.js.map +0 -1
  55. package/esm/src/__tests__/setup.d.ts +0 -1
  56. package/esm/src/__tests__/setup.js +0 -6
  57. package/esm/src/__tests__/setup.js.map +0 -1
  58. package/esm/src/__tests__/url.test.d.ts +0 -1
  59. package/esm/src/__tests__/url.test.js +0 -11
  60. package/esm/src/__tests__/url.test.js.map +0 -1
  61. package/esm/src/client/__tests__/AppClient.test.d.ts +0 -1
  62. package/esm/src/client/__tests__/AppClient.test.js +0 -1618
  63. package/esm/src/client/__tests__/AppClient.test.js.map +0 -1
  64. package/esm/src/client/__tests__/BulkRequestClient.test.d.ts +0 -1
  65. package/esm/src/client/__tests__/BulkRequestClient.test.js +0 -235
  66. package/esm/src/client/__tests__/BulkRequestClient.test.js.map +0 -1
  67. package/esm/src/client/__tests__/File.test.d.ts +0 -1
  68. package/esm/src/client/__tests__/File.test.js +0 -208
  69. package/esm/src/client/__tests__/File.test.js.map +0 -1
  70. package/esm/src/client/__tests__/RecordClient.test.d.ts +0 -1
  71. package/esm/src/client/__tests__/RecordClient.test.js +0 -1747
  72. package/esm/src/client/__tests__/RecordClient.test.js.map +0 -1
  73. package/esm/src/error/__tests__/KintoneAbortSearchError.test.d.ts +0 -1
  74. package/esm/src/error/__tests__/KintoneAbortSearchError.test.js +0 -9
  75. package/esm/src/error/__tests__/KintoneAbortSearchError.test.js.map +0 -1
  76. package/esm/src/error/__tests__/KintoneAllRecordsError.test.d.ts +0 -1
  77. package/esm/src/error/__tests__/KintoneAllRecordsError.test.js +0 -152
  78. package/esm/src/error/__tests__/KintoneAllRecordsError.test.js.map +0 -1
  79. package/esm/src/error/__tests__/KintoneRestAPIError.test.d.ts +0 -1
  80. package/esm/src/error/__tests__/KintoneRestAPIError.test.js +0 -82
  81. package/esm/src/error/__tests__/KintoneRestAPIError.test.js.map +0 -1
  82. package/esm/src/platform/__tests__/browser.test.d.ts +0 -4
  83. package/esm/src/platform/__tests__/browser.test.js +0 -109
  84. package/esm/src/platform/__tests__/browser.test.js.map +0 -1
  85. package/lib/src/__tests__/KintoneRequestConfigBuilder.test.d.ts +0 -1
  86. package/lib/src/__tests__/KintoneRequestConfigBuilder.test.js +0 -787
  87. package/lib/src/__tests__/KintoneRequestConfigBuilder.test.js.map +0 -1
  88. package/lib/src/__tests__/KintoneResponseHandler.test.d.ts +0 -1
  89. package/lib/src/__tests__/KintoneResponseHandler.test.js +0 -184
  90. package/lib/src/__tests__/KintoneResponseHandler.test.js.map +0 -1
  91. package/lib/src/__tests__/KintoneRestAPIClient.test.d.ts +0 -1
  92. package/lib/src/__tests__/KintoneRestAPIClient.test.js +0 -163
  93. package/lib/src/__tests__/KintoneRestAPIClient.test.js.map +0 -1
  94. package/lib/src/__tests__/index.browser.test.d.ts +0 -1
  95. package/lib/src/__tests__/index.browser.test.js +0 -40
  96. package/lib/src/__tests__/index.browser.test.js.map +0 -1
  97. package/lib/src/__tests__/index.test.d.ts +0 -1
  98. package/lib/src/__tests__/index.test.js +0 -40
  99. package/lib/src/__tests__/index.test.js.map +0 -1
  100. package/lib/src/__tests__/setup.d.ts +0 -1
  101. package/lib/src/__tests__/setup.js +0 -31
  102. package/lib/src/__tests__/setup.js.map +0 -1
  103. package/lib/src/__tests__/url.test.d.ts +0 -1
  104. package/lib/src/__tests__/url.test.js +0 -13
  105. package/lib/src/__tests__/url.test.js.map +0 -1
  106. package/lib/src/client/__tests__/AppClient.test.d.ts +0 -1
  107. package/lib/src/client/__tests__/AppClient.test.js +0 -1620
  108. package/lib/src/client/__tests__/AppClient.test.js.map +0 -1
  109. package/lib/src/client/__tests__/BulkRequestClient.test.d.ts +0 -1
  110. package/lib/src/client/__tests__/BulkRequestClient.test.js +0 -237
  111. package/lib/src/client/__tests__/BulkRequestClient.test.js.map +0 -1
  112. package/lib/src/client/__tests__/File.test.d.ts +0 -1
  113. package/lib/src/client/__tests__/File.test.js +0 -236
  114. package/lib/src/client/__tests__/File.test.js.map +0 -1
  115. package/lib/src/client/__tests__/RecordClient.test.d.ts +0 -1
  116. package/lib/src/client/__tests__/RecordClient.test.js +0 -1749
  117. package/lib/src/client/__tests__/RecordClient.test.js.map +0 -1
  118. package/lib/src/error/__tests__/KintoneAbortSearchError.test.d.ts +0 -1
  119. package/lib/src/error/__tests__/KintoneAbortSearchError.test.js +0 -11
  120. package/lib/src/error/__tests__/KintoneAbortSearchError.test.js.map +0 -1
  121. package/lib/src/error/__tests__/KintoneAllRecordsError.test.d.ts +0 -1
  122. package/lib/src/error/__tests__/KintoneAllRecordsError.test.js +0 -154
  123. package/lib/src/error/__tests__/KintoneAllRecordsError.test.js.map +0 -1
  124. package/lib/src/error/__tests__/KintoneRestAPIError.test.d.ts +0 -1
  125. package/lib/src/error/__tests__/KintoneRestAPIError.test.js +0 -84
  126. package/lib/src/error/__tests__/KintoneRestAPIError.test.js.map +0 -1
  127. package/lib/src/platform/__tests__/browser.test.d.ts +0 -4
  128. package/lib/src/platform/__tests__/browser.test.js +0 -111
  129. package/lib/src/platform/__tests__/browser.test.js.map +0 -1
  130. package/lib/tsconfig.tsbuildinfo +0 -1
@@ -1,1747 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- };
59
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
61
- if (ar || !(i in from)) {
62
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
63
- ar[i] = from[i];
64
- }
65
- }
66
- return to.concat(ar || Array.prototype.slice.call(from));
67
- };
68
- import { RecordClient } from "../RecordClient";
69
- import { BulkRequestClient } from "../BulkRequestClient";
70
- import { buildMockClient } from "../../http/MockClient";
71
- import { KintoneAllRecordsError } from "../../error/KintoneAllRecordsError";
72
- import { KintoneRestAPIError } from "../../error/KintoneRestAPIError";
73
- import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder";
74
- describe("RecordClient", function () {
75
- var _a;
76
- var mockClient;
77
- var recordClient;
78
- var APP_ID = 1;
79
- var RECORD_ID = 2;
80
- var fieldCode = "Customer";
81
- var record = (_a = {},
82
- _a[fieldCode] = {
83
- value: "ABC Corporation",
84
- },
85
- _a);
86
- beforeEach(function () {
87
- var requestConfigBuilder = new KintoneRequestConfigBuilder({
88
- baseUrl: "https://example.cybozu.com",
89
- auth: { type: "apiToken", apiToken: "foo" },
90
- });
91
- mockClient = buildMockClient(requestConfigBuilder);
92
- var bulkRequestClient = new BulkRequestClient(mockClient);
93
- recordClient = new RecordClient(mockClient, bulkRequestClient);
94
- });
95
- describe("getRecord", function () {
96
- var params = { app: APP_ID, id: RECORD_ID };
97
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0: return [4 /*yield*/, recordClient.getRecord(params)];
101
- case 1:
102
- _a.sent();
103
- return [2 /*return*/];
104
- }
105
- });
106
- }); });
107
- it("should pass the path to the http client", function () {
108
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record.json");
109
- });
110
- it("should send a get request", function () {
111
- expect(mockClient.getLogs()[0].method).toBe("get");
112
- });
113
- it("should pass app and id to the http client", function () {
114
- expect(mockClient.getLogs()[0].params).toEqual(params);
115
- });
116
- });
117
- describe("addRecord", function () {
118
- var params = { app: APP_ID, record: record };
119
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0: return [4 /*yield*/, recordClient.addRecord(params)];
123
- case 1:
124
- _a.sent();
125
- return [2 /*return*/];
126
- }
127
- });
128
- }); });
129
- it("should pass the path to the http client", function () {
130
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record.json");
131
- });
132
- it("should send a post request", function () {
133
- expect(mockClient.getLogs()[0].method).toBe("post");
134
- });
135
- it("should pass app and record object to the http client", function () {
136
- expect(mockClient.getLogs()[0].params).toEqual(params);
137
- });
138
- });
139
- describe("updateRecord", function () {
140
- var params = {
141
- app: APP_ID,
142
- id: RECORD_ID,
143
- record: record,
144
- revision: 5,
145
- };
146
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
147
- return __generator(this, function (_a) {
148
- switch (_a.label) {
149
- case 0: return [4 /*yield*/, recordClient.updateRecord(params)];
150
- case 1:
151
- _a.sent();
152
- return [2 /*return*/];
153
- }
154
- });
155
- }); });
156
- it("should pass the path to the http client", function () {
157
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record.json");
158
- });
159
- it("should send a put request", function () {
160
- expect(mockClient.getLogs()[0].method).toBe("put");
161
- });
162
- it("should pass app, id, record, and revision to the http client", function () {
163
- expect(mockClient.getLogs()[0].params).toEqual(params);
164
- });
165
- });
166
- describe("upsertRecord", function () {
167
- describe("update", function () {
168
- var params = {
169
- app: APP_ID,
170
- updateKey: {
171
- field: "Code",
172
- value: "foo",
173
- },
174
- record: record,
175
- revision: 5,
176
- };
177
- var getRecordsMockFn;
178
- var updateRecordMockFn;
179
- var addRecordMockFn;
180
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
181
- var bulkRequestClient;
182
- return __generator(this, function (_a) {
183
- getRecordsMockFn = jest.fn().mockResolvedValue({
184
- records: [
185
- {
186
- $id: {
187
- type: "__ID__",
188
- value: "10",
189
- },
190
- },
191
- ],
192
- });
193
- updateRecordMockFn = jest.fn().mockResolvedValue({
194
- revision: "2",
195
- });
196
- addRecordMockFn = jest.fn();
197
- bulkRequestClient = new BulkRequestClient(mockClient);
198
- recordClient = new RecordClient(mockClient, bulkRequestClient);
199
- recordClient.getRecords = getRecordsMockFn;
200
- recordClient.updateRecord = updateRecordMockFn;
201
- recordClient.addRecord = addRecordMockFn;
202
- return [2 /*return*/];
203
- });
204
- }); });
205
- it("should call getRecords with a query built with udpateKey", function () { return __awaiter(void 0, void 0, void 0, function () {
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
209
- case 1:
210
- _a.sent();
211
- expect(getRecordsMockFn.mock.calls.length).toBe(1);
212
- expect(getRecordsMockFn.mock.calls[0][0]).toEqual({
213
- app: params.app,
214
- query: "".concat(params.updateKey.field, " = \"").concat(params.updateKey.value, "\""),
215
- });
216
- return [2 /*return*/];
217
- }
218
- });
219
- }); });
220
- it("should call updateRecord with the params", function () { return __awaiter(void 0, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
224
- case 1:
225
- _a.sent();
226
- expect(updateRecordMockFn.mock.calls.length).toBe(1);
227
- expect(updateRecordMockFn.mock.calls[0][0]).toEqual(params);
228
- return [2 /*return*/];
229
- }
230
- });
231
- }); });
232
- it("should not call addRecord", function () { return __awaiter(void 0, void 0, void 0, function () {
233
- return __generator(this, function (_a) {
234
- switch (_a.label) {
235
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
236
- case 1:
237
- _a.sent();
238
- expect(addRecordMockFn.mock.calls.length).toBe(0);
239
- return [2 /*return*/];
240
- }
241
- });
242
- }); });
243
- it("should return id and revision properties", function () { return __awaiter(void 0, void 0, void 0, function () {
244
- var result;
245
- return __generator(this, function (_a) {
246
- switch (_a.label) {
247
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
248
- case 1:
249
- result = _a.sent();
250
- expect(result).toEqual({
251
- id: "10",
252
- revision: "2",
253
- });
254
- return [2 /*return*/];
255
- }
256
- });
257
- }); });
258
- });
259
- describe("insert", function () {
260
- var params = {
261
- app: APP_ID,
262
- updateKey: {
263
- field: "Customer",
264
- value: "foo",
265
- },
266
- record: record,
267
- revision: 5,
268
- };
269
- var getRecordsMockFn;
270
- var updateRecordMockFn;
271
- var addRecordMockFn;
272
- beforeEach(function () {
273
- getRecordsMockFn = jest.fn().mockResolvedValue({
274
- records: [],
275
- });
276
- updateRecordMockFn = jest.fn();
277
- addRecordMockFn = jest.fn().mockResolvedValue({
278
- id: "10",
279
- revision: "1",
280
- });
281
- var bulkRequestClient = new BulkRequestClient(mockClient);
282
- recordClient = new RecordClient(mockClient, bulkRequestClient);
283
- recordClient.getRecords = getRecordsMockFn;
284
- recordClient.updateRecord = updateRecordMockFn;
285
- recordClient.addRecord = addRecordMockFn;
286
- });
287
- it("should call getRecords with a query built with udpateKey", function () { return __awaiter(void 0, void 0, void 0, function () {
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
291
- case 1:
292
- _a.sent();
293
- expect(getRecordsMockFn.mock.calls.length).toBe(1);
294
- expect(getRecordsMockFn.mock.calls[0][0]).toEqual({
295
- app: params.app,
296
- query: "".concat(params.updateKey.field, " = \"").concat(params.updateKey.value, "\""),
297
- });
298
- return [2 /*return*/];
299
- }
300
- });
301
- }); });
302
- it("should call addRecord with the params", function () { return __awaiter(void 0, void 0, void 0, function () {
303
- var _a;
304
- return __generator(this, function (_b) {
305
- switch (_b.label) {
306
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
307
- case 1:
308
- _b.sent();
309
- expect(addRecordMockFn.mock.calls.length).toBe(1);
310
- expect(addRecordMockFn.mock.calls[0][0]).toEqual({
311
- app: params.app,
312
- record: __assign(__assign({}, params.record), (_a = {}, _a[params.updateKey.field] = { value: params.updateKey.value }, _a)),
313
- });
314
- return [2 /*return*/];
315
- }
316
- });
317
- }); });
318
- it("should not call updateRecord", function () { return __awaiter(void 0, void 0, void 0, function () {
319
- return __generator(this, function (_a) {
320
- switch (_a.label) {
321
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
322
- case 1:
323
- _a.sent();
324
- expect(updateRecordMockFn.mock.calls.length).toBe(0);
325
- return [2 /*return*/];
326
- }
327
- });
328
- }); });
329
- it("should return id and revision properties", function () { return __awaiter(void 0, void 0, void 0, function () {
330
- var result;
331
- return __generator(this, function (_a) {
332
- switch (_a.label) {
333
- case 0: return [4 /*yield*/, recordClient.upsertRecord(params)];
334
- case 1:
335
- result = _a.sent();
336
- expect(result).toEqual({
337
- id: "10",
338
- revision: "1",
339
- });
340
- return [2 /*return*/];
341
- }
342
- });
343
- }); });
344
- });
345
- });
346
- describe("getRecords", function () {
347
- describe("without offset", function () {
348
- var params = {
349
- app: APP_ID,
350
- fields: [fieldCode],
351
- query: "".concat(fieldCode, " = \"foo\""),
352
- totalCount: true,
353
- };
354
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
355
- return __generator(this, function (_a) {
356
- switch (_a.label) {
357
- case 0: return [4 /*yield*/, recordClient.getRecords(params)];
358
- case 1:
359
- _a.sent();
360
- return [2 /*return*/];
361
- }
362
- });
363
- }); });
364
- it("should pass the path to the http client", function () {
365
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records.json");
366
- });
367
- it("should send a get request", function () {
368
- expect(mockClient.getLogs()[0].method).toBe("get");
369
- });
370
- it("should pass app, fields, query and totalCount to the http client", function () {
371
- expect(mockClient.getLogs()[0].params).toEqual(params);
372
- });
373
- });
374
- describe("with offset", function () {
375
- var consoleWarnMock;
376
- beforeEach(function () {
377
- consoleWarnMock = jest.spyOn(console, "warn");
378
- consoleWarnMock.mockImplementation(function (x) { return x; });
379
- });
380
- describe("offset <= 10000", function () {
381
- var params = {
382
- app: APP_ID,
383
- fields: [fieldCode],
384
- query: "".concat(fieldCode, " = \"foo\" offset 10000"),
385
- totalCount: true,
386
- };
387
- it("doesn't output any message to the console", function () { return __awaiter(void 0, void 0, void 0, function () {
388
- return __generator(this, function (_a) {
389
- switch (_a.label) {
390
- case 0: return [4 /*yield*/, recordClient.getRecords(params)];
391
- case 1:
392
- _a.sent();
393
- expect(consoleWarnMock.mock.calls.length).toBe(0);
394
- return [2 /*return*/];
395
- }
396
- });
397
- }); });
398
- });
399
- describe("offset > 10000", function () {
400
- var params = {
401
- app: APP_ID,
402
- fields: [fieldCode],
403
- query: "".concat(fieldCode, " = \"foo\" offset 10001"),
404
- totalCount: true,
405
- };
406
- it("outputs a message to the console only once when the request succeeds", function () { return __awaiter(void 0, void 0, void 0, function () {
407
- return __generator(this, function (_a) {
408
- switch (_a.label) {
409
- case 0: return [4 /*yield*/, recordClient.getRecords(params)];
410
- case 1:
411
- _a.sent();
412
- return [4 /*yield*/, recordClient.getRecords(params)];
413
- case 2:
414
- _a.sent();
415
- expect(consoleWarnMock.mock.calls.length).toBe(1);
416
- return [2 /*return*/];
417
- }
418
- });
419
- }); });
420
- it("doesn't output any message to the console when the request fails", function () { return __awaiter(void 0, void 0, void 0, function () {
421
- var _a;
422
- return __generator(this, function (_b) {
423
- switch (_b.label) {
424
- case 0:
425
- expect.assertions(1);
426
- mockClient.mockResponse(new Error("failed"));
427
- _b.label = 1;
428
- case 1:
429
- _b.trys.push([1, 3, , 4]);
430
- return [4 /*yield*/, recordClient.getRecords(params)];
431
- case 2:
432
- _b.sent();
433
- return [3 /*break*/, 4];
434
- case 3:
435
- _a = _b.sent();
436
- expect(consoleWarnMock.mock.calls.length).toBe(0);
437
- return [3 /*break*/, 4];
438
- case 4: return [2 /*return*/];
439
- }
440
- });
441
- }); });
442
- });
443
- afterEach(function () {
444
- consoleWarnMock.mockReset();
445
- consoleWarnMock.mockRestore();
446
- });
447
- });
448
- });
449
- describe("addRecords", function () {
450
- var params = { app: APP_ID, records: [record] };
451
- var mockResponse = {
452
- ids: ["10", "20", "30"],
453
- revisions: ["1", "2", "3"],
454
- };
455
- var response;
456
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
457
- return __generator(this, function (_a) {
458
- switch (_a.label) {
459
- case 0:
460
- mockClient.mockResponse(mockResponse);
461
- return [4 /*yield*/, recordClient.addRecords(params)];
462
- case 1:
463
- response = _a.sent();
464
- return [2 /*return*/];
465
- }
466
- });
467
- }); });
468
- it("should pass the path to the http client", function () {
469
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records.json");
470
- });
471
- it("should send a post request", function () {
472
- expect(mockClient.getLogs()[0].method).toBe("post");
473
- });
474
- it("should pass app and records to the http client", function () {
475
- expect(mockClient.getLogs()[0].params).toEqual(params);
476
- });
477
- it("should return a response having ids, revisions, and records", function () {
478
- expect(response).toEqual(__assign(__assign({}, mockResponse), { records: [
479
- { id: "10", revision: "1" },
480
- { id: "20", revision: "2" },
481
- { id: "30", revision: "3" },
482
- ] }));
483
- });
484
- });
485
- describe("updateRecords", function () {
486
- var params = {
487
- app: APP_ID,
488
- records: [{ id: RECORD_ID, record: record, revision: 5 }],
489
- };
490
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
491
- return __generator(this, function (_a) {
492
- switch (_a.label) {
493
- case 0: return [4 /*yield*/, recordClient.updateRecords(params)];
494
- case 1:
495
- _a.sent();
496
- return [2 /*return*/];
497
- }
498
- });
499
- }); });
500
- it("should pass the path to the http client", function () {
501
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records.json");
502
- });
503
- it("should send a put request", function () {
504
- expect(mockClient.getLogs()[0].method).toBe("put");
505
- });
506
- it("should pass app, id, record, and revision to the http client", function () {
507
- expect(mockClient.getLogs()[0].params).toEqual(params);
508
- });
509
- });
510
- describe("deleteRecords", function () {
511
- var ids = [10, 20, 30];
512
- var revisions = [1, 2, 3];
513
- var params = {
514
- app: APP_ID,
515
- ids: ids,
516
- revisions: revisions,
517
- };
518
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
519
- return __generator(this, function (_a) {
520
- switch (_a.label) {
521
- case 0: return [4 /*yield*/, recordClient.deleteRecords(params)];
522
- case 1:
523
- _a.sent();
524
- return [2 /*return*/];
525
- }
526
- });
527
- }); });
528
- it("should pass the path to the http client", function () {
529
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records.json");
530
- });
531
- it("should send a delete request", function () {
532
- expect(mockClient.getLogs()[0].method).toBe("delete");
533
- });
534
- it("should pass app, ids, and revisions to the http client", function () {
535
- expect(mockClient.getLogs()[0].params).toEqual(params);
536
- });
537
- });
538
- describe("createCursor", function () {
539
- var params = {
540
- app: APP_ID,
541
- fields: [fieldCode],
542
- query: "".concat(fieldCode, " = \"foo\""),
543
- size: 10,
544
- };
545
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
546
- return __generator(this, function (_a) {
547
- switch (_a.label) {
548
- case 0: return [4 /*yield*/, recordClient.createCursor(params)];
549
- case 1:
550
- _a.sent();
551
- return [2 /*return*/];
552
- }
553
- });
554
- }); });
555
- it("should pass the path to the http client", function () {
556
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records/cursor.json");
557
- });
558
- it("should send a post request", function () {
559
- expect(mockClient.getLogs()[0].method).toBe("post");
560
- });
561
- it("should pass app, fields, query, and size to the http client", function () {
562
- expect(mockClient.getLogs()[0].params).toEqual(params);
563
- });
564
- });
565
- describe("getRecordsByCursor", function () {
566
- var params = {
567
- id: "cursor id",
568
- };
569
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
570
- return __generator(this, function (_a) {
571
- switch (_a.label) {
572
- case 0: return [4 /*yield*/, recordClient.getRecordsByCursor(params)];
573
- case 1:
574
- _a.sent();
575
- return [2 /*return*/];
576
- }
577
- });
578
- }); });
579
- it("should pass the path to the http client", function () {
580
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records/cursor.json");
581
- });
582
- it("should send a get request", function () {
583
- expect(mockClient.getLogs()[0].method).toBe("get");
584
- });
585
- it("should pass id to the http client", function () {
586
- expect(mockClient.getLogs()[0].params).toEqual(params);
587
- });
588
- });
589
- describe("deleteCursor", function () {
590
- var params = {
591
- id: "cursor id",
592
- };
593
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
594
- return __generator(this, function (_a) {
595
- switch (_a.label) {
596
- case 0: return [4 /*yield*/, recordClient.deleteCursor(params)];
597
- case 1:
598
- _a.sent();
599
- return [2 /*return*/];
600
- }
601
- });
602
- }); });
603
- it("should pass the path to the http client", function () {
604
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records/cursor.json");
605
- });
606
- it("should send a delete request", function () {
607
- expect(mockClient.getLogs()[0].method).toBe("delete");
608
- });
609
- it("should pass id to the http client", function () {
610
- expect(mockClient.getLogs()[0].params).toEqual(params);
611
- });
612
- });
613
- describe("getAllRecordsWithId", function () {
614
- describe("success with condition", function () {
615
- it("should do nothing if `fields` is not specified", function () { return __awaiter(void 0, void 0, void 0, function () {
616
- var params;
617
- return __generator(this, function (_a) {
618
- switch (_a.label) {
619
- case 0:
620
- params = {
621
- app: APP_ID,
622
- condition: "".concat(fieldCode, " = \"foo\""),
623
- };
624
- mockClient.mockResponse({ records: [] });
625
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
626
- case 1:
627
- _a.sent();
628
- expect(mockClient.getLogs()[0].params.fields).toBe(undefined);
629
- return [2 /*return*/];
630
- }
631
- });
632
- }); });
633
- it("should do nothing if `fields` is empty", function () { return __awaiter(void 0, void 0, void 0, function () {
634
- var params;
635
- return __generator(this, function (_a) {
636
- switch (_a.label) {
637
- case 0:
638
- params = {
639
- app: APP_ID,
640
- fields: [],
641
- condition: "".concat(fieldCode, " = \"foo\""),
642
- };
643
- mockClient.mockResponse({ records: [] });
644
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
645
- case 1:
646
- _a.sent();
647
- expect(mockClient.getLogs()[0].params.fields).toEqual([]);
648
- return [2 /*return*/];
649
- }
650
- });
651
- }); });
652
- it("should append `$id` if `fields` is specified and doesn't contain `$id`", function () { return __awaiter(void 0, void 0, void 0, function () {
653
- var params;
654
- return __generator(this, function (_a) {
655
- switch (_a.label) {
656
- case 0:
657
- params = {
658
- app: APP_ID,
659
- fields: [fieldCode],
660
- condition: "".concat(fieldCode, " = \"foo\""),
661
- };
662
- mockClient.mockResponse({ records: [] });
663
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
664
- case 1:
665
- _a.sent();
666
- expect(mockClient.getLogs()[0].params.fields.sort()).toEqual(__spreadArray(__spreadArray([], params.fields, true), ["$id"], false).sort());
667
- return [2 /*return*/];
668
- }
669
- });
670
- }); });
671
- it("should do nothing if `fields` is specified and contains `$id`", function () { return __awaiter(void 0, void 0, void 0, function () {
672
- var params;
673
- return __generator(this, function (_a) {
674
- switch (_a.label) {
675
- case 0:
676
- params = {
677
- app: APP_ID,
678
- fields: ["$id", fieldCode],
679
- condition: "".concat(fieldCode, " = \"foo\""),
680
- };
681
- mockClient.mockResponse({ records: [] });
682
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
683
- case 1:
684
- _a.sent();
685
- expect(mockClient.getLogs()[0].params.fields).toEqual(params.fields);
686
- return [2 /*return*/];
687
- }
688
- });
689
- }); });
690
- });
691
- describe("success with condition", function () {
692
- var params = {
693
- app: APP_ID,
694
- fields: ["$id"],
695
- condition: "".concat(fieldCode, " = \"foo\""),
696
- };
697
- var result;
698
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
699
- var records, i;
700
- return __generator(this, function (_a) {
701
- switch (_a.label) {
702
- case 0:
703
- records = [];
704
- for (i = 1; i <= 500; i++) {
705
- records.push({
706
- $id: {
707
- type: "__ID__",
708
- value: i.toString(),
709
- },
710
- });
711
- }
712
- mockClient.mockResponse({ records: records });
713
- mockClient.mockResponse({
714
- records: [{ $id: { type: "__ID__", value: "501" } }],
715
- });
716
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
717
- case 1:
718
- result = _a.sent();
719
- return [2 /*return*/];
720
- }
721
- });
722
- }); });
723
- it("should return all records", function () {
724
- expect(mockClient.getLogs()[0]).toEqual({
725
- path: "/k/v1/records.json",
726
- method: "get",
727
- params: {
728
- app: params.app,
729
- fields: params.fields,
730
- query: "(".concat(params.condition, ") and $id > 0 order by $id asc limit 500"),
731
- },
732
- });
733
- expect(mockClient.getLogs()[1]).toEqual({
734
- path: "/k/v1/records.json",
735
- method: "get",
736
- params: {
737
- app: params.app,
738
- fields: params.fields,
739
- query: "(".concat(params.condition, ") and $id > 500 order by $id asc limit 500"),
740
- },
741
- });
742
- expect(result.length).toBe(501);
743
- expect(result[500]).toStrictEqual({
744
- $id: { type: "__ID__", value: "501" },
745
- });
746
- });
747
- });
748
- describe("success without condition", function () {
749
- var params = {
750
- app: APP_ID,
751
- fields: ["$id"],
752
- };
753
- var result;
754
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
755
- var records, i;
756
- return __generator(this, function (_a) {
757
- switch (_a.label) {
758
- case 0:
759
- records = [];
760
- for (i = 1; i <= 500; i++) {
761
- records.push({
762
- $id: {
763
- type: "__ID__",
764
- value: i.toString(),
765
- },
766
- });
767
- }
768
- mockClient.mockResponse({ records: records });
769
- mockClient.mockResponse({
770
- records: [{ $id: { type: "__ID__", value: "501" } }],
771
- });
772
- return [4 /*yield*/, recordClient.getAllRecordsWithId(params)];
773
- case 1:
774
- result = _a.sent();
775
- return [2 /*return*/];
776
- }
777
- });
778
- }); });
779
- it("should return all records", function () {
780
- expect(mockClient.getLogs()[0]).toEqual({
781
- path: "/k/v1/records.json",
782
- method: "get",
783
- params: {
784
- app: params.app,
785
- fields: params.fields,
786
- query: "$id > 0 order by $id asc limit 500",
787
- },
788
- });
789
- expect(mockClient.getLogs()[1]).toEqual({
790
- path: "/k/v1/records.json",
791
- method: "get",
792
- params: {
793
- app: params.app,
794
- fields: params.fields,
795
- query: "$id > 500 order by $id asc limit 500",
796
- },
797
- });
798
- expect(result.length).toBe(501);
799
- expect(result[500]).toStrictEqual({
800
- $id: { type: "__ID__", value: "501" },
801
- });
802
- });
803
- });
804
- });
805
- describe("getAllRecordsWithOffset", function () {
806
- describe("condition and orderBy parameters", function () {
807
- it("with condition and orderBy", function () { return __awaiter(void 0, void 0, void 0, function () {
808
- var params;
809
- return __generator(this, function (_a) {
810
- switch (_a.label) {
811
- case 0:
812
- params = {
813
- app: APP_ID,
814
- condition: "".concat(fieldCode, " = \"foo\""),
815
- orderBy: "".concat(fieldCode, " asc"),
816
- };
817
- mockClient.mockResponse({ records: [] });
818
- return [4 /*yield*/, recordClient.getAllRecordsWithOffset(params)];
819
- case 1:
820
- _a.sent();
821
- expect(mockClient.getLogs()[0].params.query).toBe("".concat(fieldCode, " = \"foo\" order by ").concat(fieldCode, " asc limit 500 offset 0"));
822
- return [2 /*return*/];
823
- }
824
- });
825
- }); });
826
- it("with condition, without orderBy", function () { return __awaiter(void 0, void 0, void 0, function () {
827
- var params;
828
- return __generator(this, function (_a) {
829
- switch (_a.label) {
830
- case 0:
831
- params = {
832
- app: APP_ID,
833
- condition: "".concat(fieldCode, " = \"foo\""),
834
- };
835
- mockClient.mockResponse({ records: [] });
836
- return [4 /*yield*/, recordClient.getAllRecordsWithOffset(params)];
837
- case 1:
838
- _a.sent();
839
- expect(mockClient.getLogs()[0].params.query).toBe("".concat(fieldCode, " = \"foo\" limit 500 offset 0"));
840
- return [2 /*return*/];
841
- }
842
- });
843
- }); });
844
- it("without condition, with orderBy", function () { return __awaiter(void 0, void 0, void 0, function () {
845
- var params;
846
- return __generator(this, function (_a) {
847
- switch (_a.label) {
848
- case 0:
849
- params = {
850
- app: APP_ID,
851
- orderBy: "".concat(fieldCode, " asc"),
852
- };
853
- mockClient.mockResponse({ records: [] });
854
- return [4 /*yield*/, recordClient.getAllRecordsWithOffset(params)];
855
- case 1:
856
- _a.sent();
857
- expect(mockClient.getLogs()[0].params.query).toBe("order by ".concat(fieldCode, " asc limit 500 offset 0"));
858
- return [2 /*return*/];
859
- }
860
- });
861
- }); });
862
- it("neither condition nor orderBy", function () { return __awaiter(void 0, void 0, void 0, function () {
863
- var params;
864
- return __generator(this, function (_a) {
865
- switch (_a.label) {
866
- case 0:
867
- params = {
868
- app: APP_ID,
869
- };
870
- mockClient.mockResponse({ records: [] });
871
- return [4 /*yield*/, recordClient.getAllRecordsWithOffset(params)];
872
- case 1:
873
- _a.sent();
874
- expect(mockClient.getLogs()[0].params.query).toBe("limit 500 offset 0");
875
- return [2 /*return*/];
876
- }
877
- });
878
- }); });
879
- });
880
- describe("success", function () {
881
- var params = {
882
- app: APP_ID,
883
- fields: ["$id"],
884
- condition: "".concat(fieldCode, " = \"foo\""),
885
- };
886
- var result;
887
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
888
- var records, i;
889
- return __generator(this, function (_a) {
890
- switch (_a.label) {
891
- case 0:
892
- records = [];
893
- for (i = 1; i <= 500; i++) {
894
- records.push({
895
- $id: {
896
- type: "__ID__",
897
- value: i.toString(),
898
- },
899
- });
900
- }
901
- mockClient.mockResponse({ records: records });
902
- mockClient.mockResponse({
903
- records: [{ $id: { type: "__ID__", value: "501" } }],
904
- });
905
- return [4 /*yield*/, recordClient.getAllRecordsWithOffset(params)];
906
- case 1:
907
- result = _a.sent();
908
- return [2 /*return*/];
909
- }
910
- });
911
- }); });
912
- it("should return all records", function () {
913
- expect(mockClient.getLogs()[0]).toEqual({
914
- path: "/k/v1/records.json",
915
- method: "get",
916
- params: {
917
- app: params.app,
918
- fields: params.fields,
919
- query: "".concat(params.condition, " limit 500 offset 0"),
920
- },
921
- });
922
- expect(mockClient.getLogs()[1]).toEqual({
923
- path: "/k/v1/records.json",
924
- method: "get",
925
- params: {
926
- app: params.app,
927
- fields: params.fields,
928
- query: "".concat(params.condition, " limit 500 offset 500"),
929
- },
930
- });
931
- expect(result.length).toBe(501);
932
- expect(result[500]).toStrictEqual({
933
- $id: { type: "__ID__", value: "501" },
934
- });
935
- });
936
- });
937
- });
938
- describe("getAllRecords", function () {
939
- describe("`orderBy` is specified", function () {
940
- var params = {
941
- app: APP_ID,
942
- condition: "".concat(fieldCode, " = \"foo\""),
943
- orderBy: "".concat(fieldCode, " asc"),
944
- };
945
- var withCursorMockFn;
946
- var withOffsetMockFn;
947
- beforeEach(function () {
948
- withCursorMockFn = jest.fn();
949
- withOffsetMockFn = jest.fn();
950
- recordClient.getAllRecordsWithCursor = withCursorMockFn;
951
- recordClient.getAllRecordsWithOffset = withOffsetMockFn;
952
- });
953
- it("should call `getAllRecordsWithCursor` if `withCursor` is not specified", function () { return __awaiter(void 0, void 0, void 0, function () {
954
- return __generator(this, function (_a) {
955
- switch (_a.label) {
956
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign({}, params))];
957
- case 1:
958
- _a.sent();
959
- expect(withCursorMockFn.mock.calls.length).toBe(1);
960
- expect(withCursorMockFn.mock.calls[0][0]).toStrictEqual({
961
- app: params.app,
962
- query: "".concat(params.condition, " order by ").concat(params.orderBy),
963
- });
964
- return [2 /*return*/];
965
- }
966
- });
967
- }); });
968
- it("should call `getAllRecordsWithCursor` if `withCursor` is true", function () { return __awaiter(void 0, void 0, void 0, function () {
969
- return __generator(this, function (_a) {
970
- switch (_a.label) {
971
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: true }))];
972
- case 1:
973
- _a.sent();
974
- expect(withCursorMockFn.mock.calls.length).toBe(1);
975
- expect(withCursorMockFn.mock.calls[0][0]).toStrictEqual({
976
- app: params.app,
977
- query: "".concat(params.condition, " order by ").concat(params.orderBy),
978
- });
979
- return [2 /*return*/];
980
- }
981
- });
982
- }); });
983
- it("should call `getAllRecordsWithOffset` if `withCursor` is false", function () { return __awaiter(void 0, void 0, void 0, function () {
984
- return __generator(this, function (_a) {
985
- switch (_a.label) {
986
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: false }))];
987
- case 1:
988
- _a.sent();
989
- expect(withOffsetMockFn.mock.calls.length).toBe(1);
990
- expect(withOffsetMockFn.mock.calls[0][0]).toStrictEqual(params);
991
- return [2 /*return*/];
992
- }
993
- });
994
- }); });
995
- });
996
- describe("`orderBy` is an empty string", function () {
997
- var params = {
998
- app: APP_ID,
999
- condition: "".concat(fieldCode, " = \"foo\""),
1000
- orderBy: "",
1001
- };
1002
- var orderBy = params.orderBy, expected = __rest(params, ["orderBy"]);
1003
- var mockFn;
1004
- beforeEach(function () {
1005
- mockFn = jest.fn();
1006
- recordClient.getAllRecordsWithId = mockFn;
1007
- });
1008
- it("should call `getAllRecordsWithId` if `withCursor` is not specified", function () { return __awaiter(void 0, void 0, void 0, function () {
1009
- return __generator(this, function (_a) {
1010
- switch (_a.label) {
1011
- case 0: return [4 /*yield*/, recordClient.getAllRecords(params)];
1012
- case 1:
1013
- _a.sent();
1014
- expect(mockFn.mock.calls.length).toBe(1);
1015
- expect(mockFn.mock.calls[0][0]).toStrictEqual(expected);
1016
- return [2 /*return*/];
1017
- }
1018
- });
1019
- }); });
1020
- it("should call `getAllRecordsWithId` if `withCursor` is true", function () { return __awaiter(void 0, void 0, void 0, function () {
1021
- return __generator(this, function (_a) {
1022
- switch (_a.label) {
1023
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: true }))];
1024
- case 1:
1025
- _a.sent();
1026
- expect(mockFn.mock.calls.length).toBe(1);
1027
- expect(mockFn.mock.calls[0][0]).toStrictEqual(expected);
1028
- return [2 /*return*/];
1029
- }
1030
- });
1031
- }); });
1032
- it("should call `getAllRecordsWithId` if `withCursor` is false", function () { return __awaiter(void 0, void 0, void 0, function () {
1033
- return __generator(this, function (_a) {
1034
- switch (_a.label) {
1035
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: false }))];
1036
- case 1:
1037
- _a.sent();
1038
- expect(mockFn.mock.calls.length).toBe(1);
1039
- expect(mockFn.mock.calls[0][0]).toStrictEqual(expected);
1040
- return [2 /*return*/];
1041
- }
1042
- });
1043
- }); });
1044
- });
1045
- describe("`orderBy` is not specified", function () {
1046
- var params = {
1047
- app: APP_ID,
1048
- condition: "".concat(fieldCode, " = \"foo\""),
1049
- };
1050
- var mockFn;
1051
- beforeEach(function () {
1052
- mockFn = jest.fn();
1053
- recordClient.getAllRecordsWithId = mockFn;
1054
- });
1055
- it("should call `getAllRecordsWithId` if `withCursor` is not specified", function () { return __awaiter(void 0, void 0, void 0, function () {
1056
- return __generator(this, function (_a) {
1057
- switch (_a.label) {
1058
- case 0: return [4 /*yield*/, recordClient.getAllRecords(params)];
1059
- case 1:
1060
- _a.sent();
1061
- expect(mockFn.mock.calls.length).toBe(1);
1062
- expect(mockFn.mock.calls[0][0]).toStrictEqual(params);
1063
- return [2 /*return*/];
1064
- }
1065
- });
1066
- }); });
1067
- it("should call `getAllRecordsWithId` if `withCursor` is true", function () { return __awaiter(void 0, void 0, void 0, function () {
1068
- return __generator(this, function (_a) {
1069
- switch (_a.label) {
1070
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: true }))];
1071
- case 1:
1072
- _a.sent();
1073
- expect(mockFn.mock.calls.length).toBe(1);
1074
- expect(mockFn.mock.calls[0][0]).toStrictEqual(params);
1075
- return [2 /*return*/];
1076
- }
1077
- });
1078
- }); });
1079
- it("should call `getAllRecordsWithId` if `withCursor` is false", function () { return __awaiter(void 0, void 0, void 0, function () {
1080
- return __generator(this, function (_a) {
1081
- switch (_a.label) {
1082
- case 0: return [4 /*yield*/, recordClient.getAllRecords(__assign(__assign({}, params), { withCursor: false }))];
1083
- case 1:
1084
- _a.sent();
1085
- expect(mockFn.mock.calls.length).toBe(1);
1086
- expect(mockFn.mock.calls[0][0]).toStrictEqual(params);
1087
- return [2 /*return*/];
1088
- }
1089
- });
1090
- }); });
1091
- });
1092
- });
1093
- describe("getAllRecordsWithCursor", function () {
1094
- var params = {
1095
- app: APP_ID,
1096
- fields: [fieldCode],
1097
- query: "".concat(fieldCode, " = \"foo\""),
1098
- };
1099
- var CURSOR_ID = "1";
1100
- var result;
1101
- describe("success", function () {
1102
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1103
- return __generator(this, function (_a) {
1104
- switch (_a.label) {
1105
- case 0:
1106
- // response from createCursor
1107
- mockClient.mockResponse({ id: CURSOR_ID, totalCount: "4" });
1108
- // response from getRecordsByCursor
1109
- mockClient.mockResponse({
1110
- records: [
1111
- { $id: { type: "__ID__", value: "1" } },
1112
- { $id: { type: "__ID__", value: "2" } },
1113
- ],
1114
- next: true,
1115
- });
1116
- mockClient.mockResponse({
1117
- records: [
1118
- { $id: { type: "__ID__", value: "3" } },
1119
- { $id: { type: "__ID__", value: "4" } },
1120
- ],
1121
- next: false,
1122
- });
1123
- return [4 /*yield*/, recordClient.getAllRecordsWithCursor(params)];
1124
- case 1:
1125
- result = _a.sent();
1126
- return [2 /*return*/];
1127
- }
1128
- });
1129
- }); });
1130
- it("should create a cursor", function () {
1131
- expect(mockClient.getLogs()[0]).toEqual({
1132
- path: "/k/v1/records/cursor.json",
1133
- method: "post",
1134
- params: params,
1135
- });
1136
- });
1137
- it("should return all records", function () {
1138
- expect(mockClient.getLogs()[1]).toEqual({
1139
- path: "/k/v1/records/cursor.json",
1140
- method: "get",
1141
- params: { id: CURSOR_ID },
1142
- });
1143
- expect(mockClient.getLogs()[2]).toEqual({
1144
- path: "/k/v1/records/cursor.json",
1145
- method: "get",
1146
- params: { id: CURSOR_ID },
1147
- });
1148
- expect(result).toStrictEqual([
1149
- { $id: { type: "__ID__", value: "1" } },
1150
- { $id: { type: "__ID__", value: "2" } },
1151
- { $id: { type: "__ID__", value: "3" } },
1152
- { $id: { type: "__ID__", value: "4" } },
1153
- ]);
1154
- });
1155
- it("should not call deleteCursor", function () {
1156
- expect(mockClient.getLogs().length).toEqual(3);
1157
- });
1158
- });
1159
- describe("failure", function () {
1160
- beforeEach(function () {
1161
- // response from createCursor
1162
- mockClient.mockResponse({ id: CURSOR_ID, totalCount: "4" });
1163
- // response from getRecordsByCursor
1164
- mockClient.mockResponse({
1165
- records: [{ id: 1 }, { id: 2 }],
1166
- next: true,
1167
- });
1168
- mockClient.mockResponse(new Error("failed"));
1169
- });
1170
- it("should raise error", function () { return __awaiter(void 0, void 0, void 0, function () {
1171
- return __generator(this, function (_a) {
1172
- switch (_a.label) {
1173
- case 0: return [4 /*yield*/, expect(recordClient.getAllRecordsWithCursor(params)).rejects.toThrow("failed")];
1174
- case 1:
1175
- _a.sent();
1176
- expect(mockClient.getLogs()[3]).toStrictEqual({
1177
- path: "/k/v1/records/cursor.json",
1178
- method: "delete",
1179
- params: { id: CURSOR_ID },
1180
- });
1181
- return [2 /*return*/];
1182
- }
1183
- });
1184
- }); });
1185
- });
1186
- });
1187
- describe("addAllRecords", function () {
1188
- var params = {
1189
- app: APP_ID,
1190
- records: Array.from({ length: 3000 }, function (_, index) { return index + 1; }).map(function (value) {
1191
- var _a;
1192
- return (_a = {},
1193
- _a[fieldCode] = {
1194
- value: value,
1195
- },
1196
- _a);
1197
- }),
1198
- };
1199
- var response;
1200
- describe("success", function () {
1201
- var mockResponse = {
1202
- results: Array.from({ length: 20 }, function (_, index) { return index + 1; }).map(function (value) { return ({
1203
- ids: Array.from({ length: 100 }, function (_, index) { return index + 1; }),
1204
- revisions: Array.from({ length: 100 }, function () { return 1; }),
1205
- }); }),
1206
- };
1207
- var mockResponse2 = {
1208
- results: Array.from({ length: 10 }, function (_, index) { return index + 1; }).map(function (value) { return ({
1209
- ids: Array.from({ length: 100 }, function (_, index) { return index + 1; }),
1210
- revisions: Array.from({ length: 100 }, function () { return 1; }),
1211
- }); }),
1212
- };
1213
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1214
- return __generator(this, function (_a) {
1215
- switch (_a.label) {
1216
- case 0:
1217
- // response from first call of bulkRequest.send
1218
- mockClient.mockResponse(mockResponse);
1219
- // response from second call of bulkRequest.send
1220
- mockClient.mockResponse(mockResponse2);
1221
- return [4 /*yield*/, recordClient.addAllRecords(params)];
1222
- case 1:
1223
- response = _a.sent();
1224
- return [2 /*return*/];
1225
- }
1226
- });
1227
- }); });
1228
- it("should call bulkRequest multiple times", function () {
1229
- expect(mockClient.getLogs().length).toBe(2);
1230
- });
1231
- it("should return merged result of each bulkRequest's result", function () {
1232
- var accumulateResponse = function (acc, _a) {
1233
- var ids = _a.ids, revisions = _a.revisions;
1234
- return acc.concat(ids.map(function (id, index) { return ({
1235
- id: id,
1236
- revision: revisions[index],
1237
- }); }));
1238
- };
1239
- var expected = __spreadArray(__spreadArray([], mockResponse.results.reduce(accumulateResponse, []), true), mockResponse2.results.reduce(accumulateResponse, []), true);
1240
- expect(response.records).toStrictEqual(expected);
1241
- });
1242
- });
1243
- describe("parameter error", function () {
1244
- it("should raise an Error if `records` parameter is not an array", function () { return __awaiter(void 0, void 0, void 0, function () {
1245
- var invalidParams;
1246
- return __generator(this, function (_a) {
1247
- switch (_a.label) {
1248
- case 0:
1249
- invalidParams = {
1250
- app: APP_ID,
1251
- records: Array.from({ length: 3000 }, function (_, index) { return index + 1; }).map(function (value) {
1252
- var _a;
1253
- if (value === 1000) {
1254
- return value;
1255
- }
1256
- return _a = {},
1257
- _a[fieldCode] = {
1258
- value: value,
1259
- },
1260
- _a;
1261
- }),
1262
- };
1263
- return [4 /*yield*/, expect(recordClient.addAllRecords(invalidParams)).rejects.toThrow("the `records` parameter must be an array of object.")];
1264
- case 1:
1265
- _a.sent();
1266
- return [2 /*return*/];
1267
- }
1268
- });
1269
- }); });
1270
- });
1271
- describe("response error", function () {
1272
- var _a;
1273
- // success
1274
- var mockResponse = {
1275
- results: Array.from({ length: 20 }, function (_, index) { return index + 1; }).map(function (value) { return ({
1276
- ids: Array.from({ length: 100 }, function (_, index) { return index + 1; }),
1277
- revisions: Array.from({ length: 100 }, function () { return 1; }),
1278
- }); }),
1279
- };
1280
- // failed
1281
- var errorResponse = {
1282
- data: {
1283
- results: [
1284
- {},
1285
- {},
1286
- {
1287
- id: "some id",
1288
- code: "some code",
1289
- message: "some error message",
1290
- errors: (_a = {},
1291
- _a["records[5].Customer"] = {
1292
- messages: ["key is missing"],
1293
- },
1294
- _a),
1295
- },
1296
- {},
1297
- {},
1298
- {},
1299
- {},
1300
- {},
1301
- {},
1302
- {},
1303
- ],
1304
- },
1305
- status: 500,
1306
- statusText: "Internal Server Error",
1307
- headers: {
1308
- "X-Some-Header": "error",
1309
- },
1310
- };
1311
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1312
- return __generator(this, function (_a) {
1313
- mockClient.mockResponse(mockResponse);
1314
- mockClient.mockResponse(new KintoneRestAPIError(errorResponse));
1315
- return [2 /*return*/];
1316
- });
1317
- }); });
1318
- it("should raise an KintoneAllRecordsError if an error occurs during bulkRequest", function () { return __awaiter(void 0, void 0, void 0, function () {
1319
- return __generator(this, function (_a) {
1320
- switch (_a.label) {
1321
- case 0: return [4 /*yield*/, expect(recordClient.addAllRecords(params)).rejects.toBeInstanceOf(KintoneAllRecordsError)];
1322
- case 1:
1323
- _a.sent();
1324
- return [2 /*return*/];
1325
- }
1326
- });
1327
- }); });
1328
- });
1329
- });
1330
- describe("updateAllRecords", function () {
1331
- var params = {
1332
- app: APP_ID,
1333
- records: Array.from({ length: 3000 }, function (_, index) { return index + 1; }).map(function (value) {
1334
- var _a;
1335
- return ({
1336
- id: value,
1337
- record: (_a = {},
1338
- _a[fieldCode] = {
1339
- value: "".concat(fieldCode, "-").concat(value),
1340
- },
1341
- _a),
1342
- revision: 1,
1343
- });
1344
- }),
1345
- };
1346
- var response;
1347
- describe("success", function () {
1348
- var mockResponse = {
1349
- results: Array.from({ length: 20 }, function (_, index) { return index; }).map(function (value) { return ({
1350
- records: Array.from({ length: 100 }, function (_, index) {
1351
- return String(value * 100 + index + 1);
1352
- }).map(function (id) { return ({
1353
- id: id,
1354
- revision: "2",
1355
- }); }),
1356
- }); }),
1357
- };
1358
- var mockResponse2 = {
1359
- results: Array.from({ length: 10 }, function (_, index) { return index; }).map(function (value) { return ({
1360
- records: Array.from({ length: 100 }, function (_, index) {
1361
- return String(2000 + value * 100 + index + 1);
1362
- }).map(function (id) { return ({
1363
- id: id,
1364
- revision: "2",
1365
- }); }),
1366
- }); }),
1367
- };
1368
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1369
- return __generator(this, function (_a) {
1370
- switch (_a.label) {
1371
- case 0:
1372
- // response from first call of bulkRequest.send
1373
- mockClient.mockResponse(mockResponse);
1374
- // response from second call of bulkRequest.send
1375
- mockClient.mockResponse(mockResponse2);
1376
- return [4 /*yield*/, recordClient.updateAllRecords(params)];
1377
- case 1:
1378
- response = _a.sent();
1379
- return [2 /*return*/];
1380
- }
1381
- });
1382
- }); });
1383
- it("should call bulkRequest multiple times", function () {
1384
- expect(mockClient.getLogs().length).toBe(2);
1385
- });
1386
- it("should return merged result of each bulkRequest's result", function () {
1387
- var accumulateResponse = function (acc, result) {
1388
- return acc.concat(result.records);
1389
- };
1390
- var expected = __spreadArray(__spreadArray([], mockResponse.results, true), mockResponse2.results, true).reduce(accumulateResponse, []);
1391
- expect(response.records).toStrictEqual(expected);
1392
- });
1393
- });
1394
- describe("response error", function () {
1395
- var _a;
1396
- // success
1397
- var mockResponse = {
1398
- results: Array.from({ length: 20 }, function (_, index) { return index; }).map(function (value) { return ({
1399
- records: Array.from({ length: 100 }, function (_, index) {
1400
- return String(value * 100 + index + 1);
1401
- }).map(function (id) { return ({
1402
- id: id,
1403
- revision: "2",
1404
- }); }),
1405
- }); }),
1406
- };
1407
- // failed
1408
- var errorResponse = {
1409
- data: {
1410
- results: [
1411
- {},
1412
- {},
1413
- {
1414
- id: "some id",
1415
- code: "some code",
1416
- message: "some error message",
1417
- errors: (_a = {},
1418
- _a["records[5].Customer"] = {
1419
- messages: ["key is missing"],
1420
- },
1421
- _a),
1422
- },
1423
- {},
1424
- {},
1425
- {},
1426
- {},
1427
- {},
1428
- {},
1429
- {},
1430
- ],
1431
- },
1432
- status: 500,
1433
- statusText: "Internal Server Error",
1434
- headers: {
1435
- "X-Some-Header": "error",
1436
- },
1437
- };
1438
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1439
- return __generator(this, function (_a) {
1440
- mockClient.mockResponse(mockResponse);
1441
- mockClient.mockResponse(new KintoneRestAPIError(errorResponse));
1442
- return [2 /*return*/];
1443
- });
1444
- }); });
1445
- it("should raise an KintoneAllRecordsError if an error occurs during bulkRequest", function () { return __awaiter(void 0, void 0, void 0, function () {
1446
- return __generator(this, function (_a) {
1447
- switch (_a.label) {
1448
- case 0: return [4 /*yield*/, expect(recordClient.updateAllRecords(params)).rejects.toBeInstanceOf(KintoneAllRecordsError)];
1449
- case 1:
1450
- _a.sent();
1451
- return [2 /*return*/];
1452
- }
1453
- });
1454
- }); });
1455
- });
1456
- });
1457
- describe("deleteAllRecords", function () {
1458
- var params = {
1459
- app: APP_ID,
1460
- records: Array.from({ length: 3000 }, function (_, index) { return index + 1; }).map(function (value) { return ({
1461
- id: value,
1462
- revision: 1,
1463
- }); }),
1464
- };
1465
- var response;
1466
- describe("success", function () {
1467
- var mockResponse = {
1468
- results: Array.from({ length: 20 }, function () { return ({}); }),
1469
- };
1470
- var mockResponse2 = {
1471
- results: Array.from({ length: 10 }, function () { return ({}); }),
1472
- };
1473
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1474
- return __generator(this, function (_a) {
1475
- switch (_a.label) {
1476
- case 0:
1477
- // response from first call of bulkRequest.send
1478
- mockClient.mockResponse(mockResponse);
1479
- // response from second call of bulkRequest.send
1480
- mockClient.mockResponse(mockResponse2);
1481
- return [4 /*yield*/, recordClient.deleteAllRecords(params)];
1482
- case 1:
1483
- response = _a.sent();
1484
- return [2 /*return*/];
1485
- }
1486
- });
1487
- }); });
1488
- it("should call bulkRequest multiple times", function () {
1489
- expect(mockClient.getLogs().length).toBe(2);
1490
- });
1491
- it("should return an empty object", function () {
1492
- expect(response).toStrictEqual({});
1493
- });
1494
- });
1495
- describe("response error", function () {
1496
- // success
1497
- var mockResponse = {
1498
- results: Array.from({ length: 20 }, function () { return ({}); }),
1499
- };
1500
- // failed
1501
- var errorResponse = {
1502
- data: {
1503
- results: [
1504
- {},
1505
- {},
1506
- {
1507
- id: "some id",
1508
- code: "some code",
1509
- message: "some error message",
1510
- },
1511
- {},
1512
- {},
1513
- {},
1514
- {},
1515
- {},
1516
- {},
1517
- {},
1518
- ],
1519
- },
1520
- status: 500,
1521
- statusText: "Internal Server Error",
1522
- headers: {
1523
- "X-Some-Header": "error",
1524
- },
1525
- };
1526
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1527
- return __generator(this, function (_a) {
1528
- mockClient.mockResponse(mockResponse);
1529
- mockClient.mockResponse(new KintoneRestAPIError(errorResponse));
1530
- return [2 /*return*/];
1531
- });
1532
- }); });
1533
- it("should raise an KintoneAllRecordsError if an error occurs during bulkRequest", function () { return __awaiter(void 0, void 0, void 0, function () {
1534
- return __generator(this, function (_a) {
1535
- switch (_a.label) {
1536
- case 0: return [4 /*yield*/, expect(recordClient.deleteAllRecords(params)).rejects.toBeInstanceOf(KintoneAllRecordsError)];
1537
- case 1:
1538
- _a.sent();
1539
- return [2 /*return*/];
1540
- }
1541
- });
1542
- }); });
1543
- });
1544
- });
1545
- describe("addRecordComment", function () {
1546
- var params = {
1547
- app: APP_ID,
1548
- record: RECORD_ID,
1549
- comment: {
1550
- text: "hello",
1551
- mentions: [
1552
- {
1553
- code: "Administrator",
1554
- type: "USER",
1555
- },
1556
- ],
1557
- },
1558
- };
1559
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1560
- return __generator(this, function (_a) {
1561
- switch (_a.label) {
1562
- case 0: return [4 /*yield*/, recordClient.addRecordComment(params)];
1563
- case 1:
1564
- _a.sent();
1565
- return [2 /*return*/];
1566
- }
1567
- });
1568
- }); });
1569
- it("should pass the path to the http client", function () {
1570
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/comment.json");
1571
- });
1572
- it("should send a post request", function () {
1573
- expect(mockClient.getLogs()[0].method).toBe("post");
1574
- });
1575
- it("should pass app, record and comment to the http client", function () {
1576
- expect(mockClient.getLogs()[0].params).toEqual(params);
1577
- });
1578
- });
1579
- describe("deleteRecordComment", function () {
1580
- var params = {
1581
- app: APP_ID,
1582
- record: RECORD_ID,
1583
- comment: "1",
1584
- };
1585
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1586
- return __generator(this, function (_a) {
1587
- switch (_a.label) {
1588
- case 0: return [4 /*yield*/, recordClient.deleteRecordComment(params)];
1589
- case 1:
1590
- _a.sent();
1591
- return [2 /*return*/];
1592
- }
1593
- });
1594
- }); });
1595
- it("should pass the path to the http client", function () {
1596
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/comment.json");
1597
- });
1598
- it("should send a delete request", function () {
1599
- expect(mockClient.getLogs()[0].method).toBe("delete");
1600
- });
1601
- it("should pass app, record and comment to the http client", function () {
1602
- expect(mockClient.getLogs()[0].params).toEqual(params);
1603
- });
1604
- });
1605
- describe("getRecordComments", function () {
1606
- var params = {
1607
- app: APP_ID,
1608
- record: RECORD_ID,
1609
- order: "desc",
1610
- offset: 5,
1611
- limit: 5,
1612
- };
1613
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1614
- return __generator(this, function (_a) {
1615
- switch (_a.label) {
1616
- case 0: return [4 /*yield*/, recordClient.getRecordComments(params)];
1617
- case 1:
1618
- _a.sent();
1619
- return [2 /*return*/];
1620
- }
1621
- });
1622
- }); });
1623
- it("should pass the path to the http client", function () {
1624
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/comments.json");
1625
- });
1626
- it("should send a get request", function () {
1627
- expect(mockClient.getLogs()[0].method).toBe("get");
1628
- });
1629
- it("should pass app, record, order, offset and limit to the http client", function () {
1630
- expect(mockClient.getLogs()[0].params).toEqual(params);
1631
- });
1632
- });
1633
- describe("updateRecordAssignees", function () {
1634
- var params = {
1635
- app: APP_ID,
1636
- id: RECORD_ID,
1637
- assignees: ["user1"],
1638
- revision: 10,
1639
- };
1640
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1641
- return __generator(this, function (_a) {
1642
- switch (_a.label) {
1643
- case 0: return [4 /*yield*/, recordClient.updateRecordAssignees(params)];
1644
- case 1:
1645
- _a.sent();
1646
- return [2 /*return*/];
1647
- }
1648
- });
1649
- }); });
1650
- it("should pass the path to the http client", function () {
1651
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/assignees.json");
1652
- });
1653
- it("should send a put request", function () {
1654
- expect(mockClient.getLogs()[0].method).toBe("put");
1655
- });
1656
- it("should pass app, id, assignees, and revision to the http client", function () {
1657
- expect(mockClient.getLogs()[0].params).toEqual(params);
1658
- });
1659
- });
1660
- describe("updateRecordStatus", function () {
1661
- var params = {
1662
- action: "Action1",
1663
- app: APP_ID,
1664
- assignee: "user1",
1665
- id: RECORD_ID,
1666
- revision: 10,
1667
- };
1668
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1669
- return __generator(this, function (_a) {
1670
- switch (_a.label) {
1671
- case 0: return [4 /*yield*/, recordClient.updateRecordStatus(params)];
1672
- case 1:
1673
- _a.sent();
1674
- return [2 /*return*/];
1675
- }
1676
- });
1677
- }); });
1678
- it("should pass the path to the http client", function () {
1679
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/record/status.json");
1680
- });
1681
- it("should send a put request", function () {
1682
- expect(mockClient.getLogs()[0].method).toBe("put");
1683
- });
1684
- it("should pass action, app, assignee, id, and revision to the http client", function () {
1685
- expect(mockClient.getLogs()[0].params).toEqual(params);
1686
- });
1687
- });
1688
- describe("updateRecordsStatus", function () {
1689
- var params = {
1690
- app: APP_ID,
1691
- records: [
1692
- {
1693
- action: "Action1",
1694
- assignee: "user1",
1695
- id: RECORD_ID,
1696
- revision: 10,
1697
- },
1698
- ],
1699
- };
1700
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
1701
- return __generator(this, function (_a) {
1702
- switch (_a.label) {
1703
- case 0: return [4 /*yield*/, recordClient.updateRecordsStatus(params)];
1704
- case 1:
1705
- _a.sent();
1706
- return [2 /*return*/];
1707
- }
1708
- });
1709
- }); });
1710
- it("should pass the path to the http client", function () {
1711
- expect(mockClient.getLogs()[0].path).toBe("/k/v1/records/status.json");
1712
- });
1713
- it("should send a put request", function () {
1714
- expect(mockClient.getLogs()[0].method).toBe("put");
1715
- });
1716
- it("should pass app and records to the http client", function () {
1717
- expect(mockClient.getLogs()[0].params).toEqual(params);
1718
- });
1719
- });
1720
- });
1721
- describe("RecordClient with guestSpaceId", function () {
1722
- it("should pass the path to the http client", function () { return __awaiter(void 0, void 0, void 0, function () {
1723
- var APP_ID, RECORD_ID, GUEST_SPACE_ID, requestConfigBuilder, mockClient, bulkRequestClient, recordClient, params;
1724
- return __generator(this, function (_a) {
1725
- switch (_a.label) {
1726
- case 0:
1727
- APP_ID = 1;
1728
- RECORD_ID = 2;
1729
- GUEST_SPACE_ID = 3;
1730
- requestConfigBuilder = new KintoneRequestConfigBuilder({
1731
- baseUrl: "https://example.cybozu.com",
1732
- auth: { type: "session" },
1733
- });
1734
- mockClient = buildMockClient(requestConfigBuilder);
1735
- bulkRequestClient = new BulkRequestClient(mockClient);
1736
- recordClient = new RecordClient(mockClient, bulkRequestClient, GUEST_SPACE_ID);
1737
- params = { app: APP_ID, id: RECORD_ID };
1738
- return [4 /*yield*/, recordClient.getRecord(params)];
1739
- case 1:
1740
- _a.sent();
1741
- expect(mockClient.getLogs()[0].path).toBe("/k/guest/".concat(GUEST_SPACE_ID, "/v1/record.json"));
1742
- return [2 /*return*/];
1743
- }
1744
- });
1745
- }); });
1746
- });
1747
- //# sourceMappingURL=RecordClient.test.js.map