"use strict";

var _typeof = require("@babel/runtime-corejs2/helpers/typeof");
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _WeakMap = require("@babel/runtime-corejs2/core-js/weak-map");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
var _types = require("../common/types");
var _testUtil = require("../common/testUtil");
var _types2 = require("../Logger/types");
var _ContactsClient = require("./ContactsClient");
var _constants = require("../common/constants");
var _Logger = _interopRequireDefault(require("../Logger"));
var _constants2 = require("./constants");
var utils = _interopRequireWildcard(require("../common/Utils"));
var _constants3 = require("../CallingClient/constants");
var _contactFixtures = require("./contactFixtures");
function _interopRequireWildcard(e, t) { if ("function" == typeof _WeakMap) var r = new _WeakMap(), n = new _WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
describe('ContactClient Tests', function () {
  var webex = (0, _testUtil.getTestUtilsWebex)();
  var contactClient;

  // eslint-disable-next-line no-underscore-dangle
  var contactServiceUrl = "".concat(webex.internal.services._serviceUrls.contactsService, "/").concat(_constants2.ENCRYPT_FILTER, "/").concat(_constants2.USERS, "/").concat(_constants2.CONTACT_FILTER);
  var scimUrl = "".concat(_constants.WEBEX_API_BTS, "/").concat(_constants.IDENTITY_ENDPOINT_RESOURCE, "/").concat(_constants.SCIM_ENDPOINT_RESOURCE, "/").concat(webex.internal.device.orgId, "/").concat(_constants.SCIM_USER_FILTER, "id%20eq%20%22801bb994-343b-4f6b-97ae-d13c91d4b877%22");
  // eslint-disable-next-line no-underscore-dangle
  var contactServiceGroupUrl = "".concat(webex.internal.services._serviceUrls.contactsService, "/").concat(_constants2.ENCRYPT_FILTER, "/").concat(_constants2.USERS, "/").concat(_constants2.GROUP_FILTER);
  var serviceErrorCodeHandlerSpy = jest.spyOn(utils, 'serviceErrorCodeHandler');
  var uploadLogsSpy = jest.spyOn(utils, 'uploadLogs').mockResolvedValue();
  var failureResponsePayload = {
    statusCode: 503,
    body: {}
  };
  var mockGroupResponse = _contactFixtures.mockContactResponseBodyOne.groups[0];
  beforeEach(function () {
    contactClient = (0, _ContactsClient.createContactsClient)(webex, {
      level: _types2.LOGGER.INFO
    });
    expect(contactClient).toBeTruthy();
    expect(contactClient.getSDKConnector().getWebex()).toBeTruthy();

    // Set up log spies for each test
    jest.spyOn(_Logger.default, 'info');
    jest.spyOn(_Logger.default, 'log');
    jest.spyOn(_Logger.default, 'warn');
    jest.spyOn(_Logger.default, 'error');
  });
  afterEach(function () {
    webex.request.mockClear();
    jest.clearAllMocks();
  });

  /**
   * TestCase inputs
   * name: TestCase name
   * payloadData: Response body
   * inputStatusCode: Status code received in response
   * expectedData: Expected data field in ContactResponse after processing
   * expectedMessage: Expected message field in ContactResponse after processing
   * expectedStatusCode: Expected status code field in ContactResponse after processing
   * decryptTextList: Array of decrypted contact list.
   */
  var errorCodes = [{
    name: 'Success case 1: fetch contacts using get contacts api, custom and cloud contact present',
    payloadData: _contactFixtures.mockContactResponseBodyOne,
    inputStatusCode: 200,
    expectedData: {
      contacts: _contactFixtures.mockContactListOne,
      groups: _contactFixtures.mockContactGroupListOne
    },
    expectedMessage: _constants.SUCCESS_MESSAGE,
    expectedStatusCode: 200,
    decryptTextList: [_contactFixtures.mockCity, _contactFixtures.mockCountry, _contactFixtures.mockState, _contactFixtures.mockStreet, _contactFixtures.mockZipCode, _contactFixtures.mockAvatarURL, _contactFixtures.mockCompany, _contactFixtures.mockDisplayNameOne, _contactFixtures.mockEmail, _contactFixtures.mockFirstName, _contactFixtures.mockLastName, _contactFixtures.mockNumber1, _contactFixtures.mockNumber2, _contactFixtures.mockSipAddress, _contactFixtures.mockTitle, _contactFixtures.mockNumber2, _contactFixtures.mockSipAddress, _contactFixtures.mockGroupName],
    cloudContactPresent: true,
    scimResponse: _contactFixtures.mockSCIMListResponse
  }, {
    name: 'Success case 2: fetch contacts using get contacts api, single custom contact with mandatory details present',
    payloadData: _contactFixtures.mockContactResponseBodyTwo,
    inputStatusCode: 200,
    expectedData: {
      contacts: _contactFixtures.mockContactListTwo,
      groups: _contactFixtures.mockContactGroupListTwo
    },
    expectedMessage: _constants.SUCCESS_MESSAGE,
    expectedStatusCode: 200,
    decryptTextList: [_contactFixtures.mockDisplayNameTwo, _contactFixtures.mockGroupName]
  }, {
    name: 'Success case 3: fetch contacts using get contacts api, no contacts returned',
    payloadData: _contactFixtures.mockContactResponseBodyThird,
    inputStatusCode: 200,
    expectedData: {
      contacts: [],
      groups: []
    },
    expectedMessage: _constants.SUCCESS_MESSAGE,
    expectedStatusCode: 200,
    decryptTextList: []
  }, {
    name: 'Failed case: 200 OK with no response body',
    payloadData: undefined,
    inputStatusCode: 200,
    expectedData: {
      error: '422 Exception has occurred'
    },
    expectedMessage: _constants.FAILURE_MESSAGE,
    expectedStatusCode: 422,
    decryptTextList: []
  }, {
    name: 'Failed case 403: fetch contacts using get contacts api',
    payloadData: {
      error: '403 Forbidden'
    },
    inputStatusCode: 403,
    expectedData: {
      error: 'User request is forbidden'
    },
    expectedMessage: _constants.FAILURE_MESSAGE,
    expectedStatusCode: 403,
    decryptTextList: []
  }, {
    name: 'Failed case 408: fetch contacts using get contacts api',
    payloadData: {
      error: '408 Request Timeout'
    },
    inputStatusCode: 408,
    expectedData: {
      error: 'Request to the server timedout'
    },
    expectedMessage: _constants.FAILURE_MESSAGE,
    expectedStatusCode: 408,
    decryptTextList: []
  }, {
    name: 'Failed case 500: fetch contacts using get contacts api',
    payloadData: {
      error: '500 Internal Server Error'
    },
    inputStatusCode: 500,
    expectedData: {
      error: 'Internal server error occurred'
    },
    expectedMessage: _constants.FAILURE_MESSAGE,
    expectedStatusCode: 500,
    decryptTextList: []
  }, {
    name: 'Failed case 503: fetch contacts using get contacts api',
    payloadData: {
      error: '503 Service Unavailable'
    },
    inputStatusCode: 503,
    expectedData: {
      error: 'Unable to establish a connection with the server'
    },
    expectedMessage: _constants.FAILURE_MESSAGE,
    expectedStatusCode: 503,
    decryptTextList: []
  }].map(function (stat) {
    return (0, _assign.default)(stat, {
      toString: function toString() {
        /* eslint-disable dot-notation */
        return this['name'];
      }
    });
  });
  it.each(errorCodes)('%s', /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(codeObj) {
      var respPayload, contactsResponse;
      return _regenerator.default.wrap(function (_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            respPayload = {
              statusCode: codeObj.inputStatusCode
            };
            if (codeObj.inputStatusCode === 200) {
              respPayload['body'] = codeObj.payloadData;
              webex.request.mockResolvedValueOnce(respPayload);
              codeObj.decryptTextList.forEach(function (text) {
                webex.internal.encryption.decryptText.mockResolvedValueOnce(text);
              });
              if (codeObj.scimResponse) {
                webex.request.mockResolvedValueOnce(_contactFixtures.mockSCIMListResponse);
              }
            } else {
              respPayload['message'] = _constants.FAILURE_MESSAGE;
              respPayload['data'] = codeObj.payloadData;
              webex.request.mockRejectedValueOnce(respPayload);
            }
            _context.next = 1;
            return contactClient.getContacts();
          case 1:
            contactsResponse = _context.sent;
            if (codeObj.inputStatusCode === 200) {
              if (codeObj.cloudContactPresent) {
                expect(webex.request).toBeCalledTimes(2);
              } else {
                expect(webex.request).toBeCalledTimes(1);
              }
              expect(webex.request).toHaveBeenNthCalledWith(1, {
                uri: contactServiceUrl,
                method: _types.HTTP_METHODS.GET
              });
              if (codeObj.cloudContactPresent) {
                expect(webex.request).toHaveBeenNthCalledWith(2, {
                  uri: scimUrl,
                  method: _types.HTTP_METHODS.GET,
                  headers: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _constants3.CISCO_DEVICE_URL, 'https://wdm-intb.ciscospark.com/wdm/api/v1/devices/c5ae3b86-1bb7-40f1-a6a9-c296ee7e61d5'), 'spark-user-agent', 'webex-calling/beta')
                });
              }
              expect(_Logger.default.info).toHaveBeenCalledWith(_constants.METHOD_START_MESSAGE, {
                file: _constants2.CONTACTS_CLIENT,
                method: _constants2.METHODS.GET_CONTACTS
              });
              if (codeObj.payloadData) {
                expect(_Logger.default.log).toHaveBeenCalledWith('Successfully fetched contacts and groups', {
                  file: _constants2.CONTACTS_CLIENT,
                  method: _constants2.METHODS.GET_CONTACTS
                });
              } else {
                expect(_Logger.default.error).toHaveBeenCalled();
              }
            } else {
              expect(webex.request).toBeCalledOnceWith({
                uri: contactServiceUrl,
                method: _types.HTTP_METHODS.GET
              });
              expect(_Logger.default.info).toHaveBeenCalledWith(_constants.METHOD_START_MESSAGE, {
                file: _constants2.CONTACTS_CLIENT,
                method: _constants2.METHODS.GET_CONTACTS
              });
              expect(_Logger.default.error).toHaveBeenCalled();
            }
            expect(contactsResponse).toEqual({
              data: expect.any(Object),
              message: codeObj.expectedMessage,
              statusCode: codeObj.expectedStatusCode
            });
            if (codeObj.expectedMessage === _constants.SUCCESS_MESSAGE) {
              expect(serviceErrorCodeHandlerSpy).not.toBeCalled();
            } else {
              expect(serviceErrorCodeHandlerSpy).toBeCalledOnceWith(codeObj.payloadData ? respPayload : expect.any(Error), {
                file: _constants2.CONTACTS_CLIENT,
                method: _constants2.METHODS.GET_CONTACTS
              });
            }
          case 2:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x) {
      return _ref.apply(this, arguments);
    };
  }());
  it('create a contact group without encryptionKey', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
    var _contactsResponse$dat;
    var successResponsePayload, contactsResponse;
    return _regenerator.default.wrap(function (_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          successResponsePayload = {
            statusCode: 201,
            body: mockGroupResponse
          };
          contactClient['groups'] = [];
          contactClient['encryptionKeyUrl'] = '';
          webex.request.mockResolvedValue(successResponsePayload);
          webex.internal.encryption.kms.createUnboundKeys.mockResolvedValue([_contactFixtures.mockKmsKey]);
          webex.internal.encryption.kms.createResource.mockResolvedValue(_contactFixtures.mockKmsKey);
          webex.internal.encryption.encryptText.mockResolvedValueOnce('Encrypted Other').mockResolvedValueOnce('Encrypted Top');
          _context2.next = 1;
          return contactClient.createContactGroup('Top Contacts');
        case 1:
          contactsResponse = _context2.sent;
          expect(contactsResponse.statusCode).toEqual(201);
          expect((_contactsResponse$dat = contactsResponse.data.group) === null || _contactsResponse$dat === void 0 ? void 0 : _contactsResponse$dat.groupId).toBe(mockGroupResponse.groupId);
          expect(webex.internal.encryption.kms.createUnboundKeys).toBeCalledOnceWith({
            count: 1
          });
          expect(webex.internal.encryption.kms.createResource).toBeCalledOnceWith({
            keyUris: [_contactFixtures.mockKmsKey.uri]
          });
          expect(webex.request).toBeCalledTimes(2);
          expect(webex.request).toHaveBeenNthCalledWith(1, {
            uri: contactServiceGroupUrl,
            method: 'POST',
            body: {
              displayName: 'Encrypted Other',
              encryptionKeyUrl: _contactFixtures.mockKmsKey.uri,
              groupType: 'NORMAL',
              schemas: 'urn:cisco:codev:identity:contact:core:1.0'
            }
          });
          expect(webex.request).toHaveBeenNthCalledWith(2, {
            uri: contactServiceGroupUrl,
            method: 'POST',
            body: {
              displayName: 'Encrypted Top',
              encryptionKeyUrl: _contactFixtures.mockKmsKey.uri,
              groupType: 'NORMAL',
              schemas: 'urn:cisco:codev:identity:contact:core:1.0'
            }
          });
          expect(contactClient['groups'].length).toEqual(2);
          expect(contactClient['groups'][1].displayName).toEqual('Top Contacts');
          expect(_Logger.default.info).toHaveBeenCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with displayName: Top Contacts"), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
          expect(_Logger.default.info).toHaveBeenCalledWith(_constants.METHOD_START_MESSAGE, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_NEW_ENCRYPTION_KEY_URL
          });
          expect(_Logger.default.info).toHaveBeenCalledWith('Requesting kms for a new KRO and key', {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_NEW_ENCRYPTION_KEY_URL
          });
          expect(_Logger.default.log).toHaveBeenCalledWith("Creating a default group: ".concat(_constants2.DEFAULT_GROUP_NAME), {
            file: _constants2.CONTACTS_CLIENT,
            method: 'fetchEncryptionKeyUrl'
          });
          expect(_Logger.default.log).toHaveBeenCalledWith("Contact group Top Contacts successfully created", {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
        case 2:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('create a contact group with existing key info', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
    var _contactsResponse$dat2;
    var successResponsePayload, infoSpy, contactsResponse;
    return _regenerator.default.wrap(function (_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          successResponsePayload = {
            statusCode: 201,
            body: mockGroupResponse
          };
          contactClient['groups'] = _contactFixtures.mockContactGroupListOne;
          webex.request.mockResolvedValue(successResponsePayload);
          webex.internal.encryption.encryptText.mockResolvedValue('Encrypted Top Contacts');
          infoSpy = jest.spyOn(_Logger.default, 'info');
          _context3.next = 1;
          return contactClient.createContactGroup('Top Contacts');
        case 1:
          contactsResponse = _context3.sent;
          expect(contactsResponse.statusCode).toEqual(201);
          expect((_contactsResponse$dat2 = contactsResponse.data.group) === null || _contactsResponse$dat2 === void 0 ? void 0 : _contactsResponse$dat2.groupId).toBe(mockGroupResponse.groupId);
          expect(infoSpy).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with displayName: Top Contacts"), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
          expect(_Logger.default.log).toBeCalledWith("Contact group Top Contacts successfully created", {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
          expect(infoSpy).not.toBeCalledWith(_constants.METHOD_START_MESSAGE, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_NEW_ENCRYPTION_KEY_URL
          });
          expect(webex.request).toBeCalledOnceWith({
            uri: contactServiceGroupUrl,
            method: _types.HTTP_METHODS.POST,
            body: {
              displayName: 'Encrypted Top Contacts',
              encryptionKeyUrl: _contactFixtures.mockContactGroupListOne[0].encryptionKeyUrl,
              groupType: 'NORMAL',
              schemas: _constants2.CONTACTS_SCHEMA
            }
          });
          expect(contactClient['groups'].length).toEqual(2);
          expect(contactClient['groups'][1].displayName).toEqual('Top Contacts');
        case 2:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  it('create a contact group with same displayName', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
    var logSpy, contactsResponse;
    return _regenerator.default.wrap(function (_context4) {
      while (1) switch (_context4.prev = _context4.next) {
        case 0:
          contactClient['groups'] = _contactFixtures.mockContactResponseBodyOne.groups;
          webex.internal.encryption.kms.createUnboundKeys.mockResolvedValue([_contactFixtures.mockKmsKey]);
          webex.internal.encryption.kms.createResource.mockResolvedValue(_contactFixtures.mockKmsKey);
          logSpy = jest.spyOn(_Logger.default, 'warn');
          _context4.next = 1;
          return contactClient.createContactGroup(mockGroupResponse.displayName);
        case 1:
          contactsResponse = _context4.sent;
          expect(webex.request).not.toBeCalled();
          expect(contactsResponse.statusCode).toBe(400);
          expect(logSpy).toBeCalledOnceWith("Group name ".concat(mockGroupResponse.displayName, " already exists."), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with displayName: ").concat(mockGroupResponse.displayName), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT_GROUP
          });
          expect(contactClient['groups']).toEqual(_contactFixtures.mockContactResponseBodyOne.groups);
        case 2:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })));
  it('create a contact group - service unavailable', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
    var loggerContext, warnSpy, errorSpy, contactsResponse;
    return _regenerator.default.wrap(function (_context5) {
      while (1) switch (_context5.prev = _context5.next) {
        case 0:
          loggerContext = {
            file: _constants2.CONTACTS_CLIENT,
            method: 'createContactGroup'
          };
          contactClient['groups'] = _contactFixtures.mockContactGroupListOne;
          webex.request.mockRejectedValue(failureResponsePayload);
          webex.internal.encryption.kms.createUnboundKeys.mockResolvedValue([_contactFixtures.mockKmsKey]);
          webex.internal.encryption.kms.createResource.mockResolvedValue(_contactFixtures.mockKmsKey);
          webex.internal.encryption.encryptText.mockResolvedValueOnce('Encrypted group name');
          warnSpy = jest.spyOn(_Logger.default, 'warn');
          errorSpy = jest.spyOn(_Logger.default, 'error');
          _context5.next = 1;
          return contactClient.createContactGroup('New group');
        case 1:
          contactsResponse = _context5.sent;
          expect(contactsResponse.statusCode).toBe(503);
          expect(webex.request).toBeCalledOnceWith({
            uri: contactServiceGroupUrl,
            method: _types.HTTP_METHODS.POST,
            body: {
              displayName: 'Encrypted group name',
              encryptionKeyUrl: 'kms://cisco.com/keys/dcf18f9d-155e-44ff-ad61-c8a69b7103ab',
              groupType: 'NORMAL',
              schemas: 'urn:cisco:codev:identity:contact:core:1.0'
            }
          });
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with displayName: New group"), loggerContext);
          expect(warnSpy).toBeCalledTimes(1);
          expect(warnSpy).toHaveBeenNthCalledWith(1, '503 Unable to establish a connection with the server', loggerContext);
          expect(errorSpy).toBeCalledTimes(1);
          expect(errorSpy).toHaveBeenNthCalledWith(1, "Unable to create contact group: ".concat((0, _stringify.default)(failureResponsePayload)), loggerContext);
          expect(contactClient['groups']).toEqual(_contactFixtures.mockContactGroupListOne);
          expect(serviceErrorCodeHandlerSpy).toBeCalledOnceWith(failureResponsePayload, loggerContext);
        case 2:
        case "end":
          return _context5.stop();
      }
    }, _callee5);
  })));
  it('delete a contact group - service unavailable', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
    var loggerContext, warnSpy, errorSpy, contactsResponse;
    return _regenerator.default.wrap(function (_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          loggerContext = {
            file: _constants2.CONTACTS_CLIENT,
            method: 'deleteContactGroup'
          };
          contactClient['groups'] = _contactFixtures.mockContactGroupListOne;
          webex.request.mockRejectedValue(failureResponsePayload);
          webex.internal.encryption.kms.createUnboundKeys.mockResolvedValue([_contactFixtures.mockKmsKey]);
          webex.internal.encryption.kms.createResource.mockResolvedValue(_contactFixtures.mockKmsKey);
          warnSpy = jest.spyOn(_Logger.default, 'warn');
          errorSpy = jest.spyOn(_Logger.default, 'error');
          _context6.next = 1;
          return contactClient.deleteContactGroup(mockGroupResponse.groupId);
        case 1:
          contactsResponse = _context6.sent;
          expect(contactsResponse.statusCode).toBe(503);
          expect(webex.request).toBeCalledOnceWith({
            method: _types.HTTP_METHODS.DELETE,
            uri: "".concat(contactServiceGroupUrl, "/").concat(mockGroupResponse.groupId)
          });
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with groupId: ").concat(mockGroupResponse.groupId), loggerContext);
          expect(_Logger.default.info).toBeCalledWith("Deleting contact group: ".concat(mockGroupResponse.groupId), loggerContext);
          expect(warnSpy).toBeCalledTimes(1);
          expect(errorSpy).toBeCalledTimes(1);
          expect(uploadLogsSpy).toBeCalledTimes(1);
          expect(errorSpy).toHaveBeenNthCalledWith(1, "Unable to delete contact group ".concat(mockGroupResponse.groupId, ": ").concat((0, _stringify.default)(failureResponsePayload)), loggerContext);
          expect(warnSpy).toHaveBeenNthCalledWith(1, '503 Unable to establish a connection with the server', loggerContext);
          expect(contactClient['groups']).toEqual(_contactFixtures.mockContactGroupListOne);
          expect(serviceErrorCodeHandlerSpy).toBeCalledOnceWith(failureResponsePayload, loggerContext);
        case 2:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })));
  it('successful deletion of contact group', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
    var successResponsePayload, response;
    return _regenerator.default.wrap(function (_context7) {
      while (1) switch (_context7.prev = _context7.next) {
        case 0:
          successResponsePayload = {
            statusCode: 204
          };
          contactClient['groups'] = [_contactFixtures.mockContactGroupListOne[0]];
          webex.request.mockResolvedValue(successResponsePayload);
          _context7.next = 1;
          return contactClient.deleteContactGroup(_contactFixtures.mockContactGroupListOne[0].groupId);
        case 1:
          response = _context7.sent;
          expect(response.statusCode).toEqual(204);
          expect(webex.request).toBeCalledOnceWith({
            uri: "".concat(contactServiceGroupUrl, "/").concat(_contactFixtures.mockContactGroupListOne[0].groupId),
            method: _types.HTTP_METHODS.DELETE
          });
          expect(contactClient['groups']).toEqual([]);
          expect(_Logger.default.info).toBeCalledWith("Deleting contact group: ".concat(_contactFixtures.mockContactGroupListOne[0].groupId), {
            file: _constants2.CONTACTS_CLIENT,
            method: 'deleteContactGroup'
          });
          expect(_Logger.default.log).toBeCalledWith("Contact group ".concat(_contactFixtures.mockContactGroupListOne[0].groupId, " successfully deleted"), {
            file: _constants2.CONTACTS_CLIENT,
            method: 'deleteContactGroup'
          });
        case 2:
        case "end":
          return _context7.stop();
      }
    }, _callee7);
  })));
  it('create a contact with an existing group', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
    var _res$data$contact, _result$data$contact;
    var mockContactResponse, successResponsePayload, infoSpy, logSpy, contact, res, result;
    return _regenerator.default.wrap(function (_context8) {
      while (1) switch (_context8.prev = _context8.next) {
        case 0:
          mockContactResponse = _contactFixtures.mockContactResponseBodyTwo.contacts[0];
          successResponsePayload = {
            statusCode: 201,
            body: mockContactResponse
          };
          webex.request.mockResolvedValue(successResponsePayload);
          webex.internal.encryption.encryptText.mockResolvedValue('Encrypted contact name');
          infoSpy = jest.spyOn(_Logger.default, 'info');
          logSpy = jest.spyOn(_Logger.default, 'log');
          contactClient['groups'] = _contactFixtures.mockContactGroupListOne;
          contactClient['encryptionKeyUrl'] = _contactFixtures.mockContactGroupListOne[0].encryptionKeyUrl;
          contact = _contactFixtures.mockContactListTwo.slice()[0];
          contact.groups = [];
          _context8.next = 1;
          return contactClient.createContact(contact);
        case 1:
          res = _context8.sent;
          expect(res.statusCode).toEqual(201);
          expect((_res$data$contact = res.data.contact) === null || _res$data$contact === void 0 ? void 0 : _res$data$contact.contactId).toBe(mockContactResponse.contactId);
          expect(infoSpy).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactType: ").concat(contact.contactType), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          expect(logSpy).toBeCalledWith("Contact successfully created", {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          expect(logSpy).not.toBeCalledWith('Created a KRO and encryptionKeyUrl', {
            file: _constants2.CONTACTS_CLIENT,
            method: 'createNewEncryptionKeyUrl'
          });
          expect(logSpy).not.toBeCalledWith('Created a KRO and encryptionKeyUrl', {
            file: _constants2.CONTACTS_CLIENT,
            method: 'createNewEncryptionKeyUrl'
          });
          expect(infoSpy).not.toBeCalledWith("Creating a default group: ".concat(_constants2.DEFAULT_GROUP_NAME), {
            file: _constants2.CONTACTS_CLIENT,
            method: 'fetchEncryptionKeyUrl'
          });
          expect(webex.internal.encryption.encryptText).toBeCalledOnceWith(_contactFixtures.mockContactGroupListOne[0].encryptionKeyUrl, contact.displayName);
          expect(webex.request).toBeCalledOnceWith({
            body: _objectSpread(_objectSpread({}, contact), {}, {
              displayName: 'Encrypted contact name',
              groups: [_contactFixtures.mockContactGroupListOne[0].groupId],
              schemas: _constants2.CONTACTS_SCHEMA
            }),
            uri: contactServiceUrl,
            method: _types.HTTP_METHODS.POST
          });
          logSpy.mockClear();

          /* for coverage */
          _context8.next = 2;
          return contactClient.createContact(contact);
        case 2:
          result = _context8.sent;
          expect((_result$data$contact = result.data.contact) === null || _result$data$contact === void 0 ? void 0 : _result$data$contact.contactId).toBe(mockContactResponse.contactId);
          expect(logSpy).not.toBeCalledWith("Creating a default group: ".concat(_constants2.DEFAULT_GROUP_NAME), {
            file: _constants2.CONTACTS_CLIENT,
            method: 'fetchEncryptionKeyUrl'
          });
        case 3:
        case "end":
          return _context8.stop();
      }
    }, _callee8);
  })));
  it('create a contact without a group and encryptionKey', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
    var _res$data$contact2;
    var mockContactResponse, successContactGroupResponsePayload, successContactResponsePayload, contact, res;
    return _regenerator.default.wrap(function (_context9) {
      while (1) switch (_context9.prev = _context9.next) {
        case 0:
          mockContactResponse = _contactFixtures.mockContactResponseBodyOne.contacts[1];
          contactClient['groups'] = [];
          contactClient['encryptionKey'] = '';
          contactClient['defaultGroupId'] = '';
          successContactGroupResponsePayload = {
            statusCode: 201,
            body: mockGroupResponse
          };
          successContactResponsePayload = {
            statusCode: 201,
            body: mockContactResponse
          };
          webex.request.mockResolvedValueOnce(successContactGroupResponsePayload).mockResolvedValueOnce(successContactResponsePayload);
          webex.internal.encryption.kms.createUnboundKeys.mockResolvedValue([_contactFixtures.mockKmsKey]);
          webex.internal.encryption.kms.createResource.mockResolvedValue(_contactFixtures.mockKmsKey);
          webex.internal.encryption.encryptText.mockResolvedValueOnce('Encrypted group name');
          contact = {
            contactType: 'CUSTOM'
          };
          _context9.next = 1;
          return contactClient.createContact(contact);
        case 1:
          res = _context9.sent;
          expect(res.statusCode).toEqual(201);
          expect(webex.request).toBeCalledTimes(2);
          expect(webex.request).toHaveBeenNthCalledWith(1, {
            body: {
              displayName: 'Encrypted group name',
              encryptionKeyUrl: _contactFixtures.mockKmsKey.uri,
              groupType: 'NORMAL',
              schemas: _constants2.CONTACTS_SCHEMA
            },
            uri: contactServiceGroupUrl,
            method: _types.HTTP_METHODS.POST
          });
          expect(webex.request).toHaveBeenNthCalledWith(2, {
            body: {
              contactType: 'CUSTOM',
              encryptionKeyUrl: _contactFixtures.mockKmsKey.uri,
              groups: ['1561977e-3443-4ccf-a591-69686275d7d2'],
              schemas: _constants2.CONTACTS_SCHEMA
            },
            method: _types.HTTP_METHODS.POST,
            uri: contactServiceUrl
          });
          expect(webex.internal.encryption.kms.createUnboundKeys).toBeCalledOnceWith({
            count: 1
          });
          expect(webex.internal.encryption.kms.createResource).toBeCalledOnceWith({
            keyUris: [_contactFixtures.mockKmsKey.uri]
          });
          expect((_res$data$contact2 = res.data.contact) === null || _res$data$contact2 === void 0 ? void 0 : _res$data$contact2.contactId).toBe(mockContactResponse.contactId);
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactType: CUSTOM"), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          expect(_Logger.default.info).toBeCalledWith(_constants.METHOD_START_MESSAGE, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_NEW_ENCRYPTION_KEY_URL
          });
          expect(_Logger.default.info).toBeCalledWith('Requesting kms for a new KRO and key', {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_NEW_ENCRYPTION_KEY_URL
          });
          expect(_Logger.default.log).toBeCalledWith("Creating a default group: ".concat(_constants2.DEFAULT_GROUP_NAME), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.FETCH_ENCRYPTION_KEY_URL
          });
          expect(_Logger.default.log).toBeCalledWith("Contact successfully created", {
            file: _constants2.CONTACTS_CLIENT,
            method: 'createContact'
          });
        case 2:
        case "end":
          return _context9.stop();
      }
    }, _callee9);
  })));
  it('create a cloud contact with no existing groups', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee0() {
    var _res$data$contact3;
    var mockContactResponse, successResponsePayload, successResponsePayloadGroup, contact, res;
    return _regenerator.default.wrap(function (_context0) {
      while (1) switch (_context0.prev = _context0.next) {
        case 0:
          mockContactResponse = _contactFixtures.mockContactResponseBodyOne.contacts[0];
          successResponsePayload = {
            statusCode: 201,
            body: mockContactResponse
          };
          successResponsePayloadGroup = {
            statusCode: 201,
            body: _contactFixtures.mockContactResponseBodyOne.groups[0]
          };
          webex.request.mockResolvedValueOnce(successResponsePayloadGroup).mockResolvedValueOnce(successResponsePayload).mockResolvedValueOnce(_contactFixtures.mockSCIMListResponse);
          webex.internal.encryption.encryptText.mockResolvedValueOnce('Encrypted group name');
          contactClient['groups'] = [];
          contactClient['encryptionKeyUrl'] = _contactFixtures.mockContactResponseBodyOne.groups[0].encryptionKeyUrl;
          contact = {
            contactType: 'CLOUD'
          };
          contact.groups = [];
          _context0.next = 1;
          return contactClient.createContact(contact);
        case 1:
          res = _context0.sent;
          expect(res.statusCode).toEqual(400);
          expect(res.data.error).toEqual('contactId is required for contactType:CLOUD.');
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactType: CLOUD"), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          contact.contactId = mockContactResponse.contactId;
          _context0.next = 2;
          return contactClient.createContact(contact);
        case 2:
          res = _context0.sent;
          expect(res.statusCode).toEqual(201);
          expect((_res$data$contact3 = res.data.contact) === null || _res$data$contact3 === void 0 ? void 0 : _res$data$contact3.contactId).toBe(mockContactResponse.contactId);
          expect(webex.request).toBeCalledTimes(3);
          expect(webex.request).toHaveBeenNthCalledWith(1, {
            method: _types.HTTP_METHODS.POST,
            uri: contactServiceGroupUrl,
            body: {
              displayName: 'Encrypted group name',
              groupType: 'NORMAL',
              encryptionKeyUrl: _contactFixtures.mockContactResponseBodyOne.groups[0].encryptionKeyUrl,
              schemas: _constants2.CONTACTS_SCHEMA
            }
          });
          expect(webex.request).toHaveBeenNthCalledWith(2, {
            method: _types.HTTP_METHODS.POST,
            uri: contactServiceUrl,
            body: {
              contactId: mockContactResponse.contactId,
              contactType: 'CLOUD',
              encryptionKeyUrl: _contactFixtures.mockContactResponseBodyOne.groups[0].encryptionKeyUrl,
              schemas: _constants2.CONTACTS_SCHEMA,
              groups: ['1561977e-3443-4ccf-a591-69686275d7d2']
            }
          });
          expect(webex.request).toHaveBeenNthCalledWith(3, {
            uri: scimUrl,
            method: _types.HTTP_METHODS.GET,
            headers: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _constants3.CISCO_DEVICE_URL, 'https://wdm-intb.ciscospark.com/wdm/api/v1/devices/c5ae3b86-1bb7-40f1-a6a9-c296ee7e61d5'), 'spark-user-agent', 'webex-calling/beta')
          });
          expect(_Logger.default.log).toBeCalledWith("Contact successfully created", {
            file: _constants2.CONTACTS_CLIENT,
            method: 'createContact'
          });
        case 3:
        case "end":
          return _context0.stop();
      }
    }, _callee0);
  })));
  it('create a contact - service unavailable', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee1() {
    var contact, res;
    return _regenerator.default.wrap(function (_context1) {
      while (1) switch (_context1.prev = _context1.next) {
        case 0:
          webex.request.mockRejectedValue(failureResponsePayload);
          contactClient['groups'] = _contactFixtures.mockContactGroupListOne.slice();
          contactClient['encryptionKeyUrl'] = _contactFixtures.mockContactResponseBodyOne.groups[0].encryptionKeyUrl;
          contact = {
            contactType: 'CLOUD',
            contactId: '801bb994-343b-4f6b-97ae-d13c91d4b877'
          };
          _context1.next = 1;
          return contactClient.createContact(contact);
        case 1:
          res = _context1.sent;
          expect(webex.request).toBeCalledOnceWith({
            uri: contactServiceUrl,
            method: _types.HTTP_METHODS.POST,
            body: _objectSpread(_objectSpread({}, contact), {}, {
              encryptionKeyUrl: _contactFixtures.mockContactResponseBodyOne.groups[0].encryptionKeyUrl,
              groups: [_contactFixtures.mockContactGroupListOne[0].groupId],
              schemas: _constants2.CONTACTS_SCHEMA
            })
          });
          expect(serviceErrorCodeHandlerSpy).toBeCalledOnceWith(failureResponsePayload, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          expect(res.statusCode).toEqual(503);
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactType: CLOUD"), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
          expect(_Logger.default.error).toBeCalledWith("Failed to create contact: ".concat((0, _stringify.default)(failureResponsePayload)), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.CREATE_CONTACT
          });
        case 2:
        case "end":
          return _context1.stop();
      }
    }, _callee1);
  })));
  it('successful deletion of contacts', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee10() {
    var successResponsePayload, response;
    return _regenerator.default.wrap(function (_context10) {
      while (1) switch (_context10.prev = _context10.next) {
        case 0:
          successResponsePayload = {
            statusCode: 204
          };
          contactClient['contacts'] = [_contactFixtures.mockContactListOne[0]];
          webex.request.mockResolvedValue(successResponsePayload);
          _context10.next = 1;
          return contactClient.deleteContact(_contactFixtures.mockContactListOne[0].contactId);
        case 1:
          response = _context10.sent;
          expect(response.statusCode).toEqual(204);
          expect(webex.request).toBeCalledOnceWith({
            uri: "".concat(contactServiceUrl, "/").concat(_contactFixtures.mockContactListOne[0].contactId),
            method: _types.HTTP_METHODS.DELETE
          });
          expect(contactClient['contacts']).toEqual([]);
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactId: ").concat(_contactFixtures.mockContactListOne[0].contactId), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.DELETE_CONTACT
          });
          expect(_Logger.default.info).toBeCalledWith("Deleting contact : ".concat(_contactFixtures.mockContactListOne[0].contactId), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.DELETE_CONTACT
          });
        case 2:
        case "end":
          return _context10.stop();
      }
    }, _callee10);
  })));
  it('delete a contact - service unavailable', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee11() {
    var response;
    return _regenerator.default.wrap(function (_context11) {
      while (1) switch (_context11.prev = _context11.next) {
        case 0:
          contactClient['contacts'] = _contactFixtures.mockContactListOne;
          webex.request.mockRejectedValue(failureResponsePayload);
          _context11.next = 1;
          return contactClient.deleteContact(_contactFixtures.mockContactListOne[0].contactId);
        case 1:
          response = _context11.sent;
          expect(response.statusCode).toEqual(503);
          expect(webex.request).toBeCalledOnceWith({
            uri: "".concat(contactServiceUrl, "/").concat(_contactFixtures.mockContactListOne[0].contactId),
            method: _types.HTTP_METHODS.DELETE
          });
          expect(serviceErrorCodeHandlerSpy).toBeCalledOnceWith(failureResponsePayload, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.DELETE_CONTACT
          });
          expect(contactClient['contacts']).toEqual(_contactFixtures.mockContactListOne);
          expect(_Logger.default.info).toBeCalledWith("".concat(_constants.METHOD_START_MESSAGE, " with contactId: ").concat(_contactFixtures.mockContactListOne[0].contactId), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.DELETE_CONTACT
          });
          expect(_Logger.default.info).toBeCalledWith("Deleting contact : ".concat(_contactFixtures.mockContactListOne[0].contactId), {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.DELETE_CONTACT
          });
        case 2:
        case "end":
          return _context11.stop();
      }
    }, _callee11);
  })));
  it('test resolveContacts function for a minimal contact with few details', function () {
    var contact = contactClient['resolveCloudContacts']({
      userId: _contactFixtures.mockContactMinimum
    }, _contactFixtures.mockSCIMMinListResponse.body);
    expect(contact).toEqual([{
      avatarURL: '',
      avatarUrlDomain: undefined,
      contactId: 'userId',
      contactType: 'CLOUD',
      department: undefined,
      displayName: undefined,
      emails: undefined,
      encryptionKeyUrl: 'kms://cisco.com/keys/dcf18f9d-155e-44ff-ad61-c8a69b7103ab',
      firstName: undefined,
      groups: ['1561977e-3443-4ccf-a591-69686275d7d2'],
      lastName: undefined,
      manager: undefined,
      ownerId: 'ownerId',
      phoneNumbers: undefined,
      sipAddresses: undefined,
      resolved: true
    }]);
  });
  it("test resolveContacts function when contactsDataMap list doesn't match resolved list", function () {
    var mockContact = {
      firstName: 'Jane',
      lastName: 'Doe',
      contactId: 'janeDoe'
    };
    var contact = contactClient['resolveCloudContacts']({
      userId: _contactFixtures.mockContactMinimum,
      janeDoe: mockContact
    }, _contactFixtures.mockSCIMMinListResponse.body);
    expect(contact).toEqual([{
      firstName: 'Jane',
      lastName: 'Doe',
      contactId: 'janeDoe',
      resolved: false
    }, {
      avatarURL: '',
      avatarUrlDomain: undefined,
      contactId: 'userId',
      contactType: 'CLOUD',
      department: undefined,
      displayName: undefined,
      emails: undefined,
      encryptionKeyUrl: 'kms://cisco.com/keys/dcf18f9d-155e-44ff-ad61-c8a69b7103ab',
      firstName: undefined,
      groups: ['1561977e-3443-4ccf-a591-69686275d7d2'],
      lastName: undefined,
      manager: undefined,
      ownerId: 'ownerId',
      phoneNumbers: undefined,
      sipAddresses: undefined,
      resolved: true
    }]);
  });
  it('test resolveContacts function encountering an error', function () {
    var warnSpy = jest.spyOn(_Logger.default, 'warn');
    var contact = contactClient['resolveCloudContacts']({
      userId: _contactFixtures.mockContactMinimum
    }, _contactFixtures.mockSCIMMinListResponse);
    expect(contact).toEqual(null);
    expect(warnSpy).toHaveBeenCalledWith('Error occurred while parsing resolved contacts', {
      file: _constants2.CONTACTS_CLIENT,
      method: 'resolveCloudContacts'
    });
  });
  it('logs error for chunk when scimQuery API call fails in the loop for getContacts', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee12() {
    var mockData, respPayload, warnSpy, infoSpy, logSpy;
    return _regenerator.default.wrap(function (_context12) {
      while (1) switch (_context12.prev = _context12.next) {
        case 0:
          mockData = errorCodes[0];
          respPayload = {
            statusCode: mockData.inputStatusCode,
            body: mockData.payloadData
          };
          webex.request.mockResolvedValueOnce(respPayload).mockRejectedValueOnce(_objectSpread(_objectSpread({}, respPayload), {}, {
            statusCode: 503,
            message: _constants.FAILURE_MESSAGE,
            data: mockData.payloadData
          }));
          mockData.decryptTextList.forEach(function (text) {
            webex.internal.encryption.decryptText.mockResolvedValueOnce(text);
          });
          warnSpy = jest.spyOn(_Logger.default, 'warn');
          infoSpy = jest.spyOn(_Logger.default, 'info');
          logSpy = jest.spyOn(_Logger.default, 'log');
          _context12.next = 1;
          return contactClient.getContacts();
        case 1:
          expect(webex.request).toBeCalledTimes(2);
          expect(warnSpy).toBeCalledTimes(1);
          expect(warnSpy).toBeCalledWith('Error processing contact chunk 0-50', {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.GET_CONTACTS
          });
          expect(infoSpy).toBeCalledWith(_constants.METHOD_START_MESSAGE, {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.GET_CONTACTS
          });
          expect(logSpy).toBeCalledWith('Successfully fetched contacts and groups', {
            file: _constants2.CONTACTS_CLIENT,
            method: _constants2.METHODS.GET_CONTACTS
          });
        case 2:
        case "end":
          return _context12.stop();
      }
    }, _callee12);
  })));
});
//# sourceMappingURL=ContactsClient.test.js.map
