Skip to content

Commit

Permalink
feat(verify2): adding cancel method (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck authored May 22, 2023
1 parent 3e04e19 commit 365d4b8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/verify2/__tests__/__dataSets__/cancel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default [
{
label: 'cancel request',
request: ['/v2/verify/091e717f-8715-41a0-a3f0-cc04912deaa1', 'DELETE'],
response: [204],
method: 'post',
clientMethod: 'cancel',
parameters: ['091e717f-8715-41a0-a3f0-cc04912deaa1'],
expected: true,
},
{
label: 'error when request not found',
request: ['/v2/verify/091e717f-8715-41a0-a3f0-cc04912deaa1', 'DELETE'],
response: [
404,
{
title: 'Not Found',
type: 'https://developer.vonage.com/api-errors#not-found',
detail: 'Request <id> was not found or it has been verified already.',
instance: 'bf0ca0bf927b3b52e3cb03217e1a1ddf',
},
],
method: 'delete',
clientMethod: 'cancel',
parameters: ['091e717f-8715-41a0-a3f0-cc04912deaa1'],
expected: false,
},
];
5 changes: 5 additions & 0 deletions packages/verify2/__tests__/__dataSets__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requestTests from './verify';
import checkTests from './check';
import cancelTests from './cancel';

export default [
{
Expand All @@ -10,4 +11,8 @@ export default [
label: 'Check tests',
tests: checkTests,
},
{
label: 'Cancel tests',
tests: cancelTests,
},
];
11 changes: 11 additions & 0 deletions packages/verify2/lib/verify2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ export class Verify2 extends Client {

return resp.data.status;
}

public async cancel(requestId: string): Promise<boolean> {
try {
await this.sendDeleteRequest(
`${this.config.apiHost}/v2/verify/${requestId}`,
);
return true;
} catch (error) {
return false;
}
}
}

0 comments on commit 365d4b8

Please sign in to comment.