Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-508: E2E ElasticSipTrunking/SipEndpoints #120

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface CreateSipEndpointRequestData {
/** The ID of the SIP trunk. */
'sipTrunkId': string;
/** The body containing the SIP Endpoint to create for the SIP trunk */
'createSipEndpointRequestBody': SipEndpoint;
'createSipEndpointRequestBody': Omit<SipEndpoint, 'id' | 'sipTrunkId' | 'createTime' | 'updateTime'>;
}
export interface DeleteSipEndpointRequestData {
/** The ID of the SIP trunk. */
Expand Down Expand Up @@ -32,5 +32,5 @@ export interface UpdateSipEndpointRequestData {
/** The ID of the SIP endpoint. */
'sipEndpointId': string;
/** The body containing the SIP Endpoint details to update */
'updateSipEndpointRequestBody': SipEndpoint;
'updateSipEndpointRequestBody': Omit<SipEndpoint, 'id' | 'sipTrunkId' | 'createTime' | 'updateTime'>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ export class SipEndpointsApi extends ElasticSipTrunkingDomainApi {
*/
public list(data: ListSipEndpointsRequestData): ApiListPromise<SipEndpoint> {
this.client = this.getSinchClient();
data['page'] = data['page'] !== undefined ? data['page'] : 1;
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
data['pageSize'] = data['pageSize'] !== undefined ? data['pageSize'] : 1000;
const getParams = this.client.extractQueryParams<ListSipEndpointsRequestData>(data, ['page', 'pageSize']);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
Expand All @@ -111,7 +109,7 @@ export class SipEndpointsApi extends ElasticSipTrunkingDomainApi {
const operationProperties: PaginatedApiProperties = {
pagination: PaginationEnum.PAGE2,
apiName: this.apiName,
operationId: 'GetSipEndpoint',
operationId: 'GetSipEndpoints',
dataKey: 'endpoints',
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { ElasticSipTrunking, ElasticSipTrunkingService, SipEndpointsApi } from '../../../../src';
import { Given, Then, When } from '@cucumber/cucumber';
import assert from 'assert';
import { PageResult } from '@sinch/sdk-client';

let sipEndpointsApi: SipEndpointsApi;
let sipEndpoint: ElasticSipTrunking.SipEndpoint;
let listResponse: PageResult<ElasticSipTrunking.SipEndpoint>;
let sipEndpointsList: ElasticSipTrunking.SipEndpoint[];
let pagesIteration: number;
let deleteSipEndpointResponse: void;

Given('the Elastic SIP Trunking service "SIP Endpoints" is available', function () {
const elasticSipTrunkingService = new ElasticSipTrunkingService({
projectId: 'tinyfrog-jump-high-over-lilypadbasin',
keyId: 'keyId',
keySecret: 'keySecret',
authHostname: 'http://localhost:3011',
elasticSipTrunkingHostname: 'http://localhost:3016',
});
sipEndpointsApi = elasticSipTrunkingService.sipEndpoints;
});

When('I send a request to create a SIP Endpoint', async () => {
sipEndpoint = await sipEndpointsApi.create({
sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1',
createSipEndpointRequestBody: {
name: 'Capsule Corp Endpoint',
address: '127.0.0.1',
priority: 2,
},
});
});

Then('the SIP Endpoint is created', () => {
assert.equal(sipEndpoint.id, '01W4FFL35P4NC4K35SIPENDP01');
assert.equal(sipEndpoint.sipTrunkId, '01W4FFL35P4NC4K35SIPTRUNK1');
assert.equal(sipEndpoint.name, 'Capsule Corp Endpoint');
assert.equal(sipEndpoint.address, '127.0.0.1');
assert.equal(sipEndpoint.port, 5060);
assert.equal(sipEndpoint.transport, 'UDP');
assert.equal(sipEndpoint.priority, 2);
assert.equal(sipEndpoint.enabled, true);
assert.deepEqual(sipEndpoint.createTime, new Date('2024-06-06T14:42:42.337854345Z'));
assert.equal(sipEndpoint.updateTime, null);
});

When('I send a request to list the existing SIP Endpoints', async () => {
listResponse = await sipEndpointsApi.list({
sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1',
});
});

Then('the response contains {string} SIP Endpoints', (expectedAnswer: string) => {
const expectedSipEndpointsCount = parseInt(expectedAnswer, 10);
assert.equal(listResponse.data.length, expectedSipEndpointsCount);
});

When('I send a request to list all the SIP Endpoints', async () => {
sipEndpointsList = [];
for await (const sipEndpoint of sipEndpointsApi.list({ sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1' })) {
sipEndpointsList.push(sipEndpoint);
}
});

When('I iterate manually over the SIP Endpoints pages', async () => {
sipEndpointsList = [];
listResponse = await sipEndpointsApi.list({ sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1' });
sipEndpointsList.push(...listResponse.data);
pagesIteration = 1;
let reachedEndOfPages = false;
while (!reachedEndOfPages) {
if (listResponse.hasNextPage) {
listResponse = await listResponse.nextPage();
sipEndpointsList.push(...listResponse.data);
pagesIteration++;
} else {
reachedEndOfPages = true;
}
}
});

Then('the SIP Endpoints list contains {string} SIP Endpoints', (expectedAnswer: string) => {
const expectedSipEndpointsCount = parseInt(expectedAnswer, 10);
assert.equal(sipEndpointsList.length, expectedSipEndpointsCount);
});

Then('the SIP Endpoints iteration result contains the data from {string} pages', (expectedAnswer: string) => {
const expectedPagesCount = parseInt(expectedAnswer, 10);
assert.equal(pagesIteration, expectedPagesCount);
});

When('I send a request to retrieve a SIP Endpoint', async () => {
sipEndpoint = await sipEndpointsApi.get({
sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1',
sipEndpointId: '01W4FFL35P4NC4K35SIPENDP01',
});
});

Then('the response contains the SIP Endpoint details', () => {
assert.equal(sipEndpoint.id, '01W4FFL35P4NC4K35SIPENDP01');
assert.deepEqual(sipEndpoint.createTime, new Date('2024-06-06T14:42:42Z'));
});

When('I send a request to update a SIP Endpoint', async () => {
sipEndpoint = await sipEndpointsApi.update({
sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1',
sipEndpointId: '01W4FFL35P4NC4K35SIPENDP01',
updateSipEndpointRequestBody: {
name: 'Capsule Corp Endpoint - updated',
address: '127.0.0.2',
priority: 3,
port: 5061,
transport: 'TCP',
enabled: false,
},
});
});

Then('the response contains the SIP Endpoint details with updated data', () => {
assert.equal(sipEndpoint.id, '01W4FFL35P4NC4K35SIPENDP01');
assert.equal(sipEndpoint.name, 'Capsule Corp Endpoint - updated');
assert.equal(sipEndpoint.address, '127.0.0.2');
assert.equal(sipEndpoint.port, 5061);
assert.equal(sipEndpoint.transport, 'TCP');
assert.equal(sipEndpoint.priority, 3);
assert.equal(sipEndpoint.enabled, false);
assert.deepEqual(sipEndpoint.createTime, new Date('2024-06-06T14:42:42Z'));
assert.deepEqual(sipEndpoint.updateTime, new Date('2024-06-06T14:45:11.428052267Z'));
});

When('I send a request to delete a SIP Endpoint', async () => {
deleteSipEndpointResponse = await sipEndpointsApi.delete({
sipTrunkId: '01W4FFL35P4NC4K35SIPTRUNK1',
sipEndpointId: '01W4FFL35P4NC4K35SIPENDP01',
});
});

Then('the delete SIP Endpoint response contains no data', () => {
assert.deepEqual(deleteSipEndpointResponse, {} );
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ When('I send a request to list the existing SIP trunks', async () => {
});

Then('the response contains {string} SIP trunks', (expectedAnswer: string) => {
const expectedMessagesCount = parseInt(expectedAnswer, 10);
assert.equal(listResponse.data.length, expectedMessagesCount);
const expectedSipTrunksCount = parseInt(expectedAnswer, 10);
assert.equal(listResponse.data.length, expectedSipTrunksCount);
});

When('I send a request to list all the SIP trunks', async () => {
Expand Down Expand Up @@ -81,8 +81,8 @@ When('I iterate manually over the SIP trunks pages', async () => {
});

Then('the SIP trunks list contains {string} SIP trunks', (expectedAnswer: string) => {
const expectedServices = parseInt(expectedAnswer, 10);
assert.equal(sipTrunksList.length, expectedServices);
const expectedSipTrunksCount = parseInt(expectedAnswer, 10);
assert.equal(sipTrunksList.length, expectedSipTrunksCount);
});

Then('the SIP trunks iteration result contains the data from {string} pages', (expectedAnswer: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const buggyOperationIds: string[] = [
'UpdateSipTrunk',
'GetSipTrunkById',
'GetSipTrunks',
'CreateSipEndpoint',
'UpdateSipEndpoint',
'GetSipEndpointById',
'GetSipEndpoints',

];

const buggyFields: Record<string, string[]> = {
Expand All @@ -21,6 +26,10 @@ const buggyFields: Record<string, string[]> = {
'UpdateSipTrunk': ['createTime', 'updateTime'],
'GetSipTrunkById': ['createTime', 'updateTime'],
'GetSipTrunks': ['createTime', 'updateTime'],
'CreateSipEndpoint': ['createTime'],
JPPortier marked this conversation as resolved.
Show resolved Hide resolved
'UpdateSipEndpoint': ['createTime', 'updateTime'],
'GetSipEndpointById': ['createTime', 'updateTime'],
'GetSipEndpoints': ['createTime', 'updateTime'],
};

export class TimezoneResponse<V extends Record<string, any> | undefined = Record<string, any>>
Expand Down
Loading