UNPKG

boldsign

Version:

NodeJS client for boldsign

154 lines 7.06 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const contactsApi_1 = require("../../api/contactsApi"); const sinon = __importStar(require("sinon")); describe('ContactApi Unit Test', () => { let contactApiStub; beforeEach(() => { contactApiStub = sinon.createStubInstance(contactsApi_1.ContactsApi); contactApiStub.createContact = sinon.stub().resolves({ contactId: 'contact_id' }); contactApiStub.updateContact = sinon.stub().resolves({ success: true, message: 'Contact updated successfully', }); }); afterEach(() => { sinon.restore(); }); it('should mock and verify createContact call', () => __awaiter(void 0, void 0, void 0, function* () { const mockContactCreated = { contactId: 'contact_id', }; const contactData = { name: 'New contact', email: 'newEmail@gmail.com', phoneNumber: '9876543210', jobTitle: 'Test', companyName: 'Syncfusion', }; contactApiStub.createContact.resolves(mockContactCreated); const result = yield contactApiStub.createContact(contactData); expect(result).toBeDefined(); expect(result.contactId).toBe('contact_id'); sinon.assert.calledOnceWithExactly(contactApiStub.createContact, contactData); })); it('should mock and verify listContacts call', () => __awaiter(void 0, void 0, void 0, function* () { const mockContactList = [ { contactId: 'contact_1', name: 'Contact One', email: 'contact1@example.com', }, { contactId: 'contact_2', name: 'Contact Two', email: 'contact2@example.com', }, ]; contactApiStub.listContacts = sinon.stub().resolves(mockContactList); const result = yield contactApiStub.listContacts(); expect(result).toBeDefined(); expect(result.length).toBe(2); expect(result[0].contactId).toBe('contact_1'); expect(result[0].name).toBe('Contact One'); expect(result[0].email).toBe('contact1@example.com'); sinon.assert.calledOnce(contactApiStub.listContacts); })); it('should mock and verify updateContact call', () => __awaiter(void 0, void 0, void 0, function* () { const mockUpdatedContact = { success: true, message: 'Contact updated successfully', }; const contactId = 'contact_1'; const updatedContactData = { name: 'Updated Contact One', email: 'updatedEmail@example.com', phoneNumber: '1234567890', jobTitle: 'Updated Job Title', companyName: 'Updated Company', }; contactApiStub.updateContact = sinon.stub().resolves(mockUpdatedContact); const result = yield contactApiStub.updateContact(contactId, updatedContactData); expect(result).toBeDefined(); expect(result.success).toBe(true); expect(result.message).toBe('Contact updated successfully'); sinon.assert.calledOnceWithExactly(contactApiStub.updateContact, contactId, updatedContactData); })); it('should mock and verify deleteContact call', () => __awaiter(void 0, void 0, void 0, function* () { const mockDeleteResponse = { success: true, message: 'Contact deleted successfully', }; const contactId = 'contact_1'; contactApiStub.deleteContact = sinon.stub().resolves(mockDeleteResponse); const result = yield contactApiStub.deleteContact(contactId); expect(result).toBeDefined(); expect(result.success).toBe(true); expect(result.message).toBe('Contact deleted successfully'); sinon.assert.calledOnceWithExactly(contactApiStub.deleteContact, contactId); })); it('should mock and verify getContact call', () => __awaiter(void 0, void 0, void 0, function* () { const mockContactDetails = { contactId: 'contact_1', name: 'Contact One', email: 'contact1@example.com', phoneNumber: '9876543210', jobTitle: 'Software Engineer', companyName: 'TechCorp', }; const contactId = 'contact_1'; contactApiStub.getContact = sinon.stub().resolves(mockContactDetails); const result = yield contactApiStub.getContact(contactId); expect(result).toBeDefined(); expect(result.contactId).toBe('contact_1'); expect(result.name).toBe('Contact One'); expect(result.email).toBe('contact1@example.com'); expect(result.phoneNumber).toBe('9876543210'); expect(result.jobTitle).toBe('Software Engineer'); expect(result.companyName).toBe('TechCorp'); sinon.assert.calledOnceWithExactly(contactApiStub.getContact, contactId); })); }); //# sourceMappingURL=contactsApi.spec.js.map