Skip to content

Commit

Permalink
DEVEXP-421: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed May 7, 2024
1 parent 53bceb0 commit a073613
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ElasticSipTrunkingDomainApi } from '../../../src/rest/v1/elastic-sip-trunking-domain-api';
import { ApiHostname, UnifiedCredentials } from '@sinch/sdk-client';

describe('Elastic SIP Trunking API', () => {
let elasticSipTrunkingApi: ElasticSipTrunkingDomainApi;
let params: UnifiedCredentials & Pick<ApiHostname, 'elasticSipTrunkingHostname'>;
const CUSTOM_HOSTNAME = 'https://new.host.name';

beforeEach(() => {
params = {
projectId: 'PROJECT_ID',
keyId: 'KEY_ID',
keySecret: 'KEY_SECRET',
};
});

it('should initialize the client with the default hostname', () => {
elasticSipTrunkingApi = new ElasticSipTrunkingDomainApi(params, 'dummy');
elasticSipTrunkingApi.getSinchClient();
expect(elasticSipTrunkingApi.client).toBeDefined();
expect(elasticSipTrunkingApi.client?.apiClientOptions.hostname).toBe('https://elastic-trunking.api.sinch.com');
});

it('should use the hostname parameter', () => {
params.elasticSipTrunkingHostname = CUSTOM_HOSTNAME;
elasticSipTrunkingApi = new ElasticSipTrunkingDomainApi(params, 'dummy');
elasticSipTrunkingApi.getSinchClient();
expect(elasticSipTrunkingApi.client?.apiClientOptions.hostname).toBe(CUSTOM_HOSTNAME);
});

it('should set a custom URL', () => {
elasticSipTrunkingApi = new ElasticSipTrunkingDomainApi(params, 'dummy');
elasticSipTrunkingApi.setHostname(CUSTOM_HOSTNAME);
expect(elasticSipTrunkingApi.client).toBeDefined();
expect(elasticSipTrunkingApi.client?.apiClientOptions.hostname).toBe(CUSTOM_HOSTNAME);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { SinchClientParameters } from '@sinch/sdk-client';
import {
AccessControlListApi, CallsHistoryApi,
CountryPermissionsApi,
ElasticSipTrunkingService,
SipEndpointsApi,
SipTrunksApi,
} from '../../../src';

describe('Elastic SIP Trunking Service', () => {
const DEFAULT_HOSTNAME = 'https://elastic-trunking.api.sinch.com';
const CUSTOM_HOSTNAME = 'https://new.host.name';

it('should initialize the APIs', () => {
// Given
const params: SinchClientParameters = {
projectId: 'PROJECT_ID',
keyId: 'KEY_ID',
keySecret: 'KEY_SECRET',
};

// When
const elasticSipTrunkingService = new ElasticSipTrunkingService(params);

// Then
expect(elasticSipTrunkingService.sipTrunks).toBeInstanceOf(SipTrunksApi);
expect(elasticSipTrunkingService.sipEndpoints).toBeInstanceOf(SipEndpointsApi);
expect(elasticSipTrunkingService.accessControlList).toBeInstanceOf(AccessControlListApi);
expect(elasticSipTrunkingService.countryPermissions).toBeInstanceOf(CountryPermissionsApi);
expect(elasticSipTrunkingService.calls).toBeInstanceOf(CallsHistoryApi);
expect(elasticSipTrunkingService.sipTrunks.getSinchClient().apiClientOptions.hostname).toBe(DEFAULT_HOSTNAME);
expect(elasticSipTrunkingService.sipEndpoints.getSinchClient().apiClientOptions.hostname).toBe(DEFAULT_HOSTNAME);
expect(elasticSipTrunkingService.accessControlList.getSinchClient().apiClientOptions.hostname)
.toBe(DEFAULT_HOSTNAME);
expect(elasticSipTrunkingService.countryPermissions.getSinchClient().apiClientOptions.hostname)
.toBe(DEFAULT_HOSTNAME);
expect(elasticSipTrunkingService.calls.getSinchClient().apiClientOptions.hostname).toBe(DEFAULT_HOSTNAME);
});

it('should set a custom hostname for all AOPIs', () => {
// Given
const params: SinchClientParameters = {
projectId: 'PROJECT_ID',
keyId: 'KEY_ID',
keySecret: 'KEY_SECRET',
};
const elasticSipTrunkingService = new ElasticSipTrunkingService(params);

// When
elasticSipTrunkingService.setHostname(CUSTOM_HOSTNAME);

// Then
expect(elasticSipTrunkingService.sipTrunks.getSinchClient().apiClientOptions.hostname).toBe(CUSTOM_HOSTNAME);
expect(elasticSipTrunkingService.sipEndpoints.getSinchClient().apiClientOptions.hostname).toBe(CUSTOM_HOSTNAME);
expect(elasticSipTrunkingService.accessControlList.getSinchClient().apiClientOptions.hostname)
.toBe(CUSTOM_HOSTNAME);
expect(elasticSipTrunkingService.countryPermissions.getSinchClient().apiClientOptions.hostname)
.toBe(CUSTOM_HOSTNAME);
expect(elasticSipTrunkingService.calls.getSinchClient().apiClientOptions.hostname).toBe(CUSTOM_HOSTNAME);
});

});

0 comments on commit a073613

Please sign in to comment.