From 0a321c1a4a0cc9012ff96cdf7bc6c5c715004dd9 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:41:46 +0200 Subject: [PATCH] DEVEXP-521: E2E Verification/Report (#129) --- .github/workflows/run-ci.yaml | 4 + .../src/verification/app.ts | 4 +- .../verifications/data/start-seamless.ts | 2 +- .../phonecall/report-with-id_callout.ts | 1 + .../phonecall/report-with-id_phonecall.ts | 32 +++++ .../phonecall/report-with-identity_callout.ts | 1 + .../report-with-identity_phonecall.ts | 32 +++++ .../verifications/phonecall/start-callout.ts | 2 +- .../callout-verification-report-response.ts | 4 +- .../index.ts | 5 +- packages/verification/src/models/v1/helper.ts | 88 +++++++++++++ .../verifications-request-data.ts | 13 ++ .../start-verification-request.ts | 4 +- .../v1/verification-report-request/index.ts | 2 + .../verification-report-request.ts | 16 ++- .../verifications-api.jest.fixture.ts | 16 +++ .../v1/verifications/verifications-api.ts | 108 +++++++++++++++- .../rest/v1/verifications/report.steps.ts | 117 ++++++++++++++++++ .../{start => verifications}/start.steps.ts | 0 .../verifications/verifications-api.test.ts | 75 +++++++++++ 20 files changed, 516 insertions(+), 10 deletions(-) create mode 100644 examples/simple-examples/src/verification/verifications/phonecall/report-with-id_phonecall.ts create mode 100644 examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_phonecall.ts create mode 100644 packages/verification/tests/rest/v1/verifications/report.steps.ts rename packages/verification/tests/rest/v1/{start => verifications}/start.steps.ts (100%) diff --git a/.github/workflows/run-ci.yaml b/.github/workflows/run-ci.yaml index ab1da6a7..846bee5f 100644 --- a/.github/workflows/run-ci.yaml +++ b/.github/workflows/run-ci.yaml @@ -55,12 +55,16 @@ jobs: mkdir -p ./packages/numbers/tests/e2e/features mkdir -p ./packages/conversation/tests/e2e/features mkdir -p ./packages/elastic-sip-trunking/tests/e2e/features + mkdir -p ./packages/sms/tests/e2e/features + mkdir -p ./packages/verification/tests/e2e/features - name: Copy feature files run: | cp sinch-sdk-mockserver/features/fax/*.feature ./packages/fax/tests/e2e/features/ cp sinch-sdk-mockserver/features/numbers/*.feature ./packages/numbers/tests/e2e/features/ cp sinch-sdk-mockserver/features/conversation/*.feature ./packages/conversation/tests/e2e/features/ cp sinch-sdk-mockserver/features/elastic-sip-trunking/*.feature ./packages/elastic-sip-trunking/tests/e2e/features/ + cp sinch-sdk-mockserver/features/sms/*.feature ./packages/sms/tests/e2e/features/ + cp sinch-sdk-mockserver/features/verification/*.feature ./packages/verification/tests/e2e/features/ - name: Run e2e tests run: | yarn install diff --git a/examples/integrated-flows-examples/src/verification/app.ts b/examples/integrated-flows-examples/src/verification/app.ts index 138a6830..1aadd449 100644 --- a/examples/integrated-flows-examples/src/verification/app.ts +++ b/examples/integrated-flows-examples/src/verification/app.ts @@ -83,9 +83,9 @@ dotenv.config(); message: 'Enter the verification code:', }, ]); - const reportRequestData = Verification.reportVerificationByIdHelper.buildCalloutRequest( + const reportRequestData = Verification.reportVerificationByIdHelper.buildPhoneCallRequest( response.id!, answers.code); - const reportResponse = await sinch.verification.verifications.reportCalloutById(reportRequestData); + const reportResponse = await sinch.verification.verifications.reportPhoneCallById(reportRequestData); console.log(`Verification status: ${reportResponse.status}${reportResponse.status === 'SUCCESSFUL'?'':' - Reason: ' + reportResponse.reason}`); }; diff --git a/examples/simple-examples/src/verification/verifications/data/start-seamless.ts b/examples/simple-examples/src/verification/verifications/data/start-seamless.ts index f6ea52b2..e0202ba9 100644 --- a/examples/simple-examples/src/verification/verifications/data/start-seamless.ts +++ b/examples/simple-examples/src/verification/verifications/data/start-seamless.ts @@ -6,7 +6,7 @@ import { printFullResponse, } from '../../../config'; -/** @deprecated see ../../start/start-data.ts instead */ +/** @deprecated see ./start-data.ts instead */ (async () => { console.log('********************************'); console.log('* StartVerification - seamless *'); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts index 60575953..1bdaefa8 100644 --- a/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts +++ b/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts @@ -7,6 +7,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ./report-with-id_phonecall.ts instead */ (async () => { console.log('************************************'); console.log('* ReportVerificationById - callout *'); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_phonecall.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_phonecall.ts new file mode 100644 index 00000000..b4c6ec67 --- /dev/null +++ b/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_phonecall.ts @@ -0,0 +1,32 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationCodeFromConfig, + getVerificationIdFromConfig, + initVerificationService, + printFullResponse, +} from '../../../config'; + +(async () => { + console.log('**************************************'); + console.log('* ReportVerificationById - phoneCall *'); + console.log('**************************************'); + + const verificationId = getVerificationIdFromConfig(); + const verificationCode = getVerificationCodeFromConfig(); + + const requestData = Verification.reportVerificationByIdHelper.buildPhoneCallRequest( + verificationId, verificationCode); + + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportPhoneCallById(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Phone call verification status: ${response.status}${response.status === 'SUCCESSFUL'?'':' - Reason: ' + response.reason}`); + } else { + printFullResponse(response); + } + +})(); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts index 23662c77..0ae33e59 100644 --- a/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts +++ b/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts @@ -7,6 +7,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ./report-with-identity_phonecall.ts instead */ (async () => { console.log('******************************************'); console.log('* ReportVerificationByIdentity - callout *'); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_phonecall.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_phonecall.ts new file mode 100644 index 00000000..b677c8d0 --- /dev/null +++ b/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_phonecall.ts @@ -0,0 +1,32 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationCodeFromConfig, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../../config'; + +(async () => { + console.log('********************************************'); + console.log('* ReportVerificationByIdentity - phoneCall *'); + console.log('********************************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + const verificationCode = getVerificationCodeFromConfig(); + + const requestData = Verification.reportVerificationByIdentityHelper.buildPhoneCallRequest( + verificationIdentity, verificationCode); + + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportPhoneCallByIdentity(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Phone call verification status: ${response.status}${response.status === 'SUCCESSFUL'?'':' - Reason: ' + response.reason}`); + } else { + printFullResponse(response); + } + +})(); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts index 11cf58c3..d5a052a5 100644 --- a/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts +++ b/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts @@ -6,7 +6,7 @@ import { printFullResponse, } from '../../../config'; -/** @deprecated see ../../start/start-phonecall.ts instead */ +/** @deprecated see ./start-phonecall.ts instead */ (async () => { console.log('*******************************'); console.log('* StartVerification - callout *'); diff --git a/packages/verification/src/models/v1/callout-verification-report-response/callout-verification-report-response.ts b/packages/verification/src/models/v1/callout-verification-report-response/callout-verification-report-response.ts index 7e1f6b8c..a7d1af4a 100644 --- a/packages/verification/src/models/v1/callout-verification-report-response/callout-verification-report-response.ts +++ b/packages/verification/src/models/v1/callout-verification-report-response/callout-verification-report-response.ts @@ -1,8 +1,10 @@ import { ReasonEnum, SourceEnum, VerificationStatusEnum } from '../enums'; import { Identity } from '../identity'; -export interface CalloutVerificationReportResponse { +/** @deprecated */ +export type CalloutVerificationReportResponse = PhoneCallVerificationReportResponse; +export interface PhoneCallVerificationReportResponse { /** The unique ID of the verification request. */ id?: string; /** The method of the verification request. This will always be `callout`. */ diff --git a/packages/verification/src/models/v1/callout-verification-report-response/index.ts b/packages/verification/src/models/v1/callout-verification-report-response/index.ts index 864e706d..e53d47e3 100644 --- a/packages/verification/src/models/v1/callout-verification-report-response/index.ts +++ b/packages/verification/src/models/v1/callout-verification-report-response/index.ts @@ -1 +1,4 @@ -export type { CalloutVerificationReportResponse } from './callout-verification-report-response'; +export type { + PhoneCallVerificationReportResponse, + CalloutVerificationReportResponse, +} from './callout-verification-report-response'; diff --git a/packages/verification/src/models/v1/helper.ts b/packages/verification/src/models/v1/helper.ts index 817dcc9f..4d6cdbbc 100644 --- a/packages/verification/src/models/v1/helper.ts +++ b/packages/verification/src/models/v1/helper.ts @@ -3,6 +3,8 @@ import { ReportCalloutVerificationByIdRequestData, ReportFlashCallVerificationByIdentityRequestData, ReportFlashCallVerificationByIdRequestData, + ReportPhoneCallVerificationByIdentityRequestData, + ReportPhoneCallVerificationByIdRequestData, ReportSmsVerificationByIdentityRequestData, ReportSmsVerificationByIdRequestData, StartCalloutVerificationRequestData, @@ -176,6 +178,14 @@ export const startVerificationHelper = { }, }; export const reportVerificationByIdHelper = { + /** + * Builds a request object for reporting an SMS verification by its ID. + * + * @param {string} id - The unique identifier for the SMS verification request. + * @param {string} code - The verification code received via SMS. + * @param {string} [cli] - An optional CLI (Caller Line Identification) that can be included in the request. + * @return {ReportSmsVerificationByIdRequestData} The request data object used to report the SMS verification. + */ buildSmsRequest: ( id: string, code: string, @@ -191,6 +201,34 @@ export const reportVerificationByIdHelper = { }, }; }, + /** + * Builds a request object for reporting a phone call verification by its ID. + * + * @param {string} id - The unique identifier for the phone call verification request. + * @param {string} code - The verification code received during the phone call. + * @return {ReportPhoneCallVerificationByIdRequestData} The request data object used to report the phone call verification. + */ + buildPhoneCallRequest: ( + id: string, + code: string, + ): ReportPhoneCallVerificationByIdRequestData => { + return { + id, + reportPhoneCallVerificationByIdRequestBody: { + phoneCall: { + code, + }, + }, + }; + }, + /** + * Builds a request object for reporting a callout verification by its ID. + * + * @param {string} id - The unique identifier for the callout verification request. + * @param {string} code - The verification code received during the callout. + * @return {ReportCalloutVerificationByIdRequestData} The request data object used to report the callout verification. + * @deprecated + */ buildCalloutRequest: ( id: string, code: string, @@ -204,6 +242,13 @@ export const reportVerificationByIdHelper = { }, }; }, + /** + * Builds a request object for reporting a flash call verification by its ID. + * + * @param {string} id - The unique identifier for the flash call verification request. + * @param {string} cli - The CLI (Caller Line Identification) received during the flash call. + * @return {ReportFlashCallVerificationByIdRequestData} The request data object used to report the flash call verification. + */ buildFlashCallRequest: ( id: string, cli: string, @@ -219,6 +264,14 @@ export const reportVerificationByIdHelper = { }, }; export const reportVerificationByIdentityHelper = { + /** + * Builds a request object for reporting an SMS verification by the phone number identity. + * + * @param {string} identity - The phone number for which the verification process has been initiated. + * @param {string} code - The verification code received via SMS. + * @param {string} [cli] - The CLI (Caller Line Identification) that may be used during the verification. + * @return {ReportSmsVerificationByIdentityRequestData} The request data object used to report the SMS verification. + */ buildSmsRequest: ( identity: string, code: string, @@ -234,6 +287,34 @@ export const reportVerificationByIdentityHelper = { }, }; }, + /** + * Builds a request object for reporting a phone call verification by the phone number identity. + * + * @param {string} identity - The phone number for which the verification process has been initiated. + * @param {string} code - The verification code received via the phone call. + * @return {ReportPhoneCallVerificationByIdentityRequestData} The request data object used to report the phone call verification. + */ + buildPhoneCallRequest: ( + identity: string, + code: string, + ): ReportPhoneCallVerificationByIdentityRequestData => { + return { + endpoint: identity, + reportPhoneCallVerificationByIdentityRequestBody: { + phoneCall: { + code, + }, + }, + }; + }, + /** + * Builds a request object for reporting a callout verification by the phone number identity. + * + * @param {string} identity - The phone number for which the callout verification process has been initiated. + * @param {string} code - The verification code received during the callout. + * @return {ReportCalloutVerificationByIdentityRequestData} The request data object used to report the callout verification. + * @deprecated + */ buildCalloutRequest: ( identity: string, code: string, @@ -247,6 +328,13 @@ export const reportVerificationByIdentityHelper = { }, }; }, + /** + * Builds a request object for reporting a flash call verification by the phone number identity. + * + * @param {string} identity - The phone number for which the flash call verification process has been initiated. + * @param {string} cli - The CLI (Caller Line Identification) received during the flash call. + * @return {ReportFlashCallVerificationByIdentityRequestData} The request data object used to report the flash call verification. + */ buildFlashCallRequest: ( identity: string, cli: string, diff --git a/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts b/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts index 0842d3d0..5475c92a 100644 --- a/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts +++ b/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts @@ -1,6 +1,7 @@ import { CalloutVerificationReportRequest, FlashCallVerificationReportRequest, + PhoneCallVerificationReportRequest, SmsVerificationReportRequest, } from '../../verification-report-request'; import { @@ -27,6 +28,12 @@ export interface ReportFlashCallVerificationByIdRequestData extends ReportVerifi 'reportFlashCallVerificationByIdRequestBody': FlashCallVerificationReportRequest; } +export interface ReportPhoneCallVerificationByIdRequestData extends ReportVerificationByIdRequestDataBase { + /** Request body to report a verification started with a phone call by its ID */ + 'reportPhoneCallVerificationByIdRequestBody': PhoneCallVerificationReportRequest; +} + +/** @deprecated */ export interface ReportCalloutVerificationByIdRequestData extends ReportVerificationByIdRequestDataBase { /** Request body to report a verification started with a callout by its ID */ 'reportCalloutVerificationByIdRequestBody': CalloutVerificationReportRequest; @@ -47,6 +54,12 @@ export interface ReportFlashCallVerificationByIdentityRequestData extends Report 'reportFlashCallVerificationByIdentityRequestBody': FlashCallVerificationReportRequest; } +export interface ReportPhoneCallVerificationByIdentityRequestData extends ReportVerificationByIdentityRequestDataBase { + /** Request body to report a verification started with a callout by its identity */ + 'reportPhoneCallVerificationByIdentityRequestBody': PhoneCallVerificationReportRequest; +} + +/** @deprecated */ export interface ReportCalloutVerificationByIdentityRequestData extends ReportVerificationByIdentityRequestDataBase { /** Request body to report a verification started with a callout by its identity */ 'reportCalloutVerificationByIdentityRequestBody': CalloutVerificationReportRequest; diff --git a/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts b/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts index f49dd57b..d72160fe 100644 --- a/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts +++ b/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts @@ -16,8 +16,8 @@ export interface StartVerificationWithPhoneCall extends StartVerificationBase { } export interface StartVerificationWithPhoneCallServerModel extends StartVerificationBase { - /** @see CalloutOptions */ - calloutOptions?: CalloutOptions; + /** @see PhoneCallOptions */ + calloutOptions?: PhoneCallOptions; } /** @deprecated */ diff --git a/packages/verification/src/models/v1/verification-report-request/index.ts b/packages/verification/src/models/v1/verification-report-request/index.ts index adcddc04..d8974f5d 100644 --- a/packages/verification/src/models/v1/verification-report-request/index.ts +++ b/packages/verification/src/models/v1/verification-report-request/index.ts @@ -1,5 +1,7 @@ export type { SmsVerificationReportRequest, FlashCallVerificationReportRequest, + PhoneCallVerificationReportRequest, + PhoneCallVerificationReportRequestServerModel, CalloutVerificationReportRequest, } from './verification-report-request'; diff --git a/packages/verification/src/models/v1/verification-report-request/verification-report-request.ts b/packages/verification/src/models/v1/verification-report-request/verification-report-request.ts index e0b79ff0..6c2bfc51 100644 --- a/packages/verification/src/models/v1/verification-report-request/verification-report-request.ts +++ b/packages/verification/src/models/v1/verification-report-request/verification-report-request.ts @@ -20,12 +20,26 @@ interface FlashCallContent { cli: string; } +export interface PhoneCallVerificationReportRequest { + /** A configuration object containing settings specific to Phone Call verifications */ + phoneCall: PhoneCallContent; +} + +export interface PhoneCallVerificationReportRequestServerModel { + /** A configuration object containing settings specific to Phone Call verifications */ + callout: PhoneCallContent; +} + +/** @deprecated */ export interface CalloutVerificationReportRequest { /** A configuration object containing settings specific to Phone Call verifications */ callout: CalloutContent; } -interface CalloutContent { +interface PhoneCallContent { /** The code which was received by the user submitting the Phone Call verification. */ code?: string; } + +/** @deprecated */ +type CalloutContent = PhoneCallContent; diff --git a/packages/verification/src/rest/v1/verifications/verifications-api.jest.fixture.ts b/packages/verification/src/rest/v1/verifications/verifications-api.jest.fixture.ts index ee77028b..41e13406 100644 --- a/packages/verification/src/rest/v1/verifications/verifications-api.jest.fixture.ts +++ b/packages/verification/src/rest/v1/verifications/verifications-api.jest.fixture.ts @@ -21,6 +21,9 @@ import { StartPhoneCallVerificationResponse, StartPhoneCallVerificationRequestData, StartDataVerificationResponse, + ReportPhoneCallVerificationByIdRequestData, + ReportPhoneCallVerificationByIdentityRequestData, + PhoneCallVerificationReportResponse, } from '../../../models'; export class VerificationsApiFixture implements Partial> { @@ -37,6 +40,12 @@ export class VerificationsApiFixture implements Partial, [ReportFlashCallVerificationByIdRequestData]> = jest.fn(); + /** + * Fixture associated to function reportPhoneCallById + */ + public reportPhoneCallById: jest.Mock, + [ReportPhoneCallVerificationByIdRequestData]> = jest.fn(); /** * Fixture associated to function reportCalloutById */ @@ -57,6 +66,13 @@ export class VerificationsApiFixture implements Partial, [ReportFlashCallVerificationByIdentityRequestData]> = jest.fn(); + /** + * Fixture associated to function reportPhoneCallByIdentity + */ + public reportPhoneCallByIdentity: + jest.Mock, + [ReportPhoneCallVerificationByIdentityRequestData]> = jest.fn(); /** * Fixture associated to function reportCalloutByIdentity */ diff --git a/packages/verification/src/rest/v1/verifications/verifications-api.ts b/packages/verification/src/rest/v1/verifications/verifications-api.ts index 0b34400d..800da475 100644 --- a/packages/verification/src/rest/v1/verifications/verifications-api.ts +++ b/packages/verification/src/rest/v1/verifications/verifications-api.ts @@ -22,6 +22,12 @@ import { StartVerificationWithPhoneCall, StartDataVerificationRequestData, StartDataVerificationResponse, + ReportPhoneCallVerificationByIdRequestData, + PhoneCallVerificationReportRequest, + StartVerificationWithPhoneCallServerModel, + PhoneCallVerificationReportRequestServerModel, + ReportPhoneCallVerificationByIdentityRequestData, + PhoneCallVerificationReportResponse, } from '../../../models'; import { RequestBody, @@ -108,10 +114,59 @@ export class VerificationsApi extends VerificationDomainApi { }); } + /** + * Report a Phone Call verification with ID + * Report the received verification code to verify it, using the Verification ID of the Verification request. + * @param { ReportCalloutVerificationByIdRequestData } data - The data to provide to the API call. + */ + public async reportPhoneCallById( + data: ReportPhoneCallVerificationByIdRequestData, + ): Promise { + this.client = this.getSinchClient(); + (data.reportPhoneCallVerificationByIdRequestBody as any).method = 'callout'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Accept': 'application/json', + }; + + // Special fields handling: see method for details + const requestDataBody = this.performReportPhoneCallByIdRequestBodyTransformation( + data.reportPhoneCallVerificationByIdRequestBody); + + const body: RequestBody = requestDataBody + ? JSON.stringify(requestDataBody) + : '{}'; + + const path = `/verification/v1/verifications/id/${data['id']}`; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'PUT', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'ReportPhoneCallVerificationById', + }); + } + + performReportPhoneCallByIdRequestBodyTransformation( + body: PhoneCallVerificationReportRequest, + ): PhoneCallVerificationReportRequestServerModel { + const requestDataBody: any = { ...body }; + (requestDataBody).callout = { ...requestDataBody.phoneCall }; + delete requestDataBody.phoneCall; + return requestDataBody; + } + /** * Report a Callout verification with ID * Report the received verification code to verify it, using the Verification ID of the Verification request. * @param { ReportCalloutVerificationByIdRequestData } data - The data to provide to the API call. + * @deprecated */ public async reportCalloutById( data: ReportCalloutVerificationByIdRequestData, @@ -211,10 +266,59 @@ export class VerificationsApi extends VerificationDomainApi { }); } + /** + * Report a Phone Call verification using Identity + * Report the received verification code (OTP) to verify it, using the identity of the user (in most cases, the phone number). + * @param { ReportPhoneCallVerificationByIdentityRequestData } data - The data to provide to the API call. + */ + public async reportPhoneCallByIdentity( + data: ReportPhoneCallVerificationByIdentityRequestData, + ): Promise { + this.client = this.getSinchClient(); + (data.reportPhoneCallVerificationByIdentityRequestBody as any).method = 'callout'; + const getParams = this.client.extractQueryParams( + data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Accept': 'application/json', + }; + + // Special fields handling: see method for details + const requestDataBody = this.performReportPhoneCallByIdentityRequestBodyTransformation( + data.reportPhoneCallVerificationByIdentityRequestBody); + + const body: RequestBody = requestDataBody + ? JSON.stringify(requestDataBody) + : '{}'; + const path = `/verification/v1/verifications/number/${data['endpoint']}`; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'PUT', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'ReportPhoneCallVerificationByIdentity', + }); + } + + performReportPhoneCallByIdentityRequestBodyTransformation( + body: PhoneCallVerificationReportRequest, + ): PhoneCallVerificationReportRequestServerModel { + const requestDataBody: any = { ...body }; + (requestDataBody).callout = { ...requestDataBody.phoneCall }; + delete requestDataBody.phoneCall; + return requestDataBody; + } + /** * Report a Callout verification using Identity * Report the received verification code (OTP) to verify it, using the identity of the user (in most cases, the phone number). * @param { ReportCalloutVerificationByIdentityRequestData } data - The data to provide to the API call. + * @deprecated */ public async reportCalloutByIdentity( data: ReportCalloutVerificationByIdentityRequestData, @@ -382,7 +486,9 @@ export class VerificationsApi extends VerificationDomainApi { }); } - performStartPhoneCallRequestBodyTransformation(body: StartVerificationWithPhoneCall): StartVerificationWithPhoneCall { + performStartPhoneCallRequestBodyTransformation( + body: StartVerificationWithPhoneCall, + ): StartVerificationWithPhoneCallServerModel { const requestDataBody = { ...body }; if (requestDataBody.phoneCallOptions !== undefined) { (requestDataBody as any).calloutOptions = { ...requestDataBody.phoneCallOptions }; diff --git a/packages/verification/tests/rest/v1/verifications/report.steps.ts b/packages/verification/tests/rest/v1/verifications/report.steps.ts new file mode 100644 index 00000000..9d0055bf --- /dev/null +++ b/packages/verification/tests/rest/v1/verifications/report.steps.ts @@ -0,0 +1,117 @@ +import { VerificationsApi, VerificationService, Verification } from '../../../../src'; +import { Given, When, Then } from '@cucumber/cucumber'; +import * as assert from 'assert'; + +let reportVerificationApi: VerificationsApi; +let reportSmsResponse: Verification.SmsVerificationReportResponse; +let reportPhoneCallResponse: Verification.PhoneCallVerificationReportResponse; +let reportFlashCallResponse: Verification.FlashCallVerificationReportResponse; + +Given('the Verification service "Report" is available', () => { + const verificationService = new VerificationService({ + applicationKey: 'appKey', + applicationSecret: 'appSecret', + verificationHostname: 'http://localhost:3018', + }); + reportVerificationApi = verificationService.verifications; +}); + +When('I send a request to report an SMS verification with the verification ID', async () => { + reportSmsResponse = await reportVerificationApi.reportSmsById({ + id: '1ce0ffee-c0de-5eed-d00d-f00dfeed1337', + reportSmsVerificationByIdRequestBody: { + sms: { + code: 'OQP1', + }, + }, + }); +}); + +When('I send a request to report an SMS verification with the phone number', async () => { + reportSmsResponse = await reportVerificationApi.reportSmsByIdentity({ + endpoint: '+46123456789', + reportSmsVerificationByIdentityRequestBody: { + sms: { + code: 'OQP1', + }, + }, + }); +}); + +Then('the response contains the details of an SMS verification report', () => { + assert.equal(reportSmsResponse.id, '1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(reportSmsResponse.method, 'sms'); + const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL'; + assert.equal(reportSmsResponse.status, successfulStatus); +}); + +When('I send a request to report a Phone Call verification with the verification ID', async () => { + reportPhoneCallResponse = await reportVerificationApi.reportPhoneCallById({ + id: '1ce0ffee-c0de-5eed-d11d-f00dfeed1337', + reportPhoneCallVerificationByIdRequestBody: { + phoneCall: { + code: '123456', + }, + }, + }); +}); + +When('I send a request to report a Phone Call verification with the phone number', async () => { + reportPhoneCallResponse = await reportVerificationApi.reportPhoneCallByIdentity({ + endpoint: '+33612345678', + reportPhoneCallVerificationByIdentityRequestBody: { + phoneCall: { + code: '123456', + }, + }, + }); +}); + +Then('the response contains the details of a Phone Call verification report', () => { + assert.equal(reportPhoneCallResponse.id, '1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(reportPhoneCallResponse.method, 'callout'); + const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL'; + assert.equal(reportPhoneCallResponse.status, successfulStatus); + assert.equal(reportPhoneCallResponse.callComplete, true); +}); + +When('I send a request to report a Flash Call verification with the verification ID', async () => { + reportFlashCallResponse = await reportVerificationApi.reportFlashCallById({ + id: '1ce0ffee-c0de-5eed-d11d-f00dfeed1337', + reportFlashCallVerificationByIdRequestBody: { + flashCall: { + cli: '+18156540001', + }, + }, + }); +}); + +When('I send a request to report a Flash Call verification with the phone number', async () => { + reportFlashCallResponse = await reportVerificationApi.reportFlashCallByIdentity({ + endpoint: '+33612345678', + reportFlashCallVerificationByIdentityRequestBody: { + flashCall: { + cli: '+18156540001', + }, + }, + }); +}); + +Then('the response contains the details of a Flash Call verification report', () => { + assert.equal(reportFlashCallResponse.id, '1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(reportFlashCallResponse.method, 'flashcall'); + const successfulStatus: Verification.VerificationStatusEnum = 'SUCCESSFUL'; + assert.equal(reportFlashCallResponse.status, successfulStatus); + assert.equal(reportFlashCallResponse.reference, 'flashcall-verification-test-e2e'); + assert.equal(reportFlashCallResponse.callComplete, true); +}); + +Then('the response contains the details of a failed Flash Call verification report', () => { + assert.equal(reportFlashCallResponse.id, '1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(reportFlashCallResponse.method, 'flashcall'); + const failStatus: Verification.VerificationStatusEnum = 'FAIL'; + assert.equal(reportFlashCallResponse.status, failStatus); + const expiredReason: Verification.ReasonEnum = 'Expired'; + assert.equal(reportFlashCallResponse.reason, expiredReason); + assert.equal(reportFlashCallResponse.callComplete, true); +}); diff --git a/packages/verification/tests/rest/v1/start/start.steps.ts b/packages/verification/tests/rest/v1/verifications/start.steps.ts similarity index 100% rename from packages/verification/tests/rest/v1/start/start.steps.ts rename to packages/verification/tests/rest/v1/verifications/start.steps.ts diff --git a/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts b/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts index 5c2d42dc..055c96fc 100644 --- a/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts +++ b/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts @@ -234,6 +234,43 @@ describe('VerificationsApi', () => { }); it('should make a PUT request to report the verification code (OTP) received by a phone call to verify it,' + + 'using the verification ID of the verification request', async () => { + // Given + const requestData = Verification.reportVerificationByIdHelper.buildPhoneCallRequest( + 'some_verification_id', + '0000'); + const expectedResponse: Verification.PhoneCallVerificationReportResponse = { + id: 'some_verification_id', + method: 'callout', + status: 'SUCCESSFUL', + callComplete: true, + }; + + // When + fixture.reportPhoneCallById.mockResolvedValue(expectedResponse); + verificationsApi.reportPhoneCallById = fixture.reportPhoneCallById; + const response = await verificationsApi.reportPhoneCallById(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.reportPhoneCallById).toHaveBeenCalledWith(requestData); + }); + + it('should format the reportPhoneCallById request body', () => { + const requestData = Verification.reportVerificationByIdHelper.buildPhoneCallRequest( + 'some_verification_id', + '0000'); + const expectedResult: Verification.PhoneCallVerificationReportRequestServerModel = { + callout: { + code: '0000', + }, + }; + const formattedRequestData = verificationsApi.performReportPhoneCallByIdRequestBodyTransformation( + requestData.reportPhoneCallVerificationByIdRequestBody); + expect(formattedRequestData).toEqual(expectedResult); + }); + + it('should make a PUT request to report the verification code (OTP) received by a callout to verify it,' + 'using the verification ID of the verification request', async () => { // Given const requestData = Verification.reportVerificationByIdHelper.buildCalloutRequest( @@ -308,6 +345,44 @@ describe('VerificationsApi', () => { }); it('should make a PUT request to report the verification code (OTP) received by a phone call to verify it,' + + 'using the identity of the user', async () => { + // Given + const requestData = Verification.reportVerificationByIdentityHelper.buildPhoneCallRequest( + '+33444555666', + '0000'); + const expectedResponse: Verification.PhoneCallVerificationReportResponse = { + id: '018beea3-a942-0094-4a3a-d6b2f2c65057', + method: 'callout', + status: 'FAIL', + reason: 'Expired', + callComplete: true, + }; + + // When + fixture.reportPhoneCallByIdentity.mockResolvedValue(expectedResponse); + verificationsApi.reportPhoneCallByIdentity = fixture.reportPhoneCallByIdentity; + const response = await verificationsApi.reportPhoneCallByIdentity(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.reportPhoneCallByIdentity).toHaveBeenCalledWith(requestData); + }); + + it('should format the reportPhoneCallByIdentity request body', () => { + const requestData = Verification.reportVerificationByIdentityHelper.buildPhoneCallRequest( + '+33444555666', + '0000'); + const expectedResult: Verification.PhoneCallVerificationReportRequestServerModel = { + callout: { + code: '0000', + }, + }; + const formattedRequestData = verificationsApi.performReportPhoneCallByIdentityRequestBodyTransformation( + requestData.reportPhoneCallVerificationByIdentityRequestBody); + expect(formattedRequestData).toEqual(expectedResult); + }); + + it('should make a PUT request to report the verification code (OTP) received by a callout to verify it,' + 'using the identity of the user', async () => { // Given const requestData = Verification.reportVerificationByIdentityHelper.buildCalloutRequest(