Skip to content

Commit

Permalink
DEVEXP-352: Rename getByPhoneNumber method
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed Mar 19, 2024
1 parent 1761b10 commit 25732db
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions examples/simple-examples/src/sms/delivery-reports/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getPrintFormat, initSmsClient, printFullResponse } from '../../config';
import {
GetDeliveryReportsRequestData, PageResult,
ListDeliveryReportsRequestData,
PageResult,
RecipientDeliveryReport,
} from '@sinch/sdk-core';

Expand All @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -10,12 +10,12 @@ export class DeliveryReportsApiFixture implements Partial<Readonly<DeliveryRepor
public get: jest.Mock<Promise<DeliveryReport>,
[GetDeliveryReportByBatchIdRequestData]> = jest.fn();
/**
* Fixture associated to function getDeliveryReportByPhoneNumber
* Fixture associated to function getForNumber
*/
public getByPhoneNumber: jest.Mock<Promise<RecipientDeliveryReport>,
public getForNumber: jest.Mock<Promise<RecipientDeliveryReport>,
[GetDeliveryReportByPhoneNumberRequestData]> = jest.fn();
/**
* Fixture associated to function list
*/
public list: jest.Mock<ApiListPromise<RecipientDeliveryReport>, [GetDeliveryReportsRequestData]> = jest.fn();
public list: jest.Mock<ApiListPromise<RecipientDeliveryReport>, [ListDeliveryReportsRequestData]> = jest.fn();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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<RecipientDeliveryReport> {
public async getForNumber(data: GetDeliveryReportByPhoneNumberRequestData): Promise<RecipientDeliveryReport> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<GetDeliveryReportByPhoneNumberRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
Expand All @@ -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<RecipientDeliveryReport>}
*/
public list(data: GetDeliveryReportsRequestData): ApiListPromise<RecipientDeliveryReport> {
public list(data: ListDeliveryReportsRequestData): ApiListPromise<RecipientDeliveryReport> {
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<GetDeliveryReportsRequestData>(
const getParams = this.client.extractQueryParams<ListDeliveryReportsRequestData>(
data,
['page', 'page_size', 'start_date', 'end_date', 'status', 'code', 'client_reference'],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DeliveryReportsApiFixture,
GetDeliveryReportByBatchIdRequestData,
GetDeliveryReportByPhoneNumberRequestData,
GetDeliveryReportsRequestData,
ListDeliveryReportsRequestData,
RecipientDeliveryReport,
} from '../../../../src';

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 25732db

Please sign in to comment.