Skip to content

Commit

Permalink
DEVEXP-522: E2E Verification/Status (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Aug 28, 2024
1 parent 0a321c1 commit b0071d9
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tsconfig.build.tsbuildinfo
tsconfig.tsbuildinfo
packages/**/dist
.env
*.feature

This file was deleted.

4 changes: 2 additions & 2 deletions packages/verification/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export * from './sms-verification-report-response';
export * from './sms-verification-status-response';
// Models associated to PhoneCall verification workflow
export * from './start-phonecall-verification-response';
export * from './callout-verification-report-response';
export * from './callout-verification-status-response';
export * from './phonecall-verification-report-response';
export * from './phonecall-verification-status-response';
// Models associated to Flashcall verification workflow
export * from './start-flashcall-verification-response';
export * from './flashcall-verification-report-response';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type {
PhoneCallVerificationReportResponse,
CalloutVerificationReportResponse,
} from './callout-verification-report-response';
} from './phonecall-verification-report-response';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type {
PhoneCallVerificationStatusResponse,
CalloutVerificationStatusResponse,
} from './phonecall-verification-status-response';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { CallResult, ReasonEnum, VerificationStatusEnum } from '../enums';
import { Identity } from '../identity';
import { VerificationPriceCall } from '../verification-price-call';

