diff --git a/examples/simple-examples/README.md b/examples/simple-examples/README.md index 50d2af4c..a8847c62 100644 --- a/examples/simple-examples/README.md +++ b/examples/simple-examples/README.md @@ -138,7 +138,7 @@ yarn run numbers:regions:list | | [./src/sms/batches/delivery-feedback.ts](./src/sms/batches/delivery-feedback.ts) | `BATCH_ID` | | DeliveryReports | [./src/sms/delivery-reports/list.ts](./src/sms/delivery-reports/list.ts) | | | | [./src/sms/delivery-reports/getByBatchId.ts](./src/sms/delivery-reports/getByBatchId.ts) | `BATCH_ID` | -| | [./src/sms/delivery-reports/getByPhoneNumber.ts](./src/sms/delivery-reports/getByPhoneNumber.ts) | `BATCH_ID`, `RECIPIENT_PHONE_NUMBER` | +| | [./src/sms/delivery-reports/getForNumber.ts](./src/sms/delivery-reports/getForNumber.ts) | `BATCH_ID`, `RECIPIENT_PHONE_NUMBER` | | Inbounds | [./src/sms/inbounds/list.ts](./src/sms/inbounds/list.ts) | | | | [./src/sms/inbounds/get.ts](./src/sms/inbounds/get.ts) | `INBOUND_ID` | diff --git a/examples/simple-examples/package.json b/examples/simple-examples/package.json index b733d0ff..b85dc5eb 100644 --- a/examples/simple-examples/package.json +++ b/examples/simple-examples/package.json @@ -104,7 +104,7 @@ "sms:batches:delivery-feedback": "ts-node src/sms/batches/delivery-feedback.ts", "sms:delivery-reports:list": "ts-node src/sms/delivery-reports/list.ts", "sms:delivery-reports:getByBatchId": "ts-node src/sms/delivery-reports/getByBatchId.ts", - "sms:delivery-reports:getByPhoneNumber": "ts-node src/sms/delivery-reports/getByPhoneNumber.ts", + "sms:delivery-reports:getForNumber": "ts-node src/sms/delivery-reports/getForNumber.ts", "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", diff --git a/examples/simple-examples/src/sms/delivery-reports/getByPhoneNumber.ts b/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts similarity index 93% rename from examples/simple-examples/src/sms/delivery-reports/getByPhoneNumber.ts rename to examples/simple-examples/src/sms/delivery-reports/getForNumber.ts index bb092b47..708c1981 100644 --- a/examples/simple-examples/src/sms/delivery-reports/getByPhoneNumber.ts +++ b/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts @@ -23,7 +23,7 @@ import { GetDeliveryReportByPhoneNumberRequestData } from '@sinch/sdk-core'; const sinchClient = initSmsClient(); let response; try { - response = await sinchClient.sms.deliveryReports.getByPhoneNumber(requestData); + response = await sinchClient.sms.deliveryReports.getForNumber(requestData); } catch (error) { console.error(`ERROR: Impossible to retrieve the delivery report by batch ID ${requestData.batch_id} for the recipient ${requestData.recipient_msisdn}`); throw error; diff --git a/examples/simple-examples/src/sms/delivery-reports/list.ts b/examples/simple-examples/src/sms/delivery-reports/list.ts index 2a681128..9c894bd0 100644 --- a/examples/simple-examples/src/sms/delivery-reports/list.ts +++ b/examples/simple-examples/src/sms/delivery-reports/list.ts @@ -1,6 +1,7 @@ import { getPrintFormat, initSmsClient, printFullResponse } from '../../config'; import { - GetDeliveryReportsRequestData, PageResult, + ListDeliveryReportsRequestData, + PageResult, RecipientDeliveryReport, } from '@sinch/sdk-core'; @@ -24,7 +25,7 @@ const populateDeliveryReportsList = ( oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); oneWeekAgo.setHours(0, 0, 0, 0); - const requestData: GetDeliveryReportsRequestData= { + const requestData: ListDeliveryReportsRequestData= { start_date: oneWeekAgo, }; diff --git a/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.jest.fixture.ts b/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.jest.fixture.ts index 0cfe10ef..365bc547 100644 --- a/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.jest.fixture.ts +++ b/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.jest.fixture.ts @@ -1,4 +1,4 @@ -import { DeliveryReportsApi, GetDeliveryReportByBatchIdRequestData, GetDeliveryReportByPhoneNumberRequestData, GetDeliveryReportsRequestData } from './delivery-reports-api'; +import { DeliveryReportsApi, GetDeliveryReportByBatchIdRequestData, GetDeliveryReportByPhoneNumberRequestData, ListDeliveryReportsRequestData } from './delivery-reports-api'; import { DeliveryReport, RecipientDeliveryReport } from '../../../models'; import { ApiListPromise } from '@sinch/sdk-client'; @@ -10,12 +10,12 @@ export class DeliveryReportsApiFixture implements Partial, [GetDeliveryReportByBatchIdRequestData]> = jest.fn(); /** - * Fixture associated to function getDeliveryReportByPhoneNumber + * Fixture associated to function getForNumber */ - public getByPhoneNumber: jest.Mock, + public getForNumber: jest.Mock, [GetDeliveryReportByPhoneNumberRequestData]> = jest.fn(); /** * Fixture associated to function list */ - public list: jest.Mock, [GetDeliveryReportsRequestData]> = jest.fn(); + public list: jest.Mock, [ListDeliveryReportsRequestData]> = jest.fn(); } diff --git a/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.ts b/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.ts index a8625bbf..614f76f6 100644 --- a/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.ts +++ b/packages/sms/src/rest/v1/delivery-reports/delivery-reports-api.ts @@ -30,7 +30,7 @@ export interface GetDeliveryReportByPhoneNumberRequestData { /** Phone number for which you to want to search. */ 'recipient_msisdn': string; } -export interface GetDeliveryReportsRequestData { +export interface ListDeliveryReportsRequestData { /** The page number starting from 0. */ 'page'?: number; /** Determines the size of a page. */ @@ -95,7 +95,7 @@ export class DeliveryReportsApi extends SmsDomainApi { * A recipient delivery report contains the message status for a single recipient phone number. * @param { GetDeliveryReportByPhoneNumberRequestData } data - The data to provide to the API call. */ - public async getByPhoneNumber(data: GetDeliveryReportByPhoneNumberRequestData): Promise { + public async getForNumber(data: GetDeliveryReportByPhoneNumberRequestData): Promise { this.client = this.getSinchClient(); const getParams = this.client.extractQueryParams(data, [] as never[]); const headers: { [key: string]: string | undefined } = { @@ -121,14 +121,14 @@ export class DeliveryReportsApi extends SmsDomainApi { /** * Retrieve a list of delivery reports * Get a list of finished delivery reports. This operation supports pagination. - * @param { GetDeliveryReportsRequestData } data - The data to provide to the API call. + * @param { ListDeliveryReportsRequestData } data - The data to provide to the API call. * @return {ApiListPromise} */ - public list(data: GetDeliveryReportsRequestData): ApiListPromise { + public list(data: ListDeliveryReportsRequestData): ApiListPromise { this.client = this.getSinchClient(); data['page'] = data['page'] !== undefined ? data['page'] : 0; data['page_size'] = data['page_size'] !== undefined ? data['page_size'] : 30; - const getParams = this.client.extractQueryParams( + const getParams = this.client.extractQueryParams( data, ['page', 'page_size', 'start_date', 'end_date', 'status', 'code', 'client_reference'], ); diff --git a/packages/sms/tests/rest/v1/delivery-reports/delivery-reports-api.test.ts b/packages/sms/tests/rest/v1/delivery-reports/delivery-reports-api.test.ts index 8d85924e..84fe0c0d 100644 --- a/packages/sms/tests/rest/v1/delivery-reports/delivery-reports-api.test.ts +++ b/packages/sms/tests/rest/v1/delivery-reports/delivery-reports-api.test.ts @@ -5,7 +5,7 @@ import { DeliveryReportsApiFixture, GetDeliveryReportByBatchIdRequestData, GetDeliveryReportByPhoneNumberRequestData, - GetDeliveryReportsRequestData, + ListDeliveryReportsRequestData, RecipientDeliveryReport, } from '../../../../src'; @@ -74,20 +74,20 @@ describe('DeliveryReportsApi', () => { }; // When - fixture.getByPhoneNumber.mockResolvedValue(expectedResponse); - deliveryReportsApi.getByPhoneNumber = fixture.getByPhoneNumber; - const response = await deliveryReportsApi.getByPhoneNumber(requestData); + fixture.getForNumber.mockResolvedValue(expectedResponse); + deliveryReportsApi.getForNumber = fixture.getForNumber; + const response = await deliveryReportsApi.getForNumber(requestData); // Then expect(response).toEqual(expectedResponse); - expect(fixture.getByPhoneNumber).toHaveBeenCalledWith(requestData); + expect(fixture.getForNumber).toHaveBeenCalledWith(requestData); }); }); describe ('getDeliveryReports', () => { it('should make a GET request to list the delivery reports', async () => { // Given - const requestData: GetDeliveryReportsRequestData = {}; + const requestData: ListDeliveryReportsRequestData = {}; const mockData: RecipientDeliveryReport[] = [ { batch_id: '01HF28S9AAGRKWP2CY92BJB569',