Skip to content

Commit

Permalink
chore: added error related test cases for pda
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Jan 18, 2024
1 parent 2cb5737 commit cfc55f2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions test/pda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe('PDA SERVICE TESTING', () => {
expect(createPDAMutationMock).toHaveBeenCalled();
});

it('pda create to throw error', async () => {
const { createPDAMock: createPDAMutationMock } = PDAMockService(pda);

expect(
async () => await pda.createPDA(pdaCreateStub({ title: '' })),
).rejects.toThrow(' should be atleast 3 length');

expect(createPDAMutationMock).toHaveBeenCalled();
});

it('pda update status', async () => {
const { changePDAStatusMock } = PDAMockService(pda);

Expand All @@ -36,6 +46,20 @@ describe('PDA SERVICE TESTING', () => {
expect(changePDAStatusMock).toHaveBeenCalled();
});

it('pda update status to throw error', async () => {
const { changePDAStatusMock } = PDAMockService(pda);

expect(
async () =>
await pda.changePDAStatus({
id: pdaStub({ id: 'f17ac10b-58cc-4372-a567' }).id,
status: PDAStatus.Suspended,
}),
).rejects.toThrow('');

expect(changePDAStatusMock).toHaveBeenCalled();
});

it('get pda', async () => {
const { getPDAMock } = PDAMockService(pda);

Expand Down Expand Up @@ -96,4 +120,18 @@ describe('PDA SERVICE TESTING', () => {
expect(updatePDA.dataAsset?.title).toBe(pdaStub().dataAsset?.title);
expect(updatePDAMock).toHaveBeenCalled();
});

it('update pda to throw error', async () => {
const { updatePDAMock } = PDAMockService(pda);

expect(
async () =>
await pda.updatePDA({
id: pdaStub().id,
title: pdaCreateStub({ title: '' }).title,
}),
).rejects.toThrow('');

expect(updatePDAMock).toHaveBeenCalled();
});
});
3 changes: 2 additions & 1 deletion test/stubs/pda.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const pdaStub = (overridePDA?: any): PrivateDataAsset => ({
...overridePDA,
});

export const pdaCreateStub = (): CreatePDAInput => ({
export const pdaCreateStub = (overridePDA?: any): CreatePDAInput => ({
dataModelId: 'f47ac10b-58cc-4372-a567-0e02b2c3d471',
description: 'test',
title: 'test',
Expand All @@ -38,4 +38,5 @@ export const pdaCreateStub = (): CreatePDAInput => ({
value: 'sid',
},
expirationDate: new Date('2021-01-01T12:00:0'),
...overridePDA,
});

0 comments on commit cfc55f2

Please sign in to comment.