@adobe/acc-js-sdk 1.1.47 → 1.1.49

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.
package/test/mock.js CHANGED
@@ -1103,6 +1103,8 @@ xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
1103
1103
  </SOAP-ENV:Envelope>
1104
1104
  `);
1105
1105
 
1106
+ const FILE_DOWNLOAD_RESPONSE = '"First Name","Last Name","E-Mail","Blocked","Title","Phone","Units","Gender","Department","Location","Preference 1","Preference 2"\n"Vishal","Kumar (from file)","kumarvishal@adobe.com","false","Developer","9911422203","$030,321","Male","UI","N132","Agriculture","Forestry and Fishing"';
1107
+
1106
1108
  // Public exports
1107
1109
  exports.Mock = {
1108
1110
  makeClient: makeClient,
@@ -1158,6 +1160,7 @@ exports.Mock = {
1158
1160
  GET_XTK_COUNTER_RESPONSE: GET_XTK_COUNTER_RESPONSE,
1159
1161
  GET_FILERES_QUERY_SCHEMA_RESPONSE: GET_FILERES_QUERY_SCHEMA_RESPONSE,
1160
1162
  INCREASE_VALUE_RESPONSE: INCREASE_VALUE_RESPONSE,
1163
+ FILE_DOWNLOAD_RESPONSE: FILE_DOWNLOAD_RESPONSE,
1161
1164
  FILE_RES_WRITE_RESPONSE: FILE_RES_WRITE_RESPONSE,
1162
1165
  PUBLISH_IF_NEEDED_RESPONSE: PUBLISH_IF_NEEDED_RESPONSE,
1163
1166
  GET_URL_RESPONSE: GET_URL_RESPONSE,
@@ -176,7 +176,7 @@ describe('XRK Jobs', function () {
176
176
 
177
177
  describe("Execute", () => {
178
178
  it("Execute with success", async () => {
179
- const client = { _callMethod: jest.fn() };
179
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: {}} };
180
180
  const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
181
181
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
182
182
  const jobId = await job.execute();
@@ -191,8 +191,26 @@ describe('XRK Jobs', function () {
191
191
  expect(client._callMethod.mock.calls[0][2]).toEqual([ "Prepare" ]);
192
192
  });
193
193
 
194
+ it("Execute should pass extraHttpHeaders in headers", async () => {
195
+ const extraHttpHeaders = {'x-api-key': 'check'};
196
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: { extraHttpHeaders }} };
197
+ const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
198
+ client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
199
+ const jobId = await job.execute();
200
+ expect(jobId).toBe("9876");
201
+ expect(client._callMethod.mock.calls.length).toBe(1);
202
+ expect(client._callMethod.mock.calls[0][0]).toBe("Execute");
203
+ expect(client._callMethod.mock.calls[0][1]).toMatchObject({
204
+ entitySchemaId: "nms:delivery",
205
+ schemaId: "xtk:jobInterface",
206
+ object: "Hello World",
207
+ headers: extraHttpHeaders,
208
+ });
209
+ expect(client._callMethod.mock.calls[0][2]).toEqual([ "Prepare" ]);
210
+ });
211
+
194
212
  it("Infer schema from objects", async () => {
195
- const client = { _callMethod: jest.fn() };
213
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: {}} };
196
214
  const job = new XtkJobInterface(client, { object: { xtkschema: "nms:delivery", name: "Hello World" }, method: "Prepare" });
197
215
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
198
216
  const jobId = await job.execute();
@@ -238,7 +256,7 @@ describe('XRK Jobs', function () {
238
256
 
239
257
  describe("Submit", () => {
240
258
  it("Submit with success", async () => {
241
- const client = { _callMethod: jest.fn() };
259
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: {}} };
242
260
  const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
243
261
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
244
262
  const jobId = await job.submit();
@@ -253,8 +271,26 @@ describe('XRK Jobs', function () {
253
271
  expect(client._callMethod.mock.calls[0][2]).toEqual([ "Prepare" ]);
254
272
  });
255
273
 
274
+ it("Submit should pass extraHttpHeaders in headers", async () => {
275
+ const extraHttpHeaders = {'x-api-key': 'check'};
276
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: { extraHttpHeaders }} };
277
+ const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
278
+ client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
279
+ const jobId = await job.submit();
280
+ expect(jobId).toBe("9876");
281
+ expect(client._callMethod.mock.calls.length).toBe(1);
282
+ expect(client._callMethod.mock.calls[0][0]).toBe("Submit");
283
+ expect(client._callMethod.mock.calls[0][1]).toMatchObject({
284
+ entitySchemaId: "nms:delivery",
285
+ schemaId: "xtk:jobInterface",
286
+ object: "Hello World",
287
+ headers: extraHttpHeaders,
288
+ });
289
+ expect(client._callMethod.mock.calls[0][2]).toEqual([ "Prepare" ]);
290
+ });
291
+
256
292
  it("Infer schema from objects", async () => {
257
- const client = { _callMethod: jest.fn() };
293
+ const client = { _callMethod: jest.fn(), _connectionParameters: { _options: {}} };
258
294
  const job = new XtkJobInterface(client, { object: { xtkschema: "nms:delivery", name: "Hello World" }, method: "Prepare" });
259
295
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
260
296
  const jobId = await job.submit();
@@ -301,7 +337,7 @@ describe('XRK Jobs', function () {
301
337
 
302
338
  describe("SubmitSoapCall", () => {
303
339
  it("SubmitSoapCall with success", async () => {
304
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
340
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
305
341
  const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
306
342
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
307
343
  client.getSchema.mockReturnValueOnce(Promise.resolve(true));
@@ -325,8 +361,27 @@ describe('XRK Jobs', function () {
325
361
  } ]);
326
362
  });
327
363
 
364
+ it("SubmitSoapCall should pass extraHttpHeaders in headers", async () => {
365
+ const extraHttpHeaders = {'x-api-key': 'check'};
366
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: { extraHttpHeaders }} };
367
+ const job = new XtkJobInterface(client, { xtkschema: "nms:delivery", object: "Hello World", method: "Prepare" });
368
+ client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
369
+ client.getSchema.mockReturnValueOnce(Promise.resolve(true));
370
+ client._methodCache.get.mockReturnValueOnce(DomUtil.parse("<method></method>").documentElement);
371
+ const jobId = await job.submitSoapCall();
372
+ expect(jobId).toBe("9876");
373
+ expect(client._callMethod.mock.calls.length).toBe(1);
374
+ expect(client._callMethod.mock.calls[0][0]).toBe("SubmitSoapCall");
375
+ expect(client._callMethod.mock.calls[0][1]).toMatchObject({
376
+ entitySchemaId: "nms:delivery",
377
+ schemaId: "xtk:jobInterface",
378
+ object: "Hello World",
379
+ headers: extraHttpHeaders,
380
+ });
381
+ });
382
+
328
383
  it("SubmitSoapCall a non-persistant and static job with success", async () => {
329
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
384
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
330
385
  const jobDescription = {
331
386
  doNotPersist: "true",
332
387
  xtkschema: 'nms:webApp',
@@ -368,7 +423,7 @@ describe('XRK Jobs', function () {
368
423
  });
369
424
 
370
425
  it("Infer schema from objects", async () => {
371
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
426
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
372
427
  const job = new XtkJobInterface(client, { object: { xtkschema: "nms:delivery", name: "Hello World" }, method: "Prepare" });
373
428
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
374
429
  client.getSchema.mockReturnValueOnce(Promise.resolve(true));
@@ -383,7 +438,7 @@ describe('XRK Jobs', function () {
383
438
  });
384
439
 
385
440
  it("Should fail on missing schema", async () => {
386
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
441
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
387
442
  const job = new XtkJobInterface(client, { method: "Prepare" });
388
443
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
389
444
  client.getSchema.mockReturnValueOnce(Promise.resolve(false));
@@ -400,7 +455,7 @@ describe('XRK Jobs', function () {
400
455
  });
401
456
 
402
457
  it("Should fail on invalid schema", async () => {
403
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
458
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
404
459
  const job = new XtkJobInterface(client, { object: { xtkschema: "nms:notFound", name: "Hello World" }, method: "Prepare" });
405
460
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
406
461
  client.getSchema.mockReturnValueOnce(Promise.resolve(false));
@@ -417,7 +472,7 @@ describe('XRK Jobs', function () {
417
472
  });
418
473
 
419
474
  it("Should fail on method not found", async () => {
420
- const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()} };
475
+ const client = { _callMethod: jest.fn(), getSchema: jest.fn(), _methodCache: { get: jest.fn()}, _connectionParameters: { _options: {}} };
421
476
  const job = new XtkJobInterface(client, { object: { xtkschema: "nms:delivery", name: "Hello World" }, method: "NotFound" });
422
477
  client._callMethod.mockReturnValueOnce(Promise.resolve("9876"));
423
478
  client.getSchema.mockReturnValueOnce(Promise.resolve(true));
@@ -487,6 +542,16 @@ describe('XRK Jobs', function () {
487
542
  expect(client.NLWS.xtkJob.getStatus.mock.calls.length).toBe(1);
488
543
  expect(client.NLWS.xtkJob.getStatus.mock.calls[0]).toEqual(["ABC", 12, 500]);
489
544
  });
545
+
546
+ it("Should get status from provided jobId", async () => {
547
+ const jobId = 'ABC';
548
+ const client = { NLWS: { xtkJob: { getStatus: jest.fn() } } };
549
+ const job = new XtkJobInterface(client, { jobId });
550
+ client.NLWS.xtkJob.getStatus.mockReturnValueOnce(Promise.resolve({ }));
551
+ await job.getStatus(12, 500);
552
+ expect(client.NLWS.xtkJob.getStatus.mock.calls.length).toBe(1);
553
+ expect(client.NLWS.xtkJob.getStatus.mock.calls[0]).toEqual([jobId, 12, 500]);
554
+ });
490
555
  });
491
556
 
492
557
  describe("Get Result", () => {