export interface CalloutVerificationStatusResponse {
/** @deprecated */
export type CalloutVerificationStatusResponse = PhoneCallVerificationStatusResponse;

export interface PhoneCallVerificationStatusResponse {
/** The unique ID of the verification request. */
id?: string;
/** The method of the verification request. This will always be `callout`. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface VerificationStatusByIdentityRequestData {
/** For type `number` use a [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537)-compatible phone number. */
'endpoint': string;
/** The method of the verification. */
'method': 'sms' | 'callout' | 'flashcall';
// TODO v2.0 - Remove 'callout' option
'method': 'sms' | 'callout' | 'phonecall' | 'flashcall';
}
export interface VerificationStatusByReferenceRequestData {
/** The custom reference of the verification. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { SmsVerificationStatusResponse } from '../sms-verification-status-response';
import { FlashCallVerificationStatusResponse } from '../flashcall-verification-status-response';
import { CalloutVerificationStatusResponse } from '../callout-verification-status-response';
import {
CalloutVerificationStatusResponse,
PhoneCallVerificationStatusResponse,
} from '../phonecall-verification-status-response';

export type VerificationStatusResponse = SmsVerificationStatusResponse
| FlashCallVerificationStatusResponse
| CalloutVerificationStatusResponse;
| CalloutVerificationStatusResponse
| PhoneCallVerificationStatusResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ export class VerificationStatusApi extends VerificationDomainApi {
'Accept': 'application/json',
};

let verificationMethod = data['method'];
if (verificationMethod === 'phonecall') {
verificationMethod = 'callout';
}

const body: RequestBody = '';
const path = `/verification/v1/verifications/${data['method']}/number/${data['endpoint']}`;
const path = `/verification/v1/verifications/${verificationMethod}/number/${data['endpoint']}`;
const basePathUrl = this.client.apiClientOptions.hostname + path;

const requestOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('VerificationStatusApi', () => {
endpoint: '+33444555666',
method: 'callout',
};
const expectedResponse: Verification.CalloutVerificationStatusResponse = {
const expectedResponse: Verification.PhoneCallVerificationStatusResponse = {
id: '018bec2b-d123-b7b3-833e-4b177e3420df',
method: 'callout',
status: 'FAIL',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { VerificationStatusApi, VerificationService, Verification } from '../../../../src';
import { Given, When, Then } from '@cucumber/cucumber';
import * as assert from 'assert';

let verificationStatusApi: VerificationStatusApi;
let smsVerificationStatus: Verification.SmsVerificationStatusResponse;
let phoneCallVerificationStatus: Verification.PhoneCallVerificationStatusResponse;
let flashCallVerificationStatus: Verification.FlashCallVerificationStatusResponse;

Given('the Verification service "Status" is available', () => {
const verificationService = new VerificationService({
applicationKey: 'appKey',
applicationSecret: 'appSecret',
verificationHostname: 'http://localhost:3018',
});
verificationStatusApi = verificationService.verificationStatus;
});

When('I send a request to retrieve a SMS verification status by its verification ID', async () => {
smsVerificationStatus = await verificationStatusApi.getById({
id: '1ce0ffee-c0de-5eed-d00d-f00dfeed1337',
}) as Verification.SmsVerificationStatusResponse;
});

Then('the response contains the details of the SMS verification status', () => {
assert.equal(smsVerificationStatus.id, '1ce0ffee-c0de-5eed-d00d-f00dfeed1337');
assert.equal(smsVerificationStatus.method, 'sms');
const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL';
assert.equal(smsVerificationStatus.status, successfulStatus);
const verificationPrice: Verification.VerificationPriceSms = {
verificationPrice: {
currencyId: 'EUR',
amount: 0.0453,
},
};
assert.deepEqual(smsVerificationStatus.price, verificationPrice);
const identity: Verification.Identity = {
type: 'number',
endpoint: '+33612345678',
};
assert.deepEqual(smsVerificationStatus.identity, identity);
assert.equal(smsVerificationStatus.countryId, 'FR');
assert.deepEqual(smsVerificationStatus.verificationTimestamp, new Date('2024-06-06T09:08:41.4784877Z'));
});

When('I send a request to retrieve a Phone Call verification status by the phone number to verify', async () => {
phoneCallVerificationStatus = await verificationStatusApi.getByIdentity({
method: 'phonecall',
endpoint: '+33612345678',
}) as Verification.PhoneCallVerificationStatusResponse;
});

Then('the response contains the details of the Phone Call verification status', () => {
assert.equal(phoneCallVerificationStatus.id, '1ce0ffee-c0de-5eed-d11d-f00dfeed1337');
assert.equal(phoneCallVerificationStatus.method, 'callout');
const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL';
assert.equal(phoneCallVerificationStatus.status, successfulStatus);
const verificationPrice: Verification.VerificationPriceCall = {
verificationPrice: {
currencyId: 'EUR',
amount: 0.1852,
},
terminationPrice: {
currencyId: 'EUR',
amount: 0,
},
};
assert.deepEqual(phoneCallVerificationStatus.price, verificationPrice);
const identity: Verification.Identity = {
type: 'number',
endpoint: '+33612345678',
};
assert.deepEqual(phoneCallVerificationStatus.identity, identity);
assert.equal(phoneCallVerificationStatus.countryId, 'FR');
assert.deepEqual(phoneCallVerificationStatus.verificationTimestamp, new Date('2024-06-06T09:10:27.7264837Z'));
assert.equal(phoneCallVerificationStatus.callComplete, true);
const answeredCallResult: Verification.CallResult = 'ANSWERED';
assert.equal(phoneCallVerificationStatus.callResult, answeredCallResult);
});

When('I send a request to retrieve a Flash Call verification status by its reference', async () => {
flashCallVerificationStatus = await verificationStatusApi.getByReference({
reference: 'flashcall-verification-test-e2e',
}) as Verification.FlashCallVerificationReportResponse;
});

Then('the response contains the details of the Flash Call verification status', () => {
assert.equal(flashCallVerificationStatus.id, '1ce0ffee-c0de-5eed-d22d-f00dfeed1337');
assert.equal(flashCallVerificationStatus.method, 'flashcall');
const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL';
assert.equal(flashCallVerificationStatus.status, successfulStatus);
assert.equal(flashCallVerificationStatus.reference, 'flashcall-verification-test-e2e');
const verificationPrice: Verification.VerificationPriceCall = {
verificationPrice: {
currencyId: 'EUR',
amount: 0.0205,
},
terminationPrice: {
currencyId: 'EUR',
amount: 0,
},
};
assert.deepEqual(flashCallVerificationStatus.price, verificationPrice);
const identity: Verification.Identity = {
type: 'number',
endpoint: '+33612345678',
};
assert.deepEqual(flashCallVerificationStatus.identity, identity);
assert.equal(flashCallVerificationStatus.countryId, 'FR');
assert.deepEqual(flashCallVerificationStatus.verificationTimestamp, new Date('2024-06-06T09:07:32.3554646Z'));
assert.equal(flashCallVerificationStatus.callComplete, true);
const answeredCallResult: Verification.CallResult = 'ANSWERED';
assert.equal(flashCallVerificationStatus.callResult, answeredCallResult);
});

0 comments on commit b0071d9

Please sign in to comment.