biz-a-cli 2.3.32 → 2.3.33

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.
@@ -10,6 +10,12 @@ const {
10
10
  getConfig,
11
11
  getInputData,
12
12
  getQueryDataObsParameters,
13
+ mapData2Key,
14
+ getUrlApi,
15
+ json2Parameters,
16
+ getUrlAndParam,
17
+ getTableObj,
18
+ options
13
19
  } = await import('../scheduler/datalib.js');
14
20
 
15
21
  describe('data test', () => {
@@ -146,5 +152,159 @@ describe('data test', () => {
146
152
  });
147
153
  });
148
154
 
155
+ test('should map data correctly when key is provided', () => {
156
+ const res = [
157
+ { id: 1, name: 'Alice' },
158
+ { id: 2, name: 'Bob' },
159
+ ];
160
+ const cols = [
161
+ { key: 'identifier', data: 'id' },
162
+ { key: 'fullName', data: 'name' },
163
+ ];
164
+
165
+ const result = mapData2Key(res, cols);
166
+ expect(result).toEqual([
167
+ { identifier: 1, fullName: 'Alice' },
168
+ { identifier: 2, fullName: 'Bob' },
169
+ ]);
170
+ });
171
+
172
+ test('should map data correctly when key is not provided', () => {
173
+ const res = [
174
+ { id: 1, name: 'Alice' },
175
+ { id: 2, name: 'Bob' },
176
+ ];
177
+ const cols = [
178
+ { data: 'id' },
179
+ { data: 'name' },
180
+ ];
181
+
182
+ const result = mapData2Key(res, cols);
183
+ expect(result).toEqual([
184
+ { id: 1, name: 'Alice' },
185
+ { id: 2, name: 'Bob' },
186
+ ]);
187
+ });
188
+
189
+ test('should handle an empty result set', () => {
190
+ const res = [];
191
+ const cols = [
192
+ { key: 'identifier', data: 'id' },
193
+ { key: 'fullName', data: 'name' },
194
+ ];
195
+
196
+ const result = mapData2Key(res, cols);
197
+ expect(result).toEqual([]);
198
+ });
199
+
200
+ test('should handle an empty column set', () => {
201
+ const res = [
202
+ { id: 1, name: 'Alice' },
203
+ { id: 2, name: 'Bob' },
204
+ ];
205
+ const cols = [];
206
+
207
+ const result = mapData2Key(res, cols);
208
+ expect(result).toEqual([{}, {}]);
209
+ });
210
+
211
+ test('should handle null and undefined values in the data', () => {
212
+ const res = [
213
+ { id: 1, name: null },
214
+ { id: null, name: 'Bob' },
215
+ ];
216
+ const cols = [
217
+ { key: 'identifier', data: 'id' },
218
+ { key: 'fullName', data: 'name' },
219
+ ];
220
+
221
+ const result = mapData2Key(res, cols);
222
+ expect(result).toEqual([
223
+ { identifier: 1, fullName: null },
224
+ { identifier: null, fullName: 'Bob' },
225
+ ]);
226
+ });
227
+
228
+ test('should return the correct URL for POST requests', () => {
229
+ const config = { url: 'http://example.com' };
230
+ const methodName = 'testMethod';
231
+ const isPost = true;
232
+ const expectedUrl = 'http://example.com/fina/rest/TOrmMethod/%22testMethod%22';
233
+
234
+ expect(getUrlApi(config, methodName, isPost)).toBe(expectedUrl);
235
+ });
236
+
237
+ test('should return the correct URL for GET requests', () => {
238
+ const config = { url: 'http://example.com' };
239
+ const methodName = 'testMethod';
240
+ const isPost = false;
241
+ const expectedUrl = 'http://example.com/fina/rest/TOrmMethod/testMethod';
242
+
243
+ expect(getUrlApi(config, methodName, isPost)).toBe(expectedUrl);
244
+ });
245
+
246
+ test('should convert an array of objects to a JSON string with a _parameters key', () => {
247
+ const input = [{ a: 1 }, { b: 2 }];
248
+ const expectedOutput = JSON.stringify({ _parameters: [JSON.stringify({ a: 1 }), JSON.stringify({ b: 2 })] });
249
+
250
+ expect(json2Parameters(input)).toBe(expectedOutput);
251
+ });
252
+
253
+ test('should handle an empty array', () => {
254
+ const input = [];
255
+ const expectedOutput = JSON.stringify({ _parameters: [] });
256
+
257
+ expect(json2Parameters(input)).toBe(expectedOutput);
258
+ });
259
+
260
+ test('should return correct url and params', () => {
261
+ const config = {
262
+ url: 'https://example.com',
263
+ dbindex: '1'
264
+ };
265
+ const method = 'POST';
266
+ const obj = { id: 1 };
267
+ const path = 'testMethod';
268
+ const result = getUrlAndParam(config, method, obj, path);
269
+
270
+ expect(result).toEqual({
271
+ url: 'https://example.com/fina/rest/TOrmMethod/%22testMethod%22',
272
+ params: "{\"_parameters\":[\"{\\\"dbIndex\\\":\\\"1\\\",\\\"method\\\":\\\"POST\\\",\\\"object\\\":{\\\"id\\\":1}}\"]}"
273
+ });
274
+ });
275
+
276
+ test('should get table object', () => {
277
+ const model = { id: 1, name: 'testModel' };
278
+ const tableName = 'testTable';
279
+
280
+ const result = getTableObj(model, tableName);
281
+
282
+ let expected = {};
283
+ expected[tableName] = model;
284
+ expect(result).toEqual(expected);
285
+ });
286
+
287
+ test('should return the correct headers and params', () => {
288
+ const apiConfig = { subdomain: 'example' };
289
+ const expectedResult = {
290
+ headers: { 'content-type': 'text/plain' },
291
+ params: { subdomain: 'example' }
292
+ };
293
+
294
+ const result = options(apiConfig);
295
+ expect(result).toEqual(expectedResult);
296
+ });
297
+
298
+ test('should handle missing subdomain in apiConfig', () => {
299
+ const apiConfig = {};
300
+ const expectedResult = {
301
+ headers: { 'content-type': 'text/plain' },
302
+ params: { subdomain: undefined }
303
+ };
304
+
305
+ const result = options(apiConfig);
306
+ expect(result).toEqual(expectedResult);
307
+ });
308
+
149
309
  })
