Skip to content

Commit

Permalink
DEVEXP-521: E2E Verification/Report (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Aug 28, 2024
1 parent ad92b7c commit 0a321c1
Show file tree
Hide file tree
Showing 20 changed files with 516 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/run-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/integrated-flows-examples/src/verification/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 *');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ./report-with-id_phonecall.ts instead */
(async () => {
console.log('************************************');
console.log('* ReportVerificationById - callout *');
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ./report-with-identity_phonecall.ts instead */
(async () => {
console.log('******************************************');
console.log('* ReportVerificationByIdentity - callout *');
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

})();
Original file line number Diff line number Diff line change
Expand Up @@ -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 *');
Expand Down
Original file line number Diff line number Diff line change
@@ -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`. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export type { CalloutVerificationReportResponse } from './callout-verification-report-response';
export type {
PhoneCallVerificationReportResponse,
CalloutVerificationReportResponse,
} from './callout-verification-report-response';
88 changes: 88 additions & 0 deletions packages/verification/src/models/v1/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ReportCalloutVerificationByIdRequestData,
ReportFlashCallVerificationByIdentityRequestData,
ReportFlashCallVerificationByIdRequestData,
ReportPhoneCallVerificationByIdentityRequestData,
ReportPhoneCallVerificationByIdRequestData,
ReportSmsVerificationByIdentityRequestData,
ReportSmsVerificationByIdRequestData,
StartCalloutVerificationRequestData,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CalloutVerificationReportRequest,
FlashCallVerificationReportRequest,
PhoneCallVerificationReportRequest,
SmsVerificationReportRequest,
} from '../../verification-report-request';
import {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export interface StartVerificationWithPhoneCall extends StartVerificationBase {
}

export interface StartVerificationWithPhoneCallServerModel extends StartVerificationBase {
/** @see CalloutOptions */
calloutOptions?: CalloutOptions;
/** @see PhoneCallOptions */
calloutOptions?: PhoneCallOptions;
}

/** @deprecated */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type {
SmsVerificationReportRequest,
FlashCallVerificationReportRequest,
PhoneCallVerificationReportRequest,
PhoneCallVerificationReportRequestServerModel,
CalloutVerificationReportRequest,
} from './verification-report-request';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading

0 comments on commit 0a321c1

Please sign in to comment.