Skip to content

Commit

Permalink
test(signature): tests related to the signature API
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Coeurderoy committed Sep 16, 2020
1 parent 02afc0d commit b246840
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/samples/folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Holder, IFolder } from '../../src';

export const folderSample: IFolder = {
id: '5f61d3bf3b9e4d2ad7b4b251',
state: 0,
createdAt: new Date('2020-09-16T08:58:39.471+0000'),
legalDocuments: [],
supportingDocuments: [],
updatedAt: new Date('2020-09-16T08:58:39.479+0000'),
expiredAt: new Date('2020-10-16T08:58:39.472+0000'),
signatures: [
{
id: 'sign_id',
partnerId: 'partner_id',
legalDocumentIds: ['docId'],
createdAt: new Date('2020-08-14T10:14:20.224+0000'),
state: 0,
holder: Holder.APPLICANT,
},
],
};
85 changes: 85 additions & 0 deletions test/signature.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as nock from 'nock';

import { RequestBuilder } from '../src/RequestBuilder';
import { Holder, ISignature, Signature, SignatureState } from '../src';
import { getFakeAlgoanServer, getOAuthServer } from './utils/fake-server.utils';
import { folderSample } from './samples/folder';

describe('Tests related to the Application class', () => {
const baseUrl: string = 'http://localhost:3000';
let signatureAPI: nock.Scope;
let requestBuilder: RequestBuilder;

beforeEach(() => {
getOAuthServer({
baseUrl,
isRefreshToken: false,
isUserPassword: false,
nbOfCalls: 1,
expiresIn: 500,
refreshExpiresIn: 2000,
});
requestBuilder = new RequestBuilder(baseUrl, {
clientId: 'a',
clientSecret: 's',
});
});

afterEach(() => {
jest.clearAllMocks();
nock.cleanAll();
});

describe('static createSignature()', () => {
beforeEach(() => {
signatureAPI = getFakeAlgoanServer({
baseUrl,
path: `/v1/folders/${folderSample.id}/signatures`,
response: {
state: 0,
legalDocumentIds: ['random_legal_id'],
id: '5f3663fc3ec5884afc8ed04f',
partnerId: 'SIGN_ID',
holder: 'APPLICANT',
createdAt: '2020-08-14T10:14:20.224+0000',
},
method: 'post',
});
});
it('should create a signature', async () => {
const signature: ISignature = await Signature.create(requestBuilder, folderSample.id, {
partnerId: 'SIGN_ID',
legalDocumentIds: ['random_legal_id'],
holder: Holder.APPLICANT,
});
expect(signatureAPI.isDone()).toBeTruthy();
expect(signature).toBeInstanceOf(Signature);
expect(signature.id).toEqual('5f3663fc3ec5884afc8ed04f');
expect(signature.legalDocumentIds).toEqual(['random_legal_id']);
expect(signature.partnerId).toEqual('SIGN_ID');
expect(signature.holder).toEqual('APPLICANT');
expect(signature.createdAt).toEqual(new Date('2020-08-14T10:14:20.224+0000'));
});
});

describe('update()', () => {
beforeEach(() => {
signatureAPI = getFakeAlgoanServer({
baseUrl,
path: `/v1/folders/${folderSample.id}/signatures/${folderSample.signatures[0].id}`,
response: { ...folderSample.signatures[0], state: SignatureState.SIGNED },
method: 'patch',
});
});
it('should update the Signature', async () => {
const signature: Signature = new Signature(folderSample.id, folderSample.signatures[0], requestBuilder);

await signature.update({
state: SignatureState.SIGNED,
});

expect(signatureAPI.isDone()).toBeTruthy();
expect(signature.state).toEqual(4);
});
});
});

0 comments on commit b246840

Please sign in to comment.