diff --git a/examples/integrated-flows-examples/src/verification/app.ts b/examples/integrated-flows-examples/src/verification/app.ts index 5c3cf202..138a6830 100644 --- a/examples/integrated-flows-examples/src/verification/app.ts +++ b/examples/integrated-flows-examples/src/verification/app.ts @@ -18,9 +18,9 @@ dotenv.config(); enum VerificationMethods { SMS ='sms', - CALLOUT = 'callout', + PHONE_CALL = 'phone call', FLASH_CALL = 'flash call', - SEAMLESS = 'seamless', + DATA = 'data', } inquirer.prompt([ @@ -41,13 +41,13 @@ dotenv.config(); case VerificationMethods.SMS: startSmsVerificationFlow(answers.phoneNumber); break; - case VerificationMethods.CALLOUT: - startCalloutVerificationFlow(answers.phoneNumber); + case VerificationMethods.PHONE_CALL: + startPhoneCallVerificationFlow(answers.phoneNumber); break; case VerificationMethods.FLASH_CALL: startFlashCallVerificationFlow(answers.phoneNumber); break; - case VerificationMethods.SEAMLESS: + case VerificationMethods.DATA: startSeamlessVerificationFlow(answers.phoneNumber); break; } @@ -72,9 +72,9 @@ dotenv.config(); }; - const startCalloutVerificationFlow = async (phoneNumber: string) => { - const requestData = Verification.startVerificationHelper.buildCalloutRequest(phoneNumber); - const response = await sinch.verification.verifications.startCallout(requestData); + const startPhoneCallVerificationFlow = async (phoneNumber: string) => { + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest(phoneNumber); + const response = await sinch.verification.verifications.startPhoneCall(requestData); console.log('Verification request sent! Please answer to the phone call ans listen to the OTP.'); const answers = await inquirer.prompt([ { @@ -109,10 +109,10 @@ dotenv.config(); }; const startSeamlessVerificationFlow = async (phoneNumber: string) => { - const requestData = Verification.startVerificationHelper.buildSeamlessRequest(phoneNumber); + const requestData = Verification.startVerificationHelper.buildDataRequest(phoneNumber); let response; try { - response = await sinch.verification.verifications.startSeamless(requestData); + response = await sinch.verification.verifications.startData(requestData); } catch (error: any) { console.log(`Impossible to process the seamless verification: ${error.data})`); return; diff --git a/examples/simple-examples/README.md b/examples/simple-examples/README.md index 9352335e..500f9f06 100644 --- a/examples/simple-examples/README.md +++ b/examples/simple-examples/README.md @@ -149,20 +149,21 @@ yarn run numbers:regions:list ### Verification -| Service | Sample application name and location | Required parameters | -|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| -| Verifications | [./src/verification/verifications/sms/start-sms.ts](./src/verification/verifications/sms/start-sms.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/sms/report-with-id_sms.ts](./src/verification/verifications/sms/report-with-id_sms.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/sms/report-with-identity_sms.ts](./src/verification/verifications/sms/report-with-identity_sms.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/flashcall/start-flashcall.ts](./src/verification/verifications/flashcall/start-flashcall.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/flashcall/report-with-id_flashcall.ts](./src/verification/verifications/flashcall/report-with-id_flashcall.ts) | `VERIFICATION_ID` + `VERIFICATION_CLI` | -| | [./src/verification/verifications/flashcall/report-with-identity_flashcall.ts](./src/verification/verifications/flashcall/report-with-identity_flashcall.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CLI` | -| | [./src/verification/verifications/callout/start-callout.ts](./src/verification/verifications/callout/start-callout.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/callout/report-with-id_callout.ts](./src/verification/verifications/callout/report-with-id_callout.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/callout/report-with-identity_callout.ts](./src/verification/verifications/callout/report-with-identity_callout.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | -| Verification-status | [./src/verification/verification-status/verification-by-id.ts](./src/verification/verification-status/verification-by-id.ts) | `VERIFICATION_ID` | -| | [./src/verification/verification-status/verification-by-identity.ts](./src/verification/verification-status/verification-by-identity.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verification-status/verification-by-reference.ts](./src/verification/verification-status/verification-by-reference.ts) | `VERIFICATION_REFERENCE` | +| Service | Sample application name and location | Required parameters | +|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| +| Start Verifications | [./src/verification/verifications/sms/start-sms.ts](./src/verification/verifications/sms/start-sms.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/verifications/phonecall/start-phonecall.ts](./src/verification/verifications/phonecall/start-phonecall.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/verifications/flashcall/start-flashcall.ts](./src/verification/verifications/flashcall/start-flashcall.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/verifications/data/start-data.ts](./src/verification/verifications/data/start-data.ts) | `VERIFICATION_IDENTITY` | +| Verifications | [./src/verification/verifications/sms/report-with-id_sms.ts](./src/verification/verifications/sms/report-with-id_sms.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/sms/report-with-identity_sms.ts](./src/verification/verifications/sms/report-with-identity_sms.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/flashcall/report-with-id_flashcall.ts](./src/verification/verifications/flashcall/report-with-id_flashcall.ts) | `VERIFICATION_ID` + `VERIFICATION_CLI` | +| | [./src/verification/verifications/flashcall/report-with-identity_flashcall.ts](./src/verification/verifications/flashcall/report-with-identity_flashcall.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CLI` | +| | [./src/verification/verifications/callout/report-with-id_callout.ts](./src/verification/verifications/phonecall/report-with-id_callout.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/callout/report-with-identity_callout.ts](./src/verification/verifications/phonecall/report-with-identity_callout.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | +| Verification-status | [./src/verification/verification-status/verification-by-id.ts](./src/verification/verification-status/verification-by-id.ts) | `VERIFICATION_ID` | +| | [./src/verification/verification-status/verification-by-identity.ts](./src/verification/verification-status/verification-by-identity.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/verification-status/verification-by-reference.ts](./src/verification/verification-status/verification-by-reference.ts) | `VERIFICATION_REFERENCE` | ### Voice diff --git a/examples/simple-examples/package.json b/examples/simple-examples/package.json index 9f12ae68..4b72e1bb 100644 --- a/examples/simple-examples/package.json +++ b/examples/simple-examples/package.json @@ -153,14 +153,14 @@ "sms:inbounds:list": "ts-node src/sms/inbounds/list.ts", "sms:inbounds:get": "ts-node src/sms/inbounds/get.ts", "verification:verifications:start-sms": "ts-node src/verification/verifications/sms/start-sms.ts", - "verification:verifications:start-callout": "ts-node src/verification/verifications/callout/start-callout.ts", + "verification:verifications:start-phonecall": "ts-node src/verification/verifications/phonecall/start-phonecall.ts", "verification:verifications:start-flashcall": "ts-node src/verification/verifications/flashcall/start-flashcall.ts", - "verification:verifications:start-seamless": "ts-node src/verification/verifications/seamless/start-seamless.ts", + "verification:verifications:start-data": "ts-node src/verification/verifications/data/start-data.ts", "verification:verifications:report-with-id:sms": "ts-node src/verification/verifications/sms/report-with-id_sms.ts", - "verification:verifications:report-with-id:callout": "ts-node src/verification/verifications/callout/report-with-id_callout.ts", + "verification:verifications:report-with-id:callout": "ts-node src/verification/verifications/phonecall/report-with-id_callout.ts", "verification:verifications:report-with-id:flashcall": "ts-node src/verification/verifications/flashcall/report-with-id_flashcall.ts", "verification:verifications:report-with-identity:sms": "ts-node src/verification/verifications/sms/report-with-identity_sms.ts", - "verification:verifications:report-with-identity:callout": "ts-node src/verification/verifications/callout/report-with-identity_callout.ts", + "verification:verifications:report-with-identity:callout": "ts-node src/verification/verifications/phonecall/report-with-identity_callout.ts", "verification:verifications:report-with-identity:flashcall": "ts-node src/verification/verifications/flashcall/report-with-identity_flashcall.ts", "verification:verification-status:verification-by-id": "ts-node src/verification/verification-status/verification-by-id.ts", "verification:verification-status:verification-by-identity": "ts-node src/verification/verification-status/verification-by-identity.ts", diff --git a/examples/simple-examples/src/verification/verifications/data/start-data.ts b/examples/simple-examples/src/verification/verifications/data/start-data.ts new file mode 100644 index 00000000..3c0f2f7b --- /dev/null +++ b/examples/simple-examples/src/verification/verifications/data/start-data.ts @@ -0,0 +1,32 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../../config'; + +(async () => { + console.log('****************************'); + console.log('* StartVerification - data *'); + console.log('****************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildDataRequest( + verificationIdentity, + `test-reference-for-seamless-verification_${verificationIdentity}`, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startData(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + console.log(`Data verification specific field: targetUri = ${response.seamless?.targetUri}`); + } else { + printFullResponse(response); + } +})(); diff --git a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts b/examples/simple-examples/src/verification/verifications/data/start-seamless.ts similarity index 85% rename from examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts rename to examples/simple-examples/src/verification/verifications/data/start-seamless.ts index c72e5555..f6ea52b2 100644 --- a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts +++ b/examples/simple-examples/src/verification/verifications/data/start-seamless.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-data.ts instead */ (async () => { console.log('********************************'); console.log('* StartVerification - seamless *'); @@ -25,7 +26,7 @@ import { if (printFormat === 'pretty') { console.log(`Verification ID = ${response.id}`); - console.log(`Seamless verification specific field: template = ${response.seamless?.targetUri}`); + console.log(`Seamless verification specific field: targetUri = ${response.seamless?.targetUri}`); } else { printFullResponse(response); } diff --git a/examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts similarity index 100% rename from examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts rename to examples/simple-examples/src/verification/verifications/phonecall/report-with-id_callout.ts diff --git a/examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts similarity index 100% rename from examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts rename to examples/simple-examples/src/verification/verifications/phonecall/report-with-identity_callout.ts diff --git a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts b/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts similarity index 93% rename from examples/simple-examples/src/verification/verifications/callout/start-callout.ts rename to examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts index 1a0a6ddb..11cf58c3 100644 --- a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts +++ b/examples/simple-examples/src/verification/verifications/phonecall/start-callout.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-phonecall.ts instead */ (async () => { console.log('*******************************'); console.log('* StartVerification - callout *'); diff --git a/examples/simple-examples/src/verification/verifications/phonecall/start-phonecall.ts b/examples/simple-examples/src/verification/verifications/phonecall/start-phonecall.ts new file mode 100644 index 00000000..27f5c7b7 --- /dev/null +++ b/examples/simple-examples/src/verification/verifications/phonecall/start-phonecall.ts @@ -0,0 +1,31 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../../config'; + +(async () => { + console.log('**********************************'); + console.log('* StartVerification - phoneCall *'); + console.log('**********************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest( + verificationIdentity, + `test-reference-for-callout-verification_${verificationIdentity}`, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startPhoneCall(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + } else { + printFullResponse(response); + } +})(); diff --git a/packages/verification/README.md b/packages/verification/README.md index 7a7631a4..5524a2fd 100644 --- a/packages/verification/README.md +++ b/packages/verification/README.md @@ -50,19 +50,22 @@ const sinch = new SinchClient(credentials); const verificationService: VerificationService = sinch.verification; // Build the request data -const requestData: Verification.StartVerificationRequestData = { - initiateVerificationRequestBody: { +const requestData: Verification.StartSmsVerificationRequestData = { + startVerificationWithSmsRequestBody: { identity: { type: 'number', endpoint: '+17813334444', }, - method: 'sms', + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, }, }; // Use the 'verification' service registered on the Sinch client -const verificationInitResponse: Verification.InitiateVerificationResponse - = await verificationService.verifications.start(requestData); +const startVerificationResponse: Verification.StartSmsVerificationResponse + = await verificationService.startVerifications.startSms(requestData); ``` ### Standalone @@ -87,19 +90,22 @@ const credentials: ApplicationCredentials = { const verificationService = new VerificationService(credentials); // Build the request data -const requestData: Verification.StartVerificationRequestData = { - initiateVerificationRequestBody: { +const requestData: Verification.StartSmsVerificationRequestData = { + startVerificationWithSmsRequestBody: { identity: { type: 'number', endpoint: '+17813334444', }, - method: 'sms', + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, }, }; // Use the standalone declaration of the 'verification' service -const verificationInitResponse: Verification.InitiateVerificationResponse - = await verificationService.verifications.start(requestData); +const startVerificationResponse: Verification.StartSmsVerificationResponse + = await verificationService.startVerifications.startSms(requestData); ``` ## Promises @@ -108,18 +114,18 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa ```typescript // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) -let verificationInitResponse: Verification.InitiateVerificationResponse; +let startVerificationResponse: Verification.StartSmsVerificationResponse; try { - verificationInitResponse = await verificationService.verifications.start(requestData); - console.log(`Verification ID = ${verificationInitResponse.id}`); + startVerificationResponse = await verificationService.startVerifications.startSms(requestData); + console.log(`Verification ID = ${startVerificationResponse.id}`); } catch (error: any) { - console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`); + console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.startVerificationWithSmsRequestBody.identity.endpoint}`); } // Method 2: Resolve the promise -verificationService.verifications.start(requestData) +verificationService.startVerifications.startSms(requestData) .then(response => console.log(`Verification ID = ${response.id}`)) - .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`)); + .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.startVerificationWithSmsRequestBody.identity.endpoint}`)); ``` ## Contact diff --git a/packages/verification/cucumber.js b/packages/verification/cucumber.js new file mode 100644 index 00000000..691a9809 --- /dev/null +++ b/packages/verification/cucumber.js @@ -0,0 +1,8 @@ +module.exports = { + default: [ + 'tests/e2e/features/**/*.feature', + '--require-module ts-node/register', + '--require tests/rest/v1/**/*.steps.ts', + `--format-options '{"snippetInterface": "synchronous"}'`, + ].join(' '), +}; diff --git a/packages/verification/package.json b/packages/verification/package.json index fe951ea8..1213ac53 100644 --- a/packages/verification/package.json +++ b/packages/verification/package.json @@ -25,7 +25,8 @@ "scripts": { "build": "yarn run clean && yarn run compile", "clean": "rimraf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo", - "compile": "tsc -p tsconfig.build.json && tsc -p tsconfig.tests.json && rimraf dist/tests tsconfig.build.tsbuildinfo" + "compile": "tsc -p tsconfig.build.json && tsc -p tsconfig.tests.json && rimraf dist/tests tsconfig.build.tsbuildinfo", + "test:e2e": "cucumber-js" }, "dependencies": { "@sinch/sdk-client": "^1.1.0" diff --git a/packages/verification/src/models/v1/helper.ts b/packages/verification/src/models/v1/helper.ts index 44735e07..817dcc9f 100644 --- a/packages/verification/src/models/v1/helper.ts +++ b/packages/verification/src/models/v1/helper.ts @@ -6,13 +6,23 @@ import { ReportSmsVerificationByIdentityRequestData, ReportSmsVerificationByIdRequestData, StartCalloutVerificationRequestData, + StartDataVerificationRequestData, StartFlashCallVerificationRequestData, + StartPhoneCallVerificationRequestData, StartSeamlessVerificationRequestData, StartSmsVerificationRequestData, } from './requests'; import { SmsOptions } from './start-verification-request'; export const startVerificationHelper = { + /** + * Builds a request object for starting an SMS verification process. + * + * @param {string} phoneNumber - The phone number to which the verification SMS should be sent. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {SmsOptions} [smsOptions] - Optional parameters for configuring the SMS verification request, with default values assumed for all contained values if not provided. + * @return {StartSmsVerificationRequestData} The constructed SMS verification request data. + */ buildSmsRequest: ( phoneNumber: string, reference?: string, @@ -33,6 +43,44 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for starting a phone call verification process. + * + * @param {string} phoneNumber - The phone number to which the verification call should be made. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {string} [locale] - An optional language-region identifier to use for the verification call. + * @return {StartPhoneCallVerificationRequestData} The request data object for initiating the phone call verification. + */ + buildPhoneCallRequest: ( + phoneNumber: string, + reference?: string, + locale?: string, + ): StartPhoneCallVerificationRequestData => { + return { + startVerificationWithPhoneCallRequestBody: { + identity: { + type: 'number', + endpoint: phoneNumber, + }, + reference, + ...(locale !== undefined) ? { + phoneCallOptions: { + speech: { + locale, + }, + }, + } : {}, + }, + }; + }, + /** + * Builds a callout request body with the provided phone number, reference, and locale. + * + * @param {string} phoneNumber - The phone number to which the callout will be made. + * @param {string} [reference] - An optional reference identifier for the callout. + * @param {string} [locale] - An optional locale string to specify the language or region for the callout. + * @return {StartCalloutVerificationRequestData} The constructed callout request object. + * @deprecated */ buildCalloutRequest: ( phoneNumber: string, reference?: string, @@ -55,6 +103,14 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for starting a flash call verification process. + * + * @param {string} phoneNumber - The phone number to which the flash call verification should be made. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {number} [dialTimeout] - An optional timeout value in seconds for how long to wait for the flash call to be answered. + * @return {StartFlashCallVerificationRequestData} The request data object for initiating the flash call verification. + */ buildFlashCallRequest: ( phoneNumber: string, reference?: string, @@ -75,6 +131,35 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for initiating a data verification process. + * + * @param {string} phoneNumber - The phone number to be verified. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @return {StartDataVerificationRequestData} The request data object used to start the data verification. + */ + buildDataRequest: ( + phoneNumber: string, + reference?: string, + ): StartDataVerificationRequestData => { + return { + startDataVerificationRequestBody: { + identity: { + type: 'number', + endpoint: phoneNumber, + }, + reference, + }, + }; + }, + /** + * Builds a seamless verification request body with the provided phone number and optional reference. + * + * @param {string} phoneNumber - The phone number to verify. + * @param {string} [reference] - An optional reference identifier for the verification request. + * @return {StartSeamlessVerificationRequestData} The constructed seamless verification request data. + * @deprecated + */ buildSeamlessRequest: ( phoneNumber: string, reference?: string, diff --git a/packages/verification/src/models/v1/index.ts b/packages/verification/src/models/v1/index.ts index eeb783e2..cea9c020 100644 --- a/packages/verification/src/models/v1/index.ts +++ b/packages/verification/src/models/v1/index.ts @@ -6,16 +6,16 @@ export * from './verification-report-request'; export * from './start-sms-verification-response'; export * from './sms-verification-report-response'; export * from './sms-verification-status-response'; -// Models associated to Callout verification workflow -export * from './start-callout-verification-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'; // Models associated to Flashcall verification workflow export * from './start-flashcall-verification-response'; export * from './flashcall-verification-report-response'; export * from './flashcall-verification-status-response'; -// Models associated to Seamless verification workflow -export * from './start-seamless-verification-response'; +// Models associated to Data verification workflow +export * from './start-data-verification-response'; // Wrapper for the various types of Verification Status Response export * from './verification-status-response'; // Models associated to callback events 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 2c8e064a..0842d3d0 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 @@ -4,9 +4,11 @@ import { SmsVerificationReportRequest, } from '../../verification-report-request'; import { + StartDataVerification, StartSeamlessVerification, StartVerificationWithCallout, StartVerificationWithFlashCall, + StartVerificationWithPhoneCall, StartVerificationWithSms, } from '../../start-verification-request'; @@ -60,11 +62,22 @@ export interface StartFlashCallVerificationRequestData { 'startVerificationWithFlashCallRequestBody': StartVerificationWithFlashCall; } +export interface StartPhoneCallVerificationRequestData { + 'startVerificationWithPhoneCallRequestBody': StartVerificationWithPhoneCall; +} + +/** @deprecated */ export interface StartCalloutVerificationRequestData { /** Request body to start a verification with a callout */ 'startVerificationWithCalloutRequestBody': StartVerificationWithCallout; } +export interface StartDataVerificationRequestData { + /** Request body to start a seamless verification */ + 'startDataVerificationRequestBody': StartDataVerification; +} + +/** @deprecated */ export interface StartSeamlessVerificationRequestData { /** Request body to start a seamless verification */ 'startSeamlessVerificationRequestBody': StartSeamlessVerification; diff --git a/packages/verification/src/models/v1/start-callout-verification-response/index.ts b/packages/verification/src/models/v1/start-callout-verification-response/index.ts deleted file mode 100644 index 1700cf35..00000000 --- a/packages/verification/src/models/v1/start-callout-verification-response/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { StartCalloutVerificationResponse } from './start-callout-verification-response'; diff --git a/packages/verification/src/models/v1/start-data-verification-response/index.ts b/packages/verification/src/models/v1/start-data-verification-response/index.ts new file mode 100644 index 00000000..3d6f1c8f --- /dev/null +++ b/packages/verification/src/models/v1/start-data-verification-response/index.ts @@ -0,0 +1,4 @@ +export type { + StartSeamlessVerificationResponse, + StartDataVerificationResponse, +} from './start-data-verification-response'; diff --git a/packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts b/packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts similarity index 76% rename from packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts rename to packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts index 8adc5156..0d4f1160 100644 --- a/packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts +++ b/packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts @@ -1,7 +1,9 @@ import { LinksObject } from '../links-object'; -export interface StartSeamlessVerificationResponse { +/** @deprecated */ +export type StartSeamlessVerificationResponse = StartDataVerificationResponse; +export interface StartDataVerificationResponse { /** Verification identifier used to query for status. */ id: string; /** The value of the method used for the Verification. For Data Verifications, this will always be `seamless`. */ @@ -13,7 +15,6 @@ export interface StartSeamlessVerificationResponse { } interface SeamlessContent { - /** The target URI. */ targetUri?: string; } diff --git a/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts b/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts new file mode 100644 index 00000000..b282e686 --- /dev/null +++ b/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts @@ -0,0 +1,4 @@ +export type { + StartCalloutVerificationResponse, + StartPhoneCallVerificationResponse, +} from './start-phonecall-verification-response'; diff --git a/packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts b/packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts similarity index 67% rename from packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts rename to packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts index ced322ae..7d407f37 100644 --- a/packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts +++ b/packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts @@ -1,7 +1,9 @@ import { LinksObject } from '../links-object'; -export interface StartCalloutVerificationResponse { +/** @deprecated */ +export type StartCalloutVerificationResponse = StartPhoneCallVerificationResponse; +export interface StartPhoneCallVerificationResponse { /** Verification identifier used to query for status. */ id?: string; /** The value of the method used for the Verification. For Phone Call Verifications, this will always be `callout`. */ diff --git a/packages/verification/src/models/v1/start-seamless-verification-response/index.ts b/packages/verification/src/models/v1/start-seamless-verification-response/index.ts deleted file mode 100644 index 45916e62..00000000 --- a/packages/verification/src/models/v1/start-seamless-verification-response/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { StartSeamlessVerificationResponse } from './start-seamless-verification-response'; diff --git a/packages/verification/src/models/v1/start-verification-request/index.ts b/packages/verification/src/models/v1/start-verification-request/index.ts index 8cd6484e..90fb96f1 100644 --- a/packages/verification/src/models/v1/start-verification-request/index.ts +++ b/packages/verification/src/models/v1/start-verification-request/index.ts @@ -2,11 +2,16 @@ export type { StartVerificationBase, StartVerificationWithSms, StartVerificationWithFlashCall, + StartVerificationWithPhoneCall, + StartVerificationWithPhoneCallServerModel, StartVerificationWithCallout, + StartDataVerification, StartSeamlessVerification, SmsOptions, CodeType, + PhoneCallOptions, CalloutOptions, + PhoneCallOptionsSpeech, CalloutOptionsSpeech, FlashCallOptions, } from './start-verification-request'; 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 cc32b2d3..f49dd57b 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 @@ -10,11 +10,25 @@ export interface StartVerificationWithFlashCall extends StartVerificationBase { flashCallOptions?: FlashCallOptions; } +export interface StartVerificationWithPhoneCall extends StartVerificationBase { + /** @see PhoneCallOptions */ + phoneCallOptions?: PhoneCallOptions; +} + +export interface StartVerificationWithPhoneCallServerModel extends StartVerificationBase { + /** @see CalloutOptions */ + calloutOptions?: CalloutOptions; +} + +/** @deprecated */ export interface StartVerificationWithCallout extends StartVerificationBase { /** @see CalloutOptions */ calloutOptions?: CalloutOptions; } +export interface StartDataVerification extends StartVerificationBase {} + +/** @deprecated */ export interface StartSeamlessVerification extends StartVerificationBase {} export interface StartVerificationBase { @@ -50,18 +64,23 @@ export interface FlashCallOptions { dialTimeout?: number; } +/** @deprecated */ +export type CalloutOptions = PhoneCallOptions; + /** * An optional object for Phone Call Verification, with default values assumed for all contained values if not provided. */ -export interface CalloutOptions { - /** @see CalloutOptionsSpeech */ - speech?: CalloutOptionsSpeech; +export interface PhoneCallOptions { + /** @see PhoneCallOptionsSpeech */ + speech?: PhoneCallOptionsSpeech; } +/** @deprecated */ +export type CalloutOptionsSpeech = PhoneCallOptionsSpeech; /** * Text-To-Speech engine settings */ -export interface CalloutOptionsSpeech { +export interface PhoneCallOptionsSpeech { /** A `language-region` identifier according to [IANA](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry). Only a subset of those identifiers is accepted. */ locale?: string; } 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 0343520e..ee77028b 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 @@ -17,6 +17,10 @@ import { ReportSmsVerificationByIdentityRequestData, ReportFlashCallVerificationByIdentityRequestData, ReportCalloutVerificationByIdentityRequestData, + StartDataVerificationRequestData, + StartPhoneCallVerificationResponse, + StartPhoneCallVerificationRequestData, + StartDataVerificationResponse, } from '../../../models'; export class VerificationsApiFixture implements Partial> { @@ -72,6 +76,18 @@ export class VerificationsApiFixture implements Partial, [StartFlashCallVerificationRequestData]> = jest.fn(); + /** + * Fixture associated to function startPhoneCall + */ + public startPhoneCall: jest.Mock, + [StartPhoneCallVerificationRequestData]> = jest.fn(); + /** + * Fixture associated to function startData + */ + public startData: jest.Mock< + Promise, + [StartDataVerificationRequestData]> = jest.fn(); /** * Fixture associated to function startCallout */ diff --git a/packages/verification/src/rest/v1/verifications/verifications-api.ts b/packages/verification/src/rest/v1/verifications/verifications-api.ts index 0a38a183..0b34400d 100644 --- a/packages/verification/src/rest/v1/verifications/verifications-api.ts +++ b/packages/verification/src/rest/v1/verifications/verifications-api.ts @@ -17,6 +17,11 @@ import { StartCalloutVerificationRequestData, StartSeamlessVerificationRequestData, StartVerificationWithSms, + StartPhoneCallVerificationRequestData, + StartPhoneCallVerificationResponse, + StartVerificationWithPhoneCall, + StartDataVerificationRequestData, + StartDataVerificationResponse, } from '../../../models'; import { RequestBody, @@ -251,7 +256,7 @@ export class VerificationsApi extends VerificationDomainApi { (data.startVerificationWithSmsRequestBody as any).method = 'sms'; const getParams = this.client.extractQueryParams(data, [] as never[]); const headers: { [key: string]: string | undefined } = { - 'Content-Type': 'application/json; charset=UTF-8', + 'Content-Type': 'application/json', 'Accept': 'application/json', }; if (data.startVerificationWithSmsRequestBody.smsOptions?.locale !== undefined) { @@ -303,6 +308,7 @@ export class VerificationsApi extends VerificationDomainApi { return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; } + /** * Start verification with a FlashCall * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. @@ -315,7 +321,7 @@ export class VerificationsApi extends VerificationDomainApi { (data.startVerificationWithFlashCallRequestBody as any).method = 'flashcall'; const getParams = this.client.extractQueryParams(data, [] as never[]); const headers: { [key: string]: string | undefined } = { - 'Content-Type': 'application/json; charset=UTF-8', + 'Content-Type': 'application/json', 'Accept': 'application/json', }; @@ -337,10 +343,91 @@ export class VerificationsApi extends VerificationDomainApi { }); } + /** + * Start verification with a phone call + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartPhoneCallVerificationRequestData } data - The data to provide to the API call. + */ + public async startPhoneCall( + data: StartPhoneCallVerificationRequestData, + ): Promise { + this.client = this.getSinchClient(); + (data.startVerificationWithPhoneCallRequestBody as any).method = 'callout'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + // Special fields handling: see method for details + const requestDataBody = this.performStartPhoneCallRequestBodyTransformation( + data.startVerificationWithPhoneCallRequestBody); + + const body: RequestBody = requestDataBody + ? JSON.stringify(requestDataBody) + : '{}'; + + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartVerificationWithPhoneCall', + }); + } + + performStartPhoneCallRequestBodyTransformation(body: StartVerificationWithPhoneCall): StartVerificationWithPhoneCall { + const requestDataBody = { ...body }; + if (requestDataBody.phoneCallOptions !== undefined) { + (requestDataBody as any).calloutOptions = { ...requestDataBody.phoneCallOptions }; + delete requestDataBody.phoneCallOptions; + } + return requestDataBody; + } + + /** + * Start data verification + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartDataVerificationRequestData } data - The data to provide to the API call. + */ + public async startData(data: StartDataVerificationRequestData): Promise { + this.client = this.getSinchClient(); + (data.startDataVerificationRequestBody as any).method = 'seamless'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = data['startDataVerificationRequestBody'] + ? JSON.stringify(data['startDataVerificationRequestBody']) + : '{}'; + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartDataVerification', + }); + } + /** * Start verification with a callout * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartCalloutVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startCallout(data: StartCalloutVerificationRequestData): Promise { this.client = this.getSinchClient(); @@ -373,6 +460,7 @@ export class VerificationsApi extends VerificationDomainApi { * Start seamless verification (= data verification) * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartSeamlessVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startSeamless(data: StartSeamlessVerificationRequestData): Promise { this.client = this.getSinchClient(); diff --git a/packages/verification/tests/rest/v1/start/start.steps.ts b/packages/verification/tests/rest/v1/start/start.steps.ts new file mode 100644 index 00000000..f811b864 --- /dev/null +++ b/packages/verification/tests/rest/v1/start/start.steps.ts @@ -0,0 +1,139 @@ +import { VerificationsApi, VerificationService, Verification } from '../../../../src'; +import { Given, When, Then } from '@cucumber/cucumber'; +import * as assert from 'assert'; +import { RequestFailedError } from '@sinch/sdk-client/src'; + +let startVerificationApi: VerificationsApi; +let startSmsVerificationResponse: Verification.StartSmsVerificationResponse; +let startPhoneCallVerificationResponse: Verification.StartPhoneCallVerificationResponse; +let startFlashCallVerificationResponse: Verification.StartFlashCallVerificationResponse; +let startDataVerificationResponseError: RequestFailedError; + +Given('the Verification service "Start" is available', () => { + const verificationService = new VerificationService({ + applicationKey: 'appKey', + applicationSecret: 'appSecret', + verificationHostname: 'http://localhost:3018', + }); + startVerificationApi = verificationService.verifications; +}); + +When('I send a request to start a verification with a SMS', async () => { + startSmsVerificationResponse = await startVerificationApi.startSms({ + startVerificationWithSmsRequestBody: { + identity: { + type: 'number', + endpoint: '+46123456789', + }, + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, + }, + }); +}); + +Then('the response contains the details of a verification started with a SMS', () => { + assert.equal(startSmsVerificationResponse.id, '1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(startSmsVerificationResponse.method, 'sms'); + assert.ok(startSmsVerificationResponse.sms); + assert.equal(startSmsVerificationResponse.sms.template, 'Din verifieringskod är {{CODE}}.'); + assert.equal(startSmsVerificationResponse.sms.interceptionTimeout, 198); + assert.ok(startSmsVerificationResponse._links); + const statusLink = startSmsVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startSmsVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a verification with a Phone Call', async () => { + startPhoneCallVerificationResponse = await startVerificationApi.startPhoneCall({ + startVerificationWithPhoneCallRequestBody: { + identity: { + type: 'number', + endpoint: '+33612345678', + }, + phoneCallOptions: { + speech: { + locale: 'fr-FR', + }, + }, + }, + }); +}); + +Then('the response contains the details of a verification started with a Phone Call', () => { + assert.equal(startPhoneCallVerificationResponse.id, '1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(startPhoneCallVerificationResponse.method, 'callout'); + assert.ok(startPhoneCallVerificationResponse._links); + const statusLink = startPhoneCallVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startPhoneCallVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a verification with a Flash Call', async () => { + startFlashCallVerificationResponse = await startVerificationApi.startFlashCall({ + startVerificationWithFlashCallRequestBody: { + identity: { + type: 'number', + endpoint: '+33612345678', + }, + flashCallOptions: { + dialTimeout: 10, + }, + reference: 'flashcall-verification-test-e2e', + }, + }); +}); + +Then('the response contains the details of a verification started with a Flash Call', () => { + assert.equal(startFlashCallVerificationResponse.id, '1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(startFlashCallVerificationResponse.method, 'flashcall'); + assert.ok(startFlashCallVerificationResponse.flashCall); + assert.equal(startFlashCallVerificationResponse.flashCall.cliFilter, '(.*)8156(.*)'); + assert.equal(startFlashCallVerificationResponse.flashCall.interceptionTimeout, 45); + assert.equal(startFlashCallVerificationResponse.flashCall.reportTimeout, 75); + assert.equal(startFlashCallVerificationResponse.flashCall.denyCallAfter, 0); + assert.ok(startFlashCallVerificationResponse._links); + const statusLink = startFlashCallVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startFlashCallVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a Data verification for a not available destination', async () => { + try { + await startVerificationApi.startData({ + startDataVerificationRequestBody: { + identity: { + type: 'number', + endpoint: '+17818880008', + }, + }, + }); + } catch (e: any) { + startDataVerificationResponseError = e as RequestFailedError; + } +}); + +Then('the response contains the error details of a Data verification', () => { + assert.equal(startDataVerificationResponseError.statusCode, 403); + assert.ok(startDataVerificationResponseError.data); + const errorDetails = JSON.parse(startDataVerificationResponseError.data) as Verification.VerificationError; + assert.equal(errorDetails.errorCode, 40300); + assert.equal(errorDetails.message, 'Seamless verification not available for given destination.'); + assert.equal(errorDetails.reference, 'c01dc0de-c4db-44f1-5ca1-da9159d21c191'); +}); 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 13256578..5c2d42dc 100644 --- a/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts +++ b/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts @@ -59,67 +59,90 @@ describe('VerificationsApi', () => { expect(fixture.startSms).toHaveBeenCalledWith(requestData); }); - it('should format the expiry field', () => { - const requestData = Verification.startVerificationHelper.buildSmsRequest( - '+46700000000', - undefined, - { expiry: new Date('2024-02-10T13:22:34.685Z') }); - const expectedResult: Verification.StartVerificationWithSms = { - identity: { - endpoint: '+46700000000', - type: 'number', - }, - smsOptions: { - expiry: '13:22:34', + it('should make a POST request to start a verification with a FlashCall', async () => { + // Given + const requestData = Verification.startVerificationHelper.buildFlashCallRequest('+46700000000', undefined, 30); + const expectedResponse: Verification.StartFlashCallVerificationResponse = { + id: 'some_verification_id', + method: 'flashcall', + flashCall: { + cliFilter: '(.*)70123(.*)', + interceptionTimeout: 60, + reportTimeout: 120, + denyCallAfter: 120, }, + _links, }; - const formattedRequestData - = verificationsApi.performStartSmsRequestBodyTransformation(requestData.startVerificationWithSmsRequestBody); - expect(formattedRequestData).toEqual(expectedResult); + + // When + fixture.startFlashCall.mockResolvedValue(expectedResponse); + verificationsApi.startFlashCall = fixture.startFlashCall; + const response = await verificationsApi.startFlashCall(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startFlashCall).toHaveBeenCalledWith(requestData); }); - it('should leave the expiry field unchanged', () => { - const requestData = Verification.startVerificationHelper.buildSmsRequest( + it('should make a POST request to start a verification with a PhoneCall', async () => { + // Given + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest('+46700000000'); + const expectedResponse: Verification.StartPhoneCallVerificationResponse = { + id: 'some_verification_id', + method: 'callout', + _links, + }; + + // When + fixture.startPhoneCall.mockResolvedValue(expectedResponse); + verificationsApi.startPhoneCall = fixture.startPhoneCall; + const response = await verificationsApi.startPhoneCall(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startPhoneCall).toHaveBeenCalledWith(requestData); + }); + + it('should format the startPhoneCall request body', () => { + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest( '+46700000000', undefined, - { expiry: '15:15:15' }); - const expectedResult: Verification.StartVerificationWithSms = { + 'en-US'); + const expectedResult: Verification.StartVerificationWithPhoneCallServerModel = { identity: { endpoint: '+46700000000', type: 'number', }, - smsOptions: { - expiry: '15:15:15', + calloutOptions: { + speech: { + locale: 'en-US', + }, }, }; - const formattedRequestData - = verificationsApi.performStartSmsRequestBodyTransformation(requestData.startVerificationWithSmsRequestBody); + const formattedRequestData = verificationsApi.performStartPhoneCallRequestBodyTransformation( + requestData.startVerificationWithPhoneCallRequestBody); expect(formattedRequestData).toEqual(expectedResult); }); - it('should make a POST request to start a verification with a FlashCall', async () => { + it('should make a POST request to start a data verification (seamless)', async () => { // Given - const requestData = Verification.startVerificationHelper.buildFlashCallRequest('+46700000000', undefined, 30); - const expectedResponse: Verification.StartFlashCallVerificationResponse = { + const requestData = Verification.startVerificationHelper.buildDataRequest('+46700000000'); + const expectedResponse: Verification.StartDataVerificationResponse = { id: 'some_verification_id', - method: 'flashcall', - flashCall: { - cliFilter: '(.*)70123(.*)', - interceptionTimeout: 60, - reportTimeout: 120, - denyCallAfter: 120, + method: 'seamless', + seamless: { + targetUri: 'https://target-uri.com', }, - _links, }; // When - fixture.startFlashCall.mockResolvedValue(expectedResponse); - verificationsApi.startFlashCall = fixture.startFlashCall; - const response = await verificationsApi.startFlashCall(requestData); + fixture.startData.mockResolvedValue(expectedResponse); + verificationsApi.startData = fixture.startData; + const response = await verificationsApi.startData(requestData); // Then expect(response).toEqual(expectedResponse); - expect(fixture.startFlashCall).toHaveBeenCalledWith(requestData); + expect(fixture.startData).toHaveBeenCalledWith(requestData); }); it('should make a POST request to start a verification with a Callout', async () => { @@ -141,7 +164,7 @@ describe('VerificationsApi', () => { expect(fixture.startCallout).toHaveBeenCalledWith(requestData); }); - it('should make a POST request to start a data verification (seamless)', async () => { + it('should make a POST request to start a seamless verification', async () => { // Given const requestData = Verification.startVerificationHelper.buildSeamlessRequest('+46700000000'); const expectedResponse: Verification.StartSeamlessVerificationResponse = {