mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
add sip_gateways
This commit is contained in:
@@ -27,6 +27,8 @@ DROP TABLE IF EXISTS `accounts`;
|
||||
|
||||
DROP TABLE IF EXISTS `service_providers`;
|
||||
|
||||
DROP TABLE IF EXISTS `sip_gateways`;
|
||||
|
||||
DROP TABLE IF EXISTS `voip_carriers`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `applications`
|
||||
@@ -148,15 +150,6 @@ CREATE TABLE IF NOT EXISTS `api_keys`
|
||||
PRIMARY KEY (`api_key_sid`)
|
||||
) ENGINE=InnoDB COMMENT='An authorization token that is used to access the REST api';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `subscriptions`
|
||||
(
|
||||
`id` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE ,
|
||||
`subscription_sid` CHAR(36) NOT NULL UNIQUE ,
|
||||
`registration_sid` CHAR(36) NOT NULL,
|
||||
`event` VARCHAR(255),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB COMMENT='An active sip subscription';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `accounts`
|
||||
(
|
||||
`account_sid` CHAR(36) NOT NULL UNIQUE ,
|
||||
@@ -166,9 +159,19 @@ CREATE TABLE IF NOT EXISTS `accounts`
|
||||
`registration_hook` VARCHAR(255),
|
||||
`hook_basic_auth_user` VARCHAR(255),
|
||||
`hook_basic_auth_password` VARCHAR(255),
|
||||
`is_active` BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (`account_sid`)
|
||||
) ENGINE=InnoDB COMMENT='A single end-user of the platform';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `subscriptions`
|
||||
(
|
||||
`id` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE ,
|
||||
`subscription_sid` CHAR(36) NOT NULL UNIQUE ,
|
||||
`registration_sid` CHAR(36) NOT NULL,
|
||||
`event` VARCHAR(255),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB COMMENT='An active sip subscription';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `voip_carriers`
|
||||
(
|
||||
`voip_carrier_sid` CHAR(36) NOT NULL UNIQUE ,
|
||||
@@ -187,6 +190,18 @@ CREATE TABLE IF NOT EXISTS `phone_numbers`
|
||||
PRIMARY KEY (`phone_number_sid`)
|
||||
) ENGINE=InnoDB COMMENT='A phone number that has been assigned to an account';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sip_gateways`
|
||||
(
|
||||
`sip_gateway_sid` CHAR(36),
|
||||
`ipv4` VARCHAR(32) NOT NULL,
|
||||
`port` INTEGER NOT NULL DEFAULT 5060,
|
||||
`inbound` BOOLEAN NOT NULL,
|
||||
`outbound` BOOLEAN NOT NULL,
|
||||
`voip_carrier_sid` CHAR(36) NOT NULL,
|
||||
`is_active` BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (`sip_gateway_sid`)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX `applications_idx_name` ON `applications` (`account_sid`,`name`);
|
||||
|
||||
CREATE INDEX `applications_application_sid_idx` ON `applications` (`application_sid`);
|
||||
@@ -234,14 +249,14 @@ ALTER TABLE `api_keys` ADD FOREIGN KEY account_sid_idxfk_2 (`account_sid`) REFER
|
||||
CREATE INDEX `api_keys_service_provider_sid_idx` ON `api_keys` (`service_provider_sid`);
|
||||
ALTER TABLE `api_keys` ADD FOREIGN KEY service_provider_sid_idxfk (`service_provider_sid`) REFERENCES `service_providers` (`service_provider_sid`);
|
||||
|
||||
ALTER TABLE `subscriptions` ADD FOREIGN KEY registration_sid_idxfk (`registration_sid`) REFERENCES `registrations` (`registration_sid`);
|
||||
|
||||
CREATE INDEX `accounts_account_sid_idx` ON `accounts` (`account_sid`);
|
||||
CREATE INDEX `accounts_name_idx` ON `accounts` (`name`);
|
||||
CREATE INDEX `accounts_sip_realm_idx` ON `accounts` (`sip_realm`);
|
||||
CREATE INDEX `accounts_service_provider_sid_idx` ON `accounts` (`service_provider_sid`);
|
||||
ALTER TABLE `accounts` ADD FOREIGN KEY service_provider_sid_idxfk_1 (`service_provider_sid`) REFERENCES `service_providers` (`service_provider_sid`);
|
||||
|
||||
ALTER TABLE `subscriptions` ADD FOREIGN KEY registration_sid_idxfk (`registration_sid`) REFERENCES `registrations` (`registration_sid`);
|
||||
|
||||
CREATE INDEX `voip_carriers_voip_carrier_sid_idx` ON `voip_carriers` (`voip_carrier_sid`);
|
||||
CREATE INDEX `voip_carriers_name_idx` ON `voip_carriers` (`name`);
|
||||
CREATE INDEX `phone_numbers_phone_number_sid_idx` ON `phone_numbers` (`phone_number_sid`);
|
||||
@@ -251,3 +266,7 @@ ALTER TABLE `phone_numbers` ADD FOREIGN KEY voip_carrier_sid_idxfk (`voip_carrie
|
||||
ALTER TABLE `phone_numbers` ADD FOREIGN KEY account_sid_idxfk_3 (`account_sid`) REFERENCES `accounts` (`account_sid`);
|
||||
|
||||
ALTER TABLE `phone_numbers` ADD FOREIGN KEY application_sid_idxfk_2 (`application_sid`) REFERENCES `applications` (`application_sid`);
|
||||
|
||||
CREATE UNIQUE INDEX `sip_gateways_sip_gateway_idx_hostport` ON `sip_gateways` (`ipv4`,`port`);
|
||||
|
||||
ALTER TABLE `sip_gateways` ADD FOREIGN KEY voip_carrier_sid_idxfk_1 (`voip_carrier_sid`) REFERENCES `voip_carriers` (`voip_carrier_sid`);
|
||||
|
||||
109
db/jambones.sqs
109
db/jambones.sqs
@@ -104,8 +104,8 @@
|
||||
<comment><![CDATA[An external organization that can provide sip trunking and DIDs]]></comment>
|
||||
<tableType><![CDATA[InnoDB]]></tableType>
|
||||
<location>
|
||||
<x>84.00</x>
|
||||
<y>40.00</y>
|
||||
<x>57.00</x>
|
||||
<y>238.00</y>
|
||||
</location>
|
||||
<size>
|
||||
<width>266.00</width>
|
||||
@@ -353,7 +353,7 @@
|
||||
</location>
|
||||
<size>
|
||||
<width>289.00</width>
|
||||
<height>160.00</height>
|
||||
<height>180.00</height>
|
||||
</size>
|
||||
<zorder>10</zorder>
|
||||
<SQLField>
|
||||
@@ -413,6 +413,13 @@
|
||||
<type><![CDATA[VARCHAR(255)]]></type>
|
||||
<uid><![CDATA[2FF5162F-782B-43A5-BFF0-BD06A82387EB]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[is_active]]></name>
|
||||
<type><![CDATA[BOOLEAN]]></type>
|
||||
<defaultValue><![CDATA[true]]></defaultValue>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[C7130A90-DBB4-424D-A9A9-CB203C32350C]]></uid>
|
||||
</SQLField>
|
||||
<labelWindowIndex><![CDATA[8]]></labelWindowIndex>
|
||||
<objectComment><![CDATA[A single end-user of the platform]]></objectComment>
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
@@ -716,8 +723,8 @@
|
||||
<comment><![CDATA[A phone number that has been assigned to an account]]></comment>
|
||||
<tableType><![CDATA[InnoDB]]></tableType>
|
||||
<location>
|
||||
<x>50.00</x>
|
||||
<y>262.00</y>
|
||||
<x>52.00</x>
|
||||
<y>375.00</y>
|
||||
</location>
|
||||
<size>
|
||||
<width>331.00</width>
|
||||
@@ -850,6 +857,90 @@
|
||||
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
|
||||
<uid><![CDATA[C415EB08-CA27-42B5-AE94-2681B6B6DC93]]></uid>
|
||||
</SQLTable>
|
||||
<SQLTable>
|
||||
<name><![CDATA[sip_gateways]]></name>
|
||||
<schema><![CDATA[]]></schema>
|
||||
<location>
|
||||
<x>54.00</x>
|
||||
<y>17.00</y>
|
||||
</location>
|
||||
<size>
|
||||
<width>310.00</width>
|
||||
<height>180.00</height>
|
||||
</size>
|
||||
<zorder>14</zorder>
|
||||
<SQLField>
|
||||
<name><![CDATA[sip_gateway_sid]]></name>
|
||||
<type><![CDATA[CHAR(36)]]></type>
|
||||
<primaryKey>1</primaryKey>
|
||||
<uid><![CDATA[66770F98-7390-4AEB-890F-A1A16672CE20]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[ipv4]]></name>
|
||||
<type><![CDATA[VARCHAR(32)]]></type>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[F18DB7D4-F902-4863-870C-CB07032AE17C]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[port]]></name>
|
||||
<type><![CDATA[INTEGER]]></type>
|
||||
<defaultValue><![CDATA[5060]]></defaultValue>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[26B20F1E-4DB0-48C0-90F7-CA90A06A1070]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[inbound]]></name>
|
||||
<type><![CDATA[BOOLEAN]]></type>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[CDE029DC-0C7C-400C-85E9-5005C53B7460]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[outbound]]></name>
|
||||
<type><![CDATA[BOOLEAN]]></type>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[4BD24677-82BA-4647-9873-A5245F53FF1C]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[voip_carrier_sid]]></name>
|
||||
<type><![CDATA[CHAR(36)]]></type>
|
||||
<referencesField>voip_carrier_sid</referencesField>
|
||||
<referencesTable>voip_carriers</referencesTable>
|
||||
<referencesField><![CDATA[voip_carrier_sid]]></referencesField>
|
||||
<referencesTable><![CDATA[voip_carriers]]></referencesTable>
|
||||
<sourceCardinality>4</sourceCardinality>
|
||||
<destinationCardinality>1</destinationCardinality>
|
||||
<referencesFieldUID><![CDATA[E34851EF-3C5F-4118-8425-F88EE16E38AA]]></referencesFieldUID>
|
||||
<referencesTableUID><![CDATA[3D3136A7-AFC0-4A70-AEC3-68577955CA2E]]></referencesTableUID>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[BC25D27E-54E4-4D14-B53D-D1C6254D1D72]]></uid>
|
||||
</SQLField>
|
||||
<SQLField>
|
||||
<name><![CDATA[is_active]]></name>
|
||||
<type><![CDATA[BOOLEAN]]></type>
|
||||
<defaultValue><![CDATA[true]]></defaultValue>
|
||||
<notNull><![CDATA[1]]></notNull>
|
||||
<uid><![CDATA[27D4A5BD-8093-4ADD-B5B5-D546844206F9]]></uid>
|
||||
</SQLField>
|
||||
<SQLIndex>
|
||||
<name><![CDATA[sip_gateway_idx_hostport]]></name>
|
||||
<fieldName><![CDATA[ipv4]]></fieldName>
|
||||
<fieldName><![CDATA[port]]></fieldName>
|
||||
<SQLIndexEntry>
|
||||
<name><![CDATA[ipv4]]></name>
|
||||
<prefixSize><![CDATA[]]></prefixSize>
|
||||
<fieldUid><![CDATA[F18DB7D4-F902-4863-870C-CB07032AE17C]]></fieldUid>
|
||||
</SQLIndexEntry>
|
||||
<SQLIndexEntry>
|
||||
<name><![CDATA[port]]></name>
|
||||
<prefixSize><![CDATA[]]></prefixSize>
|
||||
<fieldUid><![CDATA[26B20F1E-4DB0-48C0-90F7-CA90A06A1070]]></fieldUid>
|
||||
</SQLIndexEntry>
|
||||
<indexNamePrefix><![CDATA[sip_gateway]]></indexNamePrefix>
|
||||
<indexType><![CDATA[UNIQUE]]></indexType>
|
||||
<uid><![CDATA[1C744DE3-39BD-4EC6-B427-7EB2DD258771]]></uid>
|
||||
</SQLIndex>
|
||||
<uid><![CDATA[D8A564E2-DA41-4217-8ACE-06CF77E9BEC1]]></uid>
|
||||
</SQLTable>
|
||||
<SQLTable>
|
||||
<name><![CDATA[conferences]]></name>
|
||||
<schema><![CDATA[]]></schema>
|
||||
@@ -1056,17 +1147,17 @@
|
||||
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
|
||||
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
|
||||
<PageGridVisible><![CDATA[0]]></PageGridVisible>
|
||||
<RightSidebarWidth><![CDATA[1499.000000]]></RightSidebarWidth>
|
||||
<RightSidebarWidth><![CDATA[1276.000000]]></RightSidebarWidth>
|
||||
<sidebarIndex><![CDATA[2]]></sidebarIndex>
|
||||
<snapToGrid><![CDATA[0]]></snapToGrid>
|
||||
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
|
||||
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
|
||||
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
|
||||
<windowHeight><![CDATA[1417.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[3218.000000]]></windowLocationX>
|
||||
<windowHeight><![CDATA[1027.000000]]></windowHeight>
|
||||
<windowLocationX><![CDATA[115.000000]]></windowLocationX>
|
||||
<windowLocationY><![CDATA[-0.000000]]></windowLocationY>
|
||||
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
|
||||
<windowWidth><![CDATA[1776.000000]]></windowWidth>
|
||||
<windowWidth><![CDATA[1553.000000]]></windowWidth>
|
||||
</SQLDocumentInfo>
|
||||
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
|
||||
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>
|
||||
|
||||
43
lib/models/sip-gateway.js
Normal file
43
lib/models/sip-gateway.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const Model = require('./model');
|
||||
|
||||
class SipGateway extends Model {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
SipGateway.table = 'sip_gateways';
|
||||
SipGateway.fields = [
|
||||
{
|
||||
name: 'sip_gateway_sid',
|
||||
type: 'string',
|
||||
primaryKey: true
|
||||
},
|
||||
{
|
||||
name: 'voip_carrier_sid',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
name: 'ipv4',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'port',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
name: 'inbound',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
name: 'outbound',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
name: 'is_active',
|
||||
type: 'number'
|
||||
}
|
||||
];
|
||||
|
||||
module.exports = SipGateway;
|
||||
@@ -10,6 +10,7 @@ function isAdminScope(req, res, next) {
|
||||
|
||||
api.use('/ServiceProviders', isAdminScope, require('./service-providers'));
|
||||
api.use('/VoipCarriers', isAdminScope, require('./voip-carriers'));
|
||||
api.use('/SipGateways', isAdminScope, require('./sip-gateways'));
|
||||
api.use('/PhoneNumbers', isAdminScope, require('./phone-numbers'));
|
||||
api.use('/ApiKeys', require('./api-keys'));
|
||||
api.use('/Accounts', require('./accounts'));
|
||||
|
||||
9
lib/routes/api/sip-gateways.js
Normal file
9
lib/routes/api/sip-gateways.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const router = require('express').Router();
|
||||
const SipGateway = require('../../models/sip-gateway');
|
||||
const decorate = require('./decorate');
|
||||
const preconditions = {};
|
||||
|
||||
|
||||
decorate(router, SipGateway, ['*'], preconditions);
|
||||
|
||||
module.exports = router;
|
||||
@@ -210,7 +210,144 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
|
||||
|
||||
/SipGateways:
|
||||
post:
|
||||
summary: create sip gateway
|
||||
operationId: createSipGateway
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
voip_carrier_sid:
|
||||
type: string
|
||||
description: voip carrier that provides this gateway
|
||||
format: uuid
|
||||
ipv4:
|
||||
type: string
|
||||
port:
|
||||
type: number
|
||||
is_active:
|
||||
type: boolean
|
||||
inbound:
|
||||
type: boolean
|
||||
outbound:
|
||||
type: boolean
|
||||
required:
|
||||
- voip_carrier_sid
|
||||
- ipv4
|
||||
responses:
|
||||
201:
|
||||
description: sip gateway successfully created
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SuccessfulAdd'
|
||||
400:
|
||||
description: bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
422:
|
||||
description: unprocessable entity
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
500:
|
||||
description: system error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
get:
|
||||
summary: list sip gateways
|
||||
operationId: listSipGateways
|
||||
responses:
|
||||
200:
|
||||
description: list of sip gateways
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/SipGateway'
|
||||
500:
|
||||
description: system error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
/SipGateways/{SipGatewaySid}:
|
||||
parameters:
|
||||
- name: SipGatewaySid
|
||||
in: path
|
||||
required: true
|
||||
style: simple
|
||||
explode: false
|
||||
schema:
|
||||
type: string
|
||||
delete:
|
||||
summary: delete a sip gateway
|
||||
operationId: deleteSipGateway
|
||||
responses:
|
||||
204:
|
||||
description: sip gateway successfully deleted
|
||||
404:
|
||||
description: sip gateway not found
|
||||
500:
|
||||
description: system error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
get:
|
||||
summary: retrieve sip gateway
|
||||
operationId: getSipGateway
|
||||
responses:
|
||||
200:
|
||||
description: sip gateway found
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VoipCarrier'
|
||||
404:
|
||||
description: sip gateway not found
|
||||
500:
|
||||
description: system error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
put:
|
||||
summary: update sip gateway
|
||||
operationId: updateSipGateway
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SipGateway'
|
||||
responses:
|
||||
204:
|
||||
description: sip gateway updated
|
||||
400:
|
||||
description: bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
404:
|
||||
description: sip gateway not found
|
||||
500:
|
||||
description: system error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GeneralError'
|
||||
|
||||
/PhoneNumbers:
|
||||
post:
|
||||
summary: provision a phone number into inventory from a Voip Carrier
|
||||
@@ -1051,6 +1188,30 @@ components:
|
||||
required:
|
||||
- voip_carrier_sid
|
||||
- name
|
||||
SipGateway:
|
||||
type: object
|
||||
properties:
|
||||
sip_gateway_sid:
|
||||
type: string
|
||||
format: uuid
|
||||
ipv4:
|
||||
type: string
|
||||
port:
|
||||
type: number
|
||||
voip_carrier_sid:
|
||||
type: string
|
||||
format: uuid
|
||||
is_active:
|
||||
type: boolean
|
||||
inbound:
|
||||
type: boolean
|
||||
outbound:
|
||||
type: boolean
|
||||
required:
|
||||
- sip_gateway_sid
|
||||
- voip_carrier_sid
|
||||
- ipv4
|
||||
- port
|
||||
Account:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require('./create-test-db');
|
||||
require('./sip-gateways');
|
||||
require('./service-providers');
|
||||
require('./voip-carriers');
|
||||
require('./accounts');
|
||||
|
||||
82
test/sip-gateways.js
Normal file
82
test/sip-gateways.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const test = require('tape').test ;
|
||||
const ADMIN_TOKEN = '38700987-c7a4-4685-a5bb-af378f9734de';
|
||||
const authAdmin = {bearer: ADMIN_TOKEN};
|
||||
const request = require('request-promise-native').defaults({
|
||||
baseUrl: 'http://127.0.0.1:3000/v1'
|
||||
});
|
||||
const {createVoipCarrier, deleteObjectBySid} = require('./utils');
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||
});
|
||||
|
||||
test('sip gateway tests', async(t) => {
|
||||
const app = require('../app');
|
||||
let sid;
|
||||
try {
|
||||
let result;
|
||||
const voip_carrier_sid = await createVoipCarrier(request);
|
||||
|
||||
/* add a sip gateway */
|
||||
result = await request.post('/SipGateways', {
|
||||
resolveWithFullResponse: true,
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
body: {
|
||||
voip_carrier_sid,
|
||||
ipv4: '192.168.1.1',
|
||||
inbound: true,
|
||||
outbound: true
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created sip gateway ');
|
||||
const sid = result.body.sid;
|
||||
|
||||
/* query all sip gateways */
|
||||
result = await request.get('/SipGateways', {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.length === 1 , 'successfully queried all sip gateways');
|
||||
|
||||
/* query one sip gateway */
|
||||
result = await request.get(`/SipGateways/${sid}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
//console.log(`result: ${JSON.stringify(result)}`);
|
||||
t.ok(result.ipv4 === '192.168.1.1' , 'successfully retrieved voip carrier by sid');
|
||||
|
||||
|
||||
/* update sip gateway */
|
||||
result = await request.put(`/SipGateways/${sid}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
body: {
|
||||
port: 5061,
|
||||
outbound: false
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 204, 'successfully updated voip carrier');
|
||||
|
||||
/* delete sip gatewas */
|
||||
result = await request.delete(`/SipGateways/${sid}`, {
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
json: true,
|
||||
auth: authAdmin
|
||||
});
|
||||
//console.log(`result: ${JSON.stringify(result)}`);
|
||||
t.ok(result.statusCode === 204, 'successfully deleted sip gateway');
|
||||
|
||||
await deleteObjectBySid(request, '/VoipCarriers', voip_carrier_sid);
|
||||
|
||||
t.end();
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user