150
310
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { jest } from '@jest/globals'
3
3
 
4
- const mockSendMail = jest.fn();
4
+ let mockSendMail = jest.fn();
5
5
  const mockCreateTransport = jest.fn();
6
6
  mockCreateTransport.mockImplementation(() => ({
7
7
  sendMail: mockSendMail
@@ -16,7 +16,7 @@ const { sendMailWatcher } = await import('../mailController.js');
16
16
  describe('Mail Controller', () => {
17
17
  let req;
18
18
 
19
- test('transporter.sendmailWatcher is called', () => {
19
+ test('transporter.sendmailWatcher is called', async () => {
20
20
  req = {
21
21
  body: {
22
22
  companyname: 'abc',
@@ -26,9 +26,14 @@ describe('Mail Controller', () => {
26
26
  },
27
27
  }
28
28
 
29
- sendMailWatcher(req);
29
+ mockSendMail.mockResolvedValue('OK');
30
+ expect(await sendMailWatcher(req)).toEqual('OK');
30
31
  expect(mockSendMail).toBeCalledTimes(1);
31
32
  expect(mockCreateTransport).toHaveBeenCalledWith({ smtp: 'test' });
32
33
 
34
+ mockSendMail.mockRejectedValue({ message: 'error' });
35
+ expect(await sendMailWatcher(req)).toEqual('error');
36
+
37
+ expect(mockSendMail).toBeCalledTimes(2);
33
38
  })
34
39
  })