boldsign
Version:
NodeJS client for boldsign
148 lines (115 loc) • 5.53 kB
text/typescript
import { SenderIdentitiesApi } from '../../api/senderIdentitiesApi'; // Adjust path accordingly
import * as sinon from 'sinon';
describe('SenderIdentityApi Unit Test', () => {
let senderIdentityApiStub: sinon.SinonStubbedInstance<SenderIdentitiesApi>;
beforeEach(() => {
senderIdentityApiStub = sinon.createStubInstance(SenderIdentitiesApi);
// Stub the methods (e.g., createSenderIdentity, updateSenderIdentity) for SenderIdentityApi
senderIdentityApiStub.createSenderIdentity = sinon.stub().resolves({ senderIdentityId: 'sender_identity_id' });
senderIdentityApiStub.updateSenderIdentity = sinon.stub().resolves({
success: true,
message: 'Sender identity updated successfully',
});
});
afterEach(() => {
// Restore original functionality after each test
sinon.restore();
});
it('should mock and verify createSenderIdentity call', async () => {
const mockSenderIdentityCreated = {
senderIdentityId: 'sender_identity_id',
};
const senderIdentityData = {
name: 'New Sender Identity',
email: 'senderEmail@example.com',
phoneNumber: '9876543210',
companyName: 'Syncfusion',
};
senderIdentityApiStub.createSenderIdentity.resolves(mockSenderIdentityCreated);
const result = await senderIdentityApiStub.createSenderIdentity(senderIdentityData);
expect(result).toBeDefined();
expect(result.senderIdentityId).toBe('sender_identity_id');
sinon.assert.calledOnceWithExactly(senderIdentityApiStub.createSenderIdentity, senderIdentityData);
});
it('should mock and verify updateSenderIdentity call', async () => {
const mockUpdatedSenderIdentity = {
success: true,
message: 'Sender identity updated successfully',
};
const senderIdentityId = 'sender_identity_id';
const updatedSenderIdentityData = {
name: 'Updated Sender Identity',
email: 'updatedSenderEmail@example.com',
phoneNumber: '1234567890',
companyName: 'Updated Syncfusion',
};
senderIdentityApiStub.updateSenderIdentity.resolves(mockUpdatedSenderIdentity);
const result = await senderIdentityApiStub.updateSenderIdentity(senderIdentityId, updatedSenderIdentityData);
expect(result).toBeDefined();
expect(result.success).toBe(true);
expect(result.message).toBe('Sender identity updated successfully');
sinon.assert.calledOnceWithExactly(
senderIdentityApiStub.updateSenderIdentity,
senderIdentityId,
updatedSenderIdentityData
);
});
it('should mock and verify deleteSenderIdentity call', async () => {
const mockDeleteResponse = {
success: true,
message: 'Sender identity deleted successfully',
};
const senderIdentityId = 'sender_identity_id';
senderIdentityApiStub.deleteSenderIdentity = sinon.stub().resolves(mockDeleteResponse);
const result = await senderIdentityApiStub.deleteSenderIdentity(senderIdentityId);
expect(result).toBeDefined();
expect(result.success).toBe(true);
expect(result.message).toBe('Sender identity deleted successfully');
sinon.assert.calledOnceWithExactly(
senderIdentityApiStub.deleteSenderIdentity,
senderIdentityId
);
});
it('should mock and verify resendInvitationSenderIdentity call', async () => {
const mockResendResponse = {
success: true,
message: 'Invitation resent successfully',
};
const senderIdentityId = 'sender_identity_id';
senderIdentityApiStub.resendInvitationSenderIdentity = sinon.stub().resolves(mockResendResponse);
const result = await senderIdentityApiStub.resendInvitationSenderIdentity(senderIdentityId);
expect(result).toBeDefined();
expect(result.success).toBe(true);
expect(result.message).toBe('Invitation resent successfully');
sinon.assert.calledOnceWithExactly(
senderIdentityApiStub.resendInvitationSenderIdentity,
senderIdentityId
);
});
it('should mock and verify listSenderIdentities call', async () => {
const mockListResponse = {
identities: [
{
senderIdentityId: 'id_1',
name: 'Sender One',
email: 'sender1@example.com',
companyName: 'Company One',
},
{
senderIdentityId: 'id_2',
name: 'Sender Two',
email: 'sender2@example.com',
companyName: 'Company Two',
},
],
};
senderIdentityApiStub.listSenderIdentities = sinon.stub().resolves(mockListResponse);
const result = await senderIdentityApiStub.listSenderIdentities();
expect(result).toBeDefined();
expect(Array.isArray(result.identities)).toBe(true);
expect(result.identities).toHaveLength(2);
expect(result.identities[0].senderIdentityId).toBe('id_1');
expect(result.identities[1].email).toBe('sender2@example.com');
sinon.assert.calledOnce(senderIdentityApiStub.listSenderIdentities);
});
});