Merge branch 'master' into buynumber-fix

This commit is contained in:
Mohammed Huzaif 2021-10-12 21:54:45 +05:30 committed by GitHub
commit 65f9b143bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 681 additions and 311 deletions

47
.github/workflows/unitTests.yml vendored Normal file
View file

@ -0,0 +1,47 @@
name: UnitTests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [6.x, 7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install request
- run: npm install
- run: npm test
coverage:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [15.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install request
- run: npm install
- run: npm test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests

View file

@ -1,7 +1,8 @@
# Plivo Node.js library
[![Version](https://img.shields.io/npm/v/plivo.svg)](https://www.npmjs.org/package/plivo)
[![Build Status](https://api.travis-ci.org/plivo/plivo-node.svg?branch=master)](https://travis-ci.org/github/plivo/plivo-node)
[![codecov](https://codecov.io/gh/plivo/plivo-node/branch/master/graph/badge.svg)](https://codecov.io/gh/plivo/plivo-node)
[![UnitTests](https://github.com/plivo/plivo-node/actions/workflows/unitTests.yml/badge.svg)](https://github.com/plivo/plivo-node/actions/workflows/unitTests.yml)
The Node.js SDK simplifies the integration of communications into your Node.js applications through the Plivo REST API. You will be able to use the SDK to make voice calls, send SMS, and generate Plivo XML to manage your call flows.
@ -55,12 +56,12 @@ Also, using `client.resources.list()` would list the first 20 resources by defau
let plivo = require('plivo');
let client = new plivo.Client();
client.messages.create(
'+14156667778',
'+14156667777',
'Hello, world!'
).then(function(response) {
console.log(response)
client.messages.create({
src: '+14156667778',
dst: '14156667777',
text: 'Hello, this is a sample text from Plivo',
}).then(function(response) {
console.log(response)
});
```
@ -127,4 +128,4 @@ console.log('Phlo run result', result);
More examples are available [here](https://github.com/plivo/plivo-examples-node). Also refer to the [guides for configuring the Express server to run various scenarios](https://www.plivo.com/docs/sms/quickstart/node-expressjs/) & use it to test out your integration in under 5 minutes.
## Reporting issues
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues).
Report any feedback or problems with this version by [opening an issue on Github](https://github.com/plivo/plivo-node/issues).

View file

@ -5,7 +5,6 @@ var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-babel-istanbul');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');
var babel = require('gulp-babel');
var del = require('del');
var isparta = require('isparta');
@ -41,7 +40,7 @@ gulp.task('pre-test', function () {
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['pre-test'], function (cb) {
gulp.task('test', gulp.series('pre-test', function (cb) {
var mochaErr;
console.log('Running tests with node version', process.version);
@ -57,23 +56,17 @@ gulp.task('test', ['pre-test'], function (cb) {
.on('end', function () {
cb(mochaErr);
});
});
}));
gulp.task('watch', function () {
gulp.watch(['lib/**/*.js', 'test/**'], ['test']);
});
gulp.task('coveralls', ['test'], function () {
if (!process.env.CI) {
console.log('ignoring coveralls report generation.');
return;
}
return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
.pipe(coveralls());
gulp.task('clean', function () {
return del('dist');
});
gulp.task('babel', ['clean'], function () {
gulp.task('babel', gulp.series('clean', function () {
return merge([
gulp.src('types/**/*.d.ts')
.pipe(gulp.dest('dist/')),
@ -81,7 +74,7 @@ gulp.task('babel', ['clean'], function () {
.pipe(babel())
.pipe(gulp.dest('dist'))
]);
});
}));
gulp.task('lintFix', function () {
return gulp.src('lib/**/*.js')
@ -96,5 +89,5 @@ gulp.task('clean', function () {
return del('dist');
});
gulp.task('prepublish', ['babel']);
gulp.task('default', ['static', 'test', 'coveralls']);
gulp.task('prepublish', gulp.series('babel'));
gulp.task('default', gulp.series('static', 'test'));

View file

@ -127,15 +127,14 @@ export class Message extends PlivoResource {
}
}
/**
* Represents a Message Interface
* @constructor
* @param {function} client - make api call
* @param {object} [data] - data of call
*/
export class MessageInterface extends PlivoResourceInterface {
constructor(client, data = {}) {
super(action, Message, idField, client);
extend(this, data);
@ -143,7 +142,6 @@ export class MessageInterface extends PlivoResourceInterface {
this[actionKey] = action;
this[klassKey] = Message;
this[idKey] = idField;
}
/**
@ -161,12 +159,13 @@ export class MessageInterface extends PlivoResourceInterface {
* @promise {object} return {@link PlivoGenericMessage} object if success
* @fail {Error} return Error
*/
send(src, dst, text, optionalParams) {
send(src, dst, text, optionalParams) {
return this.create(src, dst, text, optionalParams);
}
/**
* Create Message
* Send Message
* @method
* @param {string} src - source number
* @param {string} dst - destination number
@ -177,15 +176,36 @@ export class MessageInterface extends PlivoResourceInterface {
* @param {string} [optionalParams.method] The method used to call the url. Defaults to POST.
* @param {boolean} [optionalParams.log] If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
* @param {Array} [optionalParams.media_urls] For sending mms, specify the media urls in list of string
* @promise {object} return {@link MessageResponse} object if success
* @promise {object} return {@link PlivoGenericMessage} object if success
* @fail {Error} return Error
*/
create(src, dst, text, optionalParams, powerpackUUID) {
var isObject = arguments.length;
if (isObject == 1) {
var powerpackUUID = src.powerpackUUID;
var text = src.text;
var dst = src.dst;
var url = src.url;
var method = src.method;
var type = src.type;
var media_urls = src.media_urls;
var media_ids = src.media_ids;
var log = src.log;
var trackable = src.trackable;
var src = src.src;
}
let errors = validate([{
field: 'dst',
value: dst,
validators: ['isRequired']
}]);
field: 'dst',
value: dst,
validators: ['isRequired']
},
{
field: 'text',
value: text,
validators: ['isRequired']
},
]);
if (errors) {
return errors;
@ -206,6 +226,31 @@ export class MessageInterface extends PlivoResourceInterface {
}
let params = optionalParams || {};
if (isObject == 1) {
if (url) {
params.url = url;
}
if (method) {
params.method = method;
}
if (type) {
params.type = type;
}
if (media_urls) {
params.media_urls = media_urls;
}
if (media_ids) {
params.media_ids = media_ids;
}
if (log) {
params.log = log;
}
if (trackable) {
params.trackable = trackable;
}
}
if (src) {
params.src = src;
}
@ -214,7 +259,7 @@ export class MessageInterface extends PlivoResourceInterface {
if (powerpackUUID) {
params.powerpackUUID = powerpackUUID;
}
let client = this[clientKey];
let idField = this[idKey];
let action = this[actionKey] + (this.id ? this.id + '/' : '');
@ -292,5 +337,4 @@ export class MessageInterface extends PlivoResourceInterface {
id: messageUUID
}).listMedia();
}
}

View file

@ -271,7 +271,8 @@ export class NumberInterface extends PlivoResourceInterface {
params.numbers = numbers;
params.carrier = carrier;
params.region = region;
let client = this[clientKey];
return new Promise((resolve, reject) => {
client('POST', action, params)
.then(response => {

View file

@ -50,6 +50,12 @@ import {
} from '../resources/media.js';
import {MultiPartyCallInterface} from "../resources/multiPartyCall";
import { EndUserInterface } from "../resources/endUsers";
import { ComplianceDocumentTypeInterface } from "../resources/complianceDocumentTypes";
import { ComplianceDocumentInterface} from "../resources/complianceDocuments";
import { ComplianceRequirementInterface } from "../resources/complianceRequirements";
import { ComplianceApplicationInterface } from "../resources/complianceApplications";
export class Client {
constructor(authId, authToken, proxy) {
if (!(this instanceof Client)) {

View file

@ -31,6 +31,10 @@ exports.Response = function() {
return new Response();
};
exports.AccessToken = function(authId, authToken, username, validity, uid) {
return new AccessToken(authId, authToken, username, validity, uid);
};
exports.validateV3Signature = function(method, uri, nonce, auth_token, v3_signature, params={}) {
return validateV3Signature(method, uri, nonce, auth_token, v3_signature, params);
};

View file

@ -36,7 +36,7 @@ export function Request(config) {
return new Promise((resolve, reject) => {
// LiveCall - needs to be at top
if (method === 'GET' && action === 'Call/6653422-91b6-4716-9fad-9463daaeeec2/' && params.status === 'live') {
if (method === 'GET' && action === 'Call/6653422-91b6-4716-9fad-9463daaeeec2/?status=live') {
resolve({
response: {},
body: {
@ -52,7 +52,7 @@ export function Request(config) {
});
}
else if (method === 'GET' && action === 'Call/' && params.status === 'live') {
else if (method === 'GET' && action === 'Call/?status=live') {
resolve({
response: {},
body: {
@ -65,7 +65,7 @@ export function Request(config) {
});
}
else if (method === 'DELETE' && action === 'Request/1/') {
else if (method === 'DELETE' && action === 'Request/aaa-deeiei3-dfddd/') {
resolve({
response: {},
body: {}
@ -91,7 +91,7 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/' && method == 'GET') {
else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'GET') {
resolve({
response: {},
body: {
@ -100,22 +100,22 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/' && method == 'POST') {
else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'POST') {
resolve({
response: {},
body: {
id: 5,
call_uuid: 'aaa-deeiei3-dfddd'
"message": "call transferred",
"api_id": "08c94608-58bd-11e1-86da-adf28403fe48"
}
});
}
else if (action == 'Call/1/' && method == 'DELETE') {
else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
}
else if (action == 'Call/1/Record/' && method == 'POST') {
else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'POST') {
resolve({
response: {},
body: {
@ -126,14 +126,14 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/Record/' && method == 'DELETE') {
else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'DELETE') {
resolve({
response: {},
body: {
}
});
}
else if (action == 'Call/1/Play/' && method == 'POST') {
else if (action == 'Call/aaa-deeiei3-dfddd/Play/' && method == 'POST') {
resolve({
response: {},
body: {
@ -142,13 +142,13 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/Play/' && method == 'DELETE') {
else if (action == 'Call/aaa-deeiei3-dfddd/Play/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
}
else if (action == 'Call/1/Speak/' && method == 'DELETE') {
else if (action == 'Call/aaa-deeiei3-dfddd/Speak/' && method == 'DELETE') {
resolve({
response: {},
body: {
@ -157,7 +157,7 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/Speak/' && method == 'POST') {
else if (action == 'Call/aaa-deeiei3-dfddd/Speak/' && method == 'POST') {
resolve({
response: {},
body: {
@ -166,7 +166,7 @@ export function Request(config) {
}
});
}
else if (action == 'Call/1/DTMF/' && method == 'POST') {
else if (action == 'Call/aaa-deeiei3-dfddd/DTMF/' && method == 'POST') {
resolve({
response: {},
body: {
@ -184,7 +184,7 @@ export function Request(config) {
//
//
// Accounts
else if (action == '' && method == 'GET') {
else if (action == '/' && method == 'GET') {
resolve({
response: {},
body: {
@ -1128,7 +1128,325 @@ export function Request(config) {
}
// ============= Message ===================
else if (action == 'Media/0178eb8a-461a-4fd1-bc37-13eebfdc0676/' && method == 'GET'){
resolve({
response: {},
body: {
content_type: 'application/pdf',
media_id: '0178eb8a-461a-4fd1-bc37-13eebfdc0676',
media_url: 'https://xxxxxxx/Account/{auth_id}/Message/24d742b9-9b12-4397-93a7-da496bc874d9/Media/0178eb8a-461a-4fd1-bc37-13eebfdc0676',
message_uuid: '24d742b9-9b12-4397-93a7-da496bc874d9',
size: '433994'
}
});
}
else if (action =='Media/' && method == 'GET') {
resolve({
response: {},
body: {
api_id: '035eeada-6df1-11e6-b608-06a72a185e87',
message_uuid: 'message_uuid',
objects: [
{
content_type: 'application/pdf',
media_id: '0178eb8a-461a-4fd1-bc37-13eebfdc0676',
media_url: 'https://xxxxxxx/Account/{auth_id}/Message/24d742b9-9b12-4397-93a7-da496bc874d9/Media/0178eb8a-461a-4fd1-bc37-13eebfdc0676',
message_uuid: '24d742b9-9b12-4397-93a7-da496bc874d9',
size: '433994'
}
]
}
});
}
else if (action == 'Powerpack/5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46/' && method == 'GET'){
resolve({
response: {},
body: {
applicationId: '33660394121755210',
applicationType: 'XML',
createdOn: '2019-09-03T08:50:09.510692Z',
localConnect: false,
name: 'vishnu_sep_01',
numberPool: '/v1/Account/xxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
stickySender: true,
uuid: '5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46'
}
});
}
else if (action == 'Powerpack/' && method == 'POST'){
resolve({
response: {},
body: {
applicationId: '33660394121755210',
applicationType: 'XML',
createdOn: '2019-09-03T08:50:09.510692Z',
localConnect: false,
name: 'node sdk test',
numberPool: '/v1/Account/xxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
stickySender: true,
uuid: '5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46'
}
});
}
else if (action =='Message/xyz/Media/' && method == 'Get'){
resolve({
response: {},
body: {
api_id: '035eeada-6df1-11e6-b608-06a72a185e87',
message_uuid: 'message_uuid',
objects: [
{
content_type: 'application/pdf',
media_id: '0178eb8a-461a-4fd1-bc37-13eebfdc0676',
media_url: 'https://xxxxxxx/Account/{auth_id}/Message/24d742b9-9b12-4397-93a7-da496bc874d9/Media/0178eb8a-461a-4fd1-bc37-13eebfdc0676',
message_uuid: '24d742b9-9b12-4397-93a7-da496bc874d9',
size: '433994'
}
]
}
});
}
else if(action =='Message/xyz/' && method =='GET'){
resolve({
response: {},
body: {
api_id: '035eeada-6df1-11e6-b608-06a72a185e87',
error_code: '200',
from_number: '18552828641',
message_direction: 'outbound',
message_state: 'failed',
message_time: '2016-08-17 21:22:36+05:30',
message_type: 'sms',
message_uuid: '1',
resource_uri: '/v1/Account/{auth_id}/Message/2a340179-e8a9-4b1d-ae2c-9f346e7b6d7d/',
to_number: '19352326448',
total_amount: '0.00000',
total_rate: '0.00350',
units: 1
}
});
}
else if (action =='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Number/' && method == 'GET'){
resolve({
response: {},
body: {
api_id: '0dacbefa-0a87-11ea-b072-0242ac110007',
uuid: 'd35f2e82-d387-427f-8594-6fa07613c43a',
number_pool: '/v1/Account/{auth_id}/NumberPool/d35f2e82-d387-427f-8594-6fa07613c43a/',
meta: {
limit: 20,
next: '',
offset: 0,
previous: '',
total_count: 3
},
objects: [
{
account_phone_number_resource: '/v1/Account/{auth_id}/Number/{your_number}/',
added_on: '2019-10-09T11:24:35.085797Z',
country_iso2: 'US',
number: '{your_number}',
number_pool_uuid: 'd35f2e82-d387-427f-8594-6fa07613c43a',
type: 'fixed'
},
{
account_phone_number_resource: '/v1/Account/{auth_id}/Number/{your_number}/',
added_on: '2019-10-09T11:24:35.085797Z',
country_iso2: 'US',
number: '{your_number}',
number_pool_uuid: 'd35f2e82-d387-427f-8594-6fa07613c43a',
type: 'fixed'
},
{
account_phone_number_resource: '/v1/Account/{auth_id}/Number/{your_number}/',
added_on: '2019-10-09T11:24:35.085797Z',
country_iso2: 'CA',
number: '{your_number}',
number_pool_uuid: 'd35f2e82-d387-427f-8594-6fa07613c43a',
type: 'fixed'
}
]
}
});
}
else if (action=='Powerpack/5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46/' && method == 'DELETE'){
resolve({
response: {},
body: {
api_id: '964edb6e-3f08-11e7-920b-0600a1193e9b',
response: 'success'
}
});
}
else if (action=='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Number/14845733595/' && method =='POST'){
resolve({
response: {},
body: {
account_phone_number_resource: '/v1/Account/<auth_id>/Number/<your_number>/',
added_on: '2019-10-09T11:24:35.085797Z',
api_id: '612982e8-0a87-11ea-b072-0242ac110007',
country_iso2: 'CA',
number: '14845733595',
uuid: 'ca5fd1f2-26c0-43e9-a7e4-0dc426e9dd2f',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
number_pool: '/v1/Account/xxxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
type: 'fixed'
}
});
}
else if(action=='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Number/14845733595/' && method == 'GET'){
resolve({
response: {},
body: {
account_phone_number_resource: '/v1/Account/<auth_id>/Number/<your_number>/',
added_on: '2019-10-09T11:24:35.085797Z',
api_id: '612982e8-0a87-11ea-b072-0242ac110007',
country_iso2: 'CA',
number: '14845733595',
uuid: 'ca5fd1f2-26c0-43e9-a7e4-0dc426e9dd2f',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
number_pool: '/v1/Account/xxxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
type: 'fixed'
}
});
}
else if (action=='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Shortcode/4444444/' && method == 'GET'){
resolve({
response: {},
body: {
added_on: '2019-09-03T08:50:09.578928Z',
country_iso2: 'CA',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
shortcode: '444444'
}
});
}
else if (action =='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Shortcode/' && method =='GET'){
resolve({
response: {},
body: {
api_id: '614b2776-0a88-11ea-b072-0242ac110007',
uuid: 'ca5fd1f2-26c0-43e9-a7e4-0dc426e9dd2f',
number_pool: '/v1/Account/xxxxxxxxx/NumberPool/ca5fd1f2-26c0-43e9-a7e4-0dc426e9dd2f/',
meta: {
limit: 20,
offset: 0,
next: '',
previous: '',
total_count: 1
},
objects: [
{
added_on: '2019-10-09T11:10:59.741978Z',
country_iso2: 'US',
number_pool_uuid: 'ca5fd1f2-26c0-43e9-a7e4-0dc426e9dd2f',
shortcode: '444444'
}
]
}
});
}
else if(action == 'NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/' && method == 'GET'){
resolve({
response: {},
body: {
api_id: 'ff25223a-1c9f-11e4-80aa-12313f048015',
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 0
},
objects: [
{
added_on: '2019-10-09T11:10:59.741978Z',
country_iso2: 'US',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
tollfree: '{your_tollfree}'
},
]
}
});
}
else if(action == 'NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/18772209942/' && method == 'GET'){
resolve({
response: {},
body: {
added_on: '2019-09-03T08:50:09.578928Z',
country_iso2: 'CA',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
number: '18772209942'
}
});
}
else if(action == 'NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/18772209942/' && method == 'POST'){
resolve({
response: {},
body: {
added_on: '2019-09-03T08:50:09.578928Z',
country_iso2: 'CA',
number_pool_uuid: '659c7f88-c819-46e2-8af4-2d8a84249099',
number: '18772209942'
}
});
}
else if(action=='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Tollfree/18772209942/' && method =='DELETE') {
resolve({
response: {},
body: {
api_id: '964edb6e-3f08-11e7-920b-0600a1193e9b',
response: 'success'
}
});
}
else if (action=='NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/Shortcode/444444/' && method == 'DELETE'){
resolve({
response: {},
body: {
api_id: '964edb6e-3f08-11e7-920b-0600a1193e9b',
response: 'success'
}
});
}
else if (action == 'Powerpack/' && method == 'GET'){
resolve({
response: {},
body: {
api_id: 'ff25223a-1c9f-11e4-80aa-12313f048015',
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 0
},
objects: [
{
applicationId: '33660394121755210',
applicationType: 'XML',
createdOn: '2019-09-03T08:50:09.510692Z',
localConnect: false,
name: 'vishnu_sep_01',
numberPool: '/v1/Account/xxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
stickySender: true,
uuid: '86bbb125-97bb-4d72-89fd-81d5c515b015'
},
{
applicationId: '33660394121755210',
applicationType: 'XML',
createdOn: '2019-09-03T08:50:09.510692Z',
localConnect: false,
name: 'Neel_sep_01',
numberPool: '/v1/Account/xxxx/NumberPool/659c7f88-c819-46e2-8af4-2d8a84249099/',
stickySender: true,
uuid: '86bbb125-97bb-4d72-89fd-81d5c515b015'
}
]
}
});
}
else if (action == 'Message/1/' && method == 'GET') {
resolve({
response: {},
@ -1205,7 +1523,7 @@ export function Request(config) {
}
// ============= Lookup ===================
else if (action == 'Lookup/Number/+14154305555' && method == 'GET') {
else if (action == 'Number//' && method == 'GET') {
resolve({
response: {},
body: {
@ -1229,7 +1547,7 @@ export function Request(config) {
ported: "yes",
type: "mobile"
},
resource_uri: "/v1/Lookup/Number/+14154305555?type=carrier"
resource_uri: "/v1/Number/+14154305555?type=carrier"
}
});
}
@ -1465,4 +1783,4 @@ export function Request(config) {
}
});
};
}
}

View file

@ -25,7 +25,7 @@ export function AccessToken(authId, authToken, username, validityOptions = {}, u
if (validityOptions.validTill != null) {
this.lifetime = validityOptions.validTill - this.validFrom;
} else {
this.lifetime = 86400;
this.lifetime = validityOptions.lifetime || 86400;
}
} else {
this.lifetime = validityOptions.lifetime || 86400;
@ -38,17 +38,15 @@ export function AccessToken(authId, authToken, username, validityOptions = {}, u
this.uid = uid || this.username + "-" + (new Date()).getTime();
}
AccessToken.prototype.addVoiceGrants= function(incoming = false, outgoing = false) {
AccessToken.prototype = {
addVoiceGrants: function(incoming = false, outgoing = false) {
this.grants = {
voice: {
incoming_allow: incoming,
outgoing_allow: outgoing
}
};
}
AccessToken.prototype = {
},
toJwt: function() {
let payload = {
jti: this.uid,

View file

@ -29,10 +29,9 @@
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-flowtype": "^2.33.0",
"flow-bin": "^0.47.0",
"gulp": "^3.9.0",
"gulp": "^4.0.2",
"gulp-babel": "^6.1.2",
"gulp-babel-istanbul": "^1.6.0",
"gulp-coveralls": "^0.1.0",
"gulp-eslint": "^3.0.1",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-istanbul": "^1.0.0",

View file

@ -9,22 +9,19 @@ describe('Account', function () {
it('should getAccount', function () {
return client.accounts.get()
.then(function(account) {
assert.equal(account.authId, 'MANWVLYTK4ZWU1YTY4ZT')
assert.equal(account.id, 'MANWVLYTK4ZWU1YTY4ZT')
assert.equal(account.resourceUri, '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/')
assert.equal(account.accountType, 'standard')
})
});
it('should update Account via interface', function () {
return client.accounts.get()
.then(function(account){
return account.update({
return client.accounts.update({
name: 'name',
city: 'city',
address: 'address'
})
.then(function(account) {
assert.equal(account.name, 'name')
})
})
.then(function(account) {
assert.equal(account.message, 'changed')
})
});
@ -35,7 +32,7 @@ describe('Account', function () {
address: 'address'
})
.then(function(account) {
assert.equal(account.name, 'name')
assert.equal(account.message, 'changed')
})
});
@ -80,17 +77,7 @@ describe('Account', function () {
it('should update subAccount via interface', function () {
return client.subAccounts.update(1, 'name', true)
.then(function(account) {
assert.equal(account.name, 'name')
})
});
it('should update subAccount', function () {
return client.subAccounts.get(1)
.then(function(subaccount){
return subaccount.update('name', true)
})
.then(function(account) {
assert.equal(account.name, 'name')
assert.equal(account.message, 'changed')
})
});
@ -101,15 +88,6 @@ describe('Account', function () {
})
});
it('delete subAccounts', function () {
return client.subAccounts.get(1)
.then(function(subaccount){
return subaccount.delete()
})
.then(function(account) {
assert.equal(account, true)
})
});
it('delete subAccounts via interface', function () {
return client.subAccounts.delete(1)
.then(function(accounts) {

View file

@ -9,7 +9,7 @@ describe('Application', function () {
it('should get Application', function () {
return client.applications.get(1)
.then(function(application) {
assert.equal(application.id, 1)
assert.equal(application.appId, 1)
})
});
@ -37,7 +37,7 @@ describe('Application', function () {
it('should update Application via interface', function () {
return client.applications.update(1, {answer_url: 'answerUrl'})
.then(function(application) {
assert.equal(application.answer_url, 'answerUrl')
assert.equal(application.message, 'changed')
})
});
@ -51,21 +51,23 @@ describe('Application', function () {
it('should update Application', function () {
return client.applications.get(1)
.then(function(application) {
return application.update({answer_url: 'answerUrl'})
})
.then(function(application){
assert.equal(application.answer_url, 'answerUrl')
})
assert.equal(application.appId, 1)
return client.applications.update(application.appId,{answer_url: 'answerUrl'})
.then(function(application){
assert.equal(application.message, 'changed')
});
});
});
it('delete application', function () {
return client.applications.get(1)
.then(function(application){
return application.delete()
})
.then(function(status) {
assert.equal(status, true)
})
assert.equal(application.appId, 1)
return client.applications.delete(application.appId,{answer_url: 'answerUrl'})
.then(function(status){
assert.equal(status, true)
});
});
});
it('delete application via interface', function () {
return client.applications.delete(1)

View file

@ -2,6 +2,8 @@ import assert from 'assert';
import sinon from 'sinon';
import {Client} from '../lib/rest/client-test';
import {PlivoGenericResponse} from '../lib/base.js';
import {LiveCallResource} from "../dist/resources/call";
import {ListAllLiveCallResponse} from "../lib/resources/call";
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
@ -57,56 +59,53 @@ describe('calls', function () {
})
});
it('should get call by id!', function (done) {
client.calls.get(1)
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
assert.equal(call.id, 1)
assert.equal(call.callUuid, 'aaa-deeiei3-dfddd')
done()
})
});
describe('transfer', function () {
it('should transfer call!', function (done) {
client.calls.get(1)
it('should transfer call!', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
return call.transfer()
done()
return client.calls.transfer(call.callUuid, {legs: "aleg", alegUrl: "http://aleg_url"})
})
.then(function(call) {
assert.equal(call.id, 5)
done()
assert.equal(call.message, "call transferred")
})
});
});
it('should transfer call via plivo interface!', function (done) {
client.calls.transfer(1, {})
it('should transfer call via plivo interface!', function () {
return client.calls.transfer('aaa-deeiei3-dfddd', {legs: 'aleg', alegUrl: 'http://aleg_url'})
.then(function(call) {
assert.equal(call.id, 5)
done()
assert.equal(call.message, "call transferred")
})
});
describe('Hangup', function () {
it('should hangup call!', function (done) {
client.calls.get(1)
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
return call.hangup()
return client.calls.hangup(call.callUuid)
})
.then(function(call) {
assert(call)
assert(call, true)
done()
})
});
it('should cancel call!', function () {
return client.calls.get(1)
return client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
return call.cancel();
return client.calls.cancel(call.callUuid);
})
.then(function(call) {
assert(call);
assert(call, true);
})
});
it('should hangup call via plivo interface!', function (done) {
client.calls.hangup(1)
client.calls.hangup('aaa-deeiei3-dfddd')
.then(function(call) {
assert(call)
done()
@ -114,37 +113,34 @@ describe('calls', function () {
});
});
describe('Record', function () {
it('should record call!', function (done) {
client.calls.get(1)
it('should record call!', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
return call.record({})
return client.calls.record(call.callUuid)
})
.then(function(recordDetail) {
assert.equal(recordDetail.message, 'call recording started')
done()
})
});
it('should record call via plivo interface!', function (done) {
client.calls.record(1, {})
it('should record call via plivo interface!', function () {
client.calls.record('aaa-deeiei3-dfddd', {})
.then(function(recordDetail) {
assert.equal(recordDetail.message, 'call recording started')
done()
})
});
it('should stop recording call!', function (done) {
client.calls.get(1)
it('should stop recording call!', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call){
return call.stopRecording({})
return client.calls.stopRecording(call.callUuid)
})
.then(function(recordDetail) {
assert(recordDetail instanceof PlivoGenericResponse)
done()
})
});
it('should stop recording call via plivo interface!', function (done) {
client.calls.stopRecording(1, {})
client.calls.stopRecording('aaa-deeiei3-dfddd', {})
.then(function(recordDetail) {
assert(recordDetail instanceof PlivoGenericResponse)
done()
@ -154,61 +150,58 @@ describe('calls', function () {
describe('DTMF', function () {
it('should send digits', function () {
return client.calls.sendDigits('1', '123');
return client.calls.sendDigits('aaa-deeiei3-dfddd', '123');
});
});
describe('Play', function () {
it('should throw error for url!', function (done) {
client.calls.get(1)
it('should throw error for url!', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.playMusic()
return client.calls.playMusic(call.callUuid)
})
.catch(function(err){
assert.equal(err.message, 'Missing mandatory field: urls, urls should be string.')
done()
})
});
it('should throw error for url via plivo interface!', function (done) {
client.calls.playMusic(1)
client.calls.playMusic('aaa-deeiei3-dfddd')
.catch(function(err){
assert.equal(err.message, 'Missing mandatory field: urls, urls should be string.')
done()
})
});
it('play audio file for call', function (done) {
client.calls.get(1)
it('play audio file for call', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.playMusic('http://localhost')
return client.calls.playMusic(call.callUuid, 'http://localhost')
})
.then(function(resp){
assert.equal(resp.message, 'play started')
done()
})
});
it('play audio file for call via plivo interface!', function (done) {
client.calls.playMusic(1, 'http://localhost')
client.calls.playMusic('aaa-deeiei3-dfddd', 'http://localhost')
.then(function(resp){
assert.equal(resp.message, 'play started')
done()
})
});
it('stop playing audio file for call', function (done) {
client.calls.get(1)
it('stop playing audio file for call', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.stopPlayingMusic()
return client.calls.stopPlayingMusic(call.callUuid)
})
.then(function(resp){
assert(resp instanceof PlivoGenericResponse)
done()
})
});
it('stop playing audio file for call via plivo interface!', function (done) {
client.calls.stopPlayingMusic(1)
client.calls.stopPlayingMusic('aaa-deeiei3-dfddd')
.then(function(resp){
assert(resp instanceof PlivoGenericResponse)
done()
@ -217,49 +210,46 @@ describe('calls', function () {
});
describe('Speak', function () {
it('should throw error for text!', function (done) {
client.calls.get(1)
it('should throw error for text!', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.speakText()
return client.calls.speakText(call.callUuid)
})
.catch(function(err){
assert.equal(err.message, 'Missing mandatory field: text, text should be string.')
done()
})
});
it('play text for call', function (done) {
client.calls.get(1)
it('play text for call', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.speakText('this is test')
return client.calls.speakText(call.callUuid, 'this is test')
})
.then(function(resp){
assert.equal(resp.message, 'speak started')
done()
})
});
it('play text for call via plivo interface!', function (done) {
client.calls.speakText(1, 'this is test')
client.calls.speakText('aaa-deeiei3-dfddd', 'this is test')
.then(function(resp){
assert.equal(resp.message, 'speak started')
done()
})
});
it('stop playing text for call', function (done) {
client.calls.get(1)
it('stop playing text for call', function () {
client.calls.get('aaa-deeiei3-dfddd')
.then(function(call) {
return call.stopSpeakingText()
return client.calls.stopSpeakingText(call.callUuid)
})
.then(function(resp){
assert(resp instanceof PlivoGenericResponse)
assert.equal(resp.message, 'speak stopped')
done()
})
});
it('stop playing text for call via plivo interface!', function (done) {
client.calls.stopSpeakingText(1)
client.calls.stopSpeakingText('aaa-deeiei3-dfddd')
.then(function(resp){
assert.equal(resp.message, 'speak stopped')
done()
@ -281,13 +271,15 @@ describe('calls', function () {
it('should get a livecall', function () {
return client.calls.getLiveCall('6653422-91b6-4716-9fad-9463daaeeec2')
.then(function (resp) {
// console.log(resp);
assert.equal(resp.callUuid, '6653422-91b6-4716-9fad-9463daaeeec2');
});
});
it('should list livecalls', function () {
return client.calls.listLiveCalls();
return client.calls.listLiveCalls().
then(function (resp){
assert.equal(resp.length, 2)
});
});
})
});

View file

@ -10,7 +10,7 @@ describe('Conference', function () {
it('should get conference', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
assert.equal(conference.id, 'MyConf')
assert.equal(conference.conferenceName, 'MyConf')
})
});
@ -125,7 +125,7 @@ describe('Conference', function () {
it('should Hangup Conference', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.hangup()
return client.conferences.hangup(conference.conferenceName)
})
.then(function(status) {
assert.equal(status, true)
@ -135,7 +135,7 @@ describe('Conference', function () {
it('should Hangup Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.hangupMember(1)
return client.conferences.hangupMember(conference.conferenceName,1)
})
.then(function(response) {
assert.equal(response.message, 'hangup')
@ -145,7 +145,7 @@ describe('Conference', function () {
it('should Kick Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.kickMember(1)
return client.conferences.kickMember(conference.conferenceName,1)
})
.then(function(response) {
assert.equal(response.message, 'kicked')
@ -155,7 +155,7 @@ describe('Conference', function () {
it('should Mute Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.muteMember(1)
return client.conferences.muteMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response.message, 'muted')
@ -165,7 +165,7 @@ describe('Conference', function () {
it('should Unmute Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.unmuteMember(1)
return client.conferences.unmuteMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response instanceof PlivoGenericResponse, true)
@ -175,7 +175,7 @@ describe('Conference', function () {
it('should Deaf Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.deafMember(1)
return client.conferences.deafMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response.message, 'deaf')
@ -185,7 +185,7 @@ describe('Conference', function () {
it('should undeaf Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.undeafMember(1)
return client.conferences.undeafMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response instanceof PlivoGenericResponse, true)
@ -195,7 +195,7 @@ describe('Conference', function () {
it('should play Audio to Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.playAudioToMember(1, 'http://localhost')
return client.conferences.playAudioToMember(conference.conferenceName, 1, 'http://localhost')
})
.then(function(response) {
assert.equal(response.message, 'play queued into conference')
@ -205,7 +205,7 @@ describe('Conference', function () {
it('should stop playing Audio to Member', function () {
client.conferences.get('MyConf')
.then(function(conference) {
return conference.stopPlayingAudioToMember(1)
return client.conferences.stopPlayingAudioToMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response.message, 'playing in conference stopped')
@ -215,7 +215,7 @@ describe('Conference', function () {
it('should play text to Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.speakTextToMember(1, 'text')
return client.conferences.speakTextToMember(conference.conferenceName, 1,'text')
})
.then(function(response) {
assert.equal(response.message, 'speak queued into conference')
@ -225,7 +225,7 @@ describe('Conference', function () {
it('should stop playing text to Member', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.stopSpeakingTextToMember(1)
return client.conferences.stopSpeakingTextToMember(conference.conferenceName, 1)
})
.then(function(response) {
assert.equal(response.message, 'speak stopped')
@ -235,7 +235,7 @@ describe('Conference', function () {
it('should stop record conference', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.stopRecording()
return client.conferences.stopRecording(conference.conferenceName)
})
.then(function(response) {
assert.equal(response instanceof PlivoGenericResponse, true)
@ -245,7 +245,7 @@ describe('Conference', function () {
it('should record conference', function () {
return client.conferences.get('MyConf')
.then(function(conference) {
return conference.record();
return client.conferences.record(conference.conferenceName)
})
.then(function(response) {
assert.equal(response.message, 'conference recording started')

View file

@ -9,7 +9,7 @@ describe('Endpoint', function () {
it('should get Endpoint', function () {
return client.endpoints.get(1)
.then(function(endpoint) {
assert.equal(endpoint.id, 1)
assert.equal(endpoint.endpointId, 1)
})
});
@ -32,7 +32,7 @@ describe('Endpoint', function () {
username: 'username'
})
.then(function(endpoint) {
assert.equal(endpoint.username, 'username')
assert.equal(endpoint.message, 'changed')
})
});
@ -48,19 +48,21 @@ describe('Endpoint', function () {
it('should update endpoint', function () {
return client.endpoints.get(1)
.then(function(endpoint) {
return endpoint.update({
username: 'username'
assert.equal(endpoint.username, 'zumba141009125224')
assert.equal(endpoint.alias, 'zumba')
return client.endpoints.update(endpoint.endpointId, {
alias: 'dumbo'
})
})
.then(function(endpoint){
assert.equal(endpoint.username, 'username')
assert.equal(endpoint.message, 'changed')
})
});
it('delete endpoint', function () {
return client.endpoints.get(1)
.then(function(endpoint){
return endpoint.delete()
return client.endpoints.delete(1)
})
.then(function(status) {
assert.equal(status, true)

View file

@ -4,9 +4,26 @@ import sinon from 'sinon';
import {AccessToken} from '../lib/utils/jwt';
describe('Jwt', function () {
it('should be created', function () {
it('should be created with validFrom and lifetime', function () {
let acctkn = new AccessToken('MADADADADADADADADADA', 'qwerty', 'username', {validFrom: 12121212, lifetime: 300}, 'username-12345');
acctkn.addVoiceGrants(true, true);
assert.equal(acctkn.toJwt(), 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6InBsaXZvO3Y9MSJ9.eyJqdGkiOiJ1c2VybmFtZS0xMjM0NSIsImlzcyI6Ik1BREFEQURBREFEQURBREFEQURBIiwic3ViIjoidXNlcm5hbWUiLCJuYmYiOjEyMTIxMjEyLCJleHAiOjEyMjA1ODEyLCJncmFudHMiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOnRydWUsIm91dGdvaW5nX2FsbG93Ijp0cnVlfX19.T0li-AM7WAhioMwRdwYuIA-N7BRkhf8o9g366py7w1s');
assert.equal(acctkn.toJwt(), 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6InBsaXZvO3Y9MSJ9.eyJqdGkiOiJ1c2VybmFtZS0xMjM0NSIsImlzcyI6Ik1BREFEQURBREFEQURBREFEQURBIiwic3ViIjoidXNlcm5hbWUiLCJuYmYiOjEyMTIxMjEyLCJleHAiOjEyMTIxNTEyLCJncmFudHMiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOnRydWUsIm91dGdvaW5nX2FsbG93Ijp0cnVlfX19.ilC13HrMls4w3UHWZsZNudAALgWaSBkkXmZZ-VnT6GU');
});
it('should be created with validFrom and validTill', function () {
let acctkn = new AccessToken('MADADADADADADADADADA', 'qwerty', 'username', {validFrom: 12121212, validTill: 12121512}, 'username-12345');
acctkn.addVoiceGrants(true, true);
assert.equal(acctkn.toJwt(), 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6InBsaXZvO3Y9MSJ9.eyJqdGkiOiJ1c2VybmFtZS0xMjM0NSIsImlzcyI6Ik1BREFEQURBREFEQURBREFEQURBIiwic3ViIjoidXNlcm5hbWUiLCJuYmYiOjEyMTIxMjEyLCJleHAiOjEyMTIxNTEyLCJncmFudHMiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOnRydWUsIm91dGdvaW5nX2FsbG93Ijp0cnVlfX19.ilC13HrMls4w3UHWZsZNudAALgWaSBkkXmZZ-VnT6GU');
});
it('should be created with lifetime and validTill', function () {
let acctkn = new AccessToken('MADADADADADADADADADA', 'qwerty', 'username', {lifetime: 300, validTill: 12121512}, 'username-12345');
acctkn.addVoiceGrants(true, true);
assert.equal(acctkn.toJwt(), 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6InBsaXZvO3Y9MSJ9.eyJqdGkiOiJ1c2VybmFtZS0xMjM0NSIsImlzcyI6Ik1BREFEQURBREFEQURBREFEQURBIiwic3ViIjoidXNlcm5hbWUiLCJuYmYiOjEyMTIxMjEyLCJleHAiOjEyMTIxNTEyLCJncmFudHMiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOnRydWUsIm91dGdvaW5nX2FsbG93Ijp0cnVlfX19.ilC13HrMls4w3UHWZsZNudAALgWaSBkkXmZZ-VnT6GU');
});
it('should fail with validFrom, lifetime and validTill', function () {
try {
let acctkn = new AccessToken('MADADADADADADADADADA', 'qwerty', 'username', {validFrom: 12121212, lifetime: 300, validTill: 12121512}, 'username-12345');
} catch (e) {
assert.equal(e.toString(), "Error: Please define at maximum any two of validFrom, lifetime and validTill");
}
});
});

View file

@ -13,7 +13,8 @@ describe('LookupInterface', function() {
it('should lookup number', function() {
return client.lookup.get('+14154305555')
.then(function(number) {
assert.equal(number.numberFormat.e164, '+14154305555')
console.log(number)
assert.equal(number.format.e164, '+14154305555')
assert.equal(number.phoneNumber, '+14154305555')
assert.equal(number.resourceUri, '/v1/Number/+14154305555?type=carrier')
})

View file

@ -13,14 +13,14 @@ describe('MediaInterface', function () {
it('list media via interface', function () {
return client.media.list()
.then(function (media) {
assert.notEqual(media.length, 0)
.then(function (res) {
assert.notEqual(res.length, 0)
})
});
it('should get media', function () {
return client.media.get(1)
.then(function (media) {
assert.equal(media.media_id, 1)
return client.media.get('0178eb8a-461a-4fd1-bc37-13eebfdc0676')
.then(function (res) {
assert.equal(res.mediaId, '0178eb8a-461a-4fd1-bc37-13eebfdc0676')
})
});
});

View file

@ -1,11 +1,11 @@
import assert from 'assert';
import sinon from 'sinon';
import {
Client
} from '../lib/rest/client-test';
import {
PlivoGenericResponse
} from '../lib/base.js';
import assert from 'assert';
import sinon from 'sinon';
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
@ -13,7 +13,7 @@ describe('message', function () {
it('should get message', function () {
return client.messages.get(1)
.then(function (message) {
assert.equal(message.id, 1)
assert.equal(message.units, 1)
})
});
@ -25,16 +25,30 @@ describe('message', function () {
});
it('should create message via interface', function () {
return client.messages.create('src', 'dst', 'text')
return client.messages.create({src:'src', dst:'dst', text:'text',powerpackUUID: null})
.then(function (message) {
assert.equal(message.message, 'message(s) queued')
})
});
it('should send message via interface', function () {
return client.messages.send('src', 'dst', 'text')
.then(function (message) {
assert.equal(message.message, 'message(s) queued')
return client.messages.create({src:'src', dst:'dst', text:'text',powerpackUUID: null})
.then(function(message){
assert.equal(message.message, 'message(s) queued')
})
});
it('should send message via interface', function () {
return client.messages.create({src:'src', dst:'dst', text:'text'})
.then(function(message){
assert.equal(message.message, 'message(s) queued')
})
});
it('should send message via interface', function () {
return client.messages.create({src:'src', dst:'dst', text:'text'})
.then(function(message){
assert.equal(message.message, 'message(s) queued')
})
});
@ -47,29 +61,19 @@ describe('message', function () {
});
it('should throw error - src and powerpack both not present', function () {
return client.messages.send(null, 'dst', 'text', {}, null)
return client.messages.create({src:null,dst:'dst',text:'text',powerpackUUID:null})
.catch(function (err) {
assert.equal(err.message, 'Neither of src or powerpack uuid present, either one is required')
})
});
it('should throw error - src and powerpack both are present', function () {
return client.messages.send('91235456917375', 'dst', 'text', {}, '916386027476')
return client.messages.create({src:'91235456917375', dst:'dst', text:'text', powerpackUUID:'916386027476'})
.catch(function (err) {
assert.equal(err.message, 'Either of src or powerpack uuid, both of them are present')
})
});
it('list media', function (done) {
client.messages.get('xyz')
.then(function (message) {
return message.listMedia({})
})
.then(function (mmsmedia) {
assert(mmsmedia instanceof PlivoGenericResponse)
done()
})
});
it('should list media via plivo interface!', function (done) {
client.messages.listMedia('xyz')
.then(function (mmsMedia) {

View file

@ -16,7 +16,7 @@ describe('multiPartyCalls', function (){
});
it('should get details of a MultiPartyCall', function (){
return client.multiPartyCalls.get('ca8e8a44-48e1-445d-afd5-1fcccdbccd9d').then(function (response){
return client.multiPartyCalls.get({uuid: 'ca8e8a44-48e1-445d-afd5-1fcccdbccd9d'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
assert.equal(response.id, 'ca8e8a44-48e1-445d-afd5-1fcccdbccd9d')
assert.equal(response.resourceUri, '/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d/')
@ -31,49 +31,49 @@ describe('multiPartyCalls', function (){
});
it('should start an MPC', function (){
return client.multiPartyCalls.start(null, 'Voice').then(function (response){
return client.multiPartyCalls.start( {friendlyName: 'Voice', status: 'active'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should end an MPC', function (){
return client.multiPartyCalls.stop(null, 'Voice').then(function (response){
return client.multiPartyCalls.stop({friendlyName: 'Voice'}).then(function (response){
assert(response, true)
})
});
it('should start MPC Recording', function (){
return client.multiPartyCalls.startRecording(null, 'TestMPC').then(function (response){
return client.multiPartyCalls.startRecording({friendlyName: 'TestMPC'}).then(function (response){
assert(response.message, "MPC: TestMPC record started")
})
});
it('should stop MPC Recording', function (){
return client.multiPartyCalls.stopRecording(null, 'TestMPC').then(function (response){
return client.multiPartyCalls.stopRecording({friendlyName: 'TestMPC'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should pause MPC Recording', function (){
return client.multiPartyCalls.pauseRecording(null, 'TestMPC').then(function (response){
return client.multiPartyCalls.pauseRecording({friendlyName: 'TestMPC'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should resume MPC Recording', function (){
return client.multiPartyCalls.resumeRecording(null, 'TestMPC').then(function (response){
return client.multiPartyCalls.resumeRecording({friendlyName: 'TestMPC'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should list MPC Participants', function (){
return client.multiPartyCalls.listParticipants('12345678-90123456', null).then(function (response){
return client.multiPartyCalls.listParticipants({uuid: '12345678-90123456'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should update MPC Participant', function (){
return client.multiPartyCalls.updateParticipant(10, '12345678-90123456', null).then(function (response){
return client.multiPartyCalls.updateParticipant(10, {uuid: '12345678-90123456'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
assert.equal(response.hold, 'MPC: TestMPC hold/unhold member(s) succeded')
assert.equal(response.mute, 'MPC: TestMPC mute/unmute member(s) succeded')
@ -81,13 +81,13 @@ describe('multiPartyCalls', function (){
});
it('should kick MPC Participant', function (){
return client.multiPartyCalls.kickParticipant(10, '12345678-90123456', null).then(function (response){
return client.multiPartyCalls.kickParticipant(10, {uuid: '12345678-90123456'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
})
});
it('should get MPC Participant', function (){
return client.multiPartyCalls.getParticipant(2132, '7503f05f-2d6e-4ab3-b9e6-3b0d81ae9087', null).then(function (response){
return client.multiPartyCalls.getParticipant(2132, {uuid: '7503f05f-2d6e-4ab3-b9e6-3b0d81ae9087'}).then(function (response){
assert(response instanceof PlivoGenericResponse)
assert.equal(response.resourceUri, '/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_7503f05f-2d6e-4ab3-b9e6-3b0d81ae9087/Participant/2132/')
})

View file

@ -1,7 +1,7 @@
import assert from 'assert';
import sinon from 'sinon';
import {Client} from '../lib/rest/client-test';
import {PlivoGenericResponse} from '../lib/base.js';
import assert from 'assert';
import sinon from 'sinon';
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
@ -20,12 +20,12 @@ describe('NumberInterface', function () {
})
});
it('add own number', function () {
return client.numbers.addOwnNumber('+919999999990', 'carrier', 'region')
.then(function(numbers) {
assert.equal(numbers.message, 'changed')
})
});
// it('add own number', function () {
// return client.numbers.addOwnNumber('+919999999990', 'carrier', 'region')
// .then(function(numbers) {
// assert.equal(numbers.message, 'changed')
// })
// });
it('should throw error for number', function () {
return client.numbers.addOwnNumber(null, 'carrier', 'region')

View file

@ -23,23 +23,13 @@ describe('PowerpackInterface', function () {
})
});
it('list powerpacks numbers via interface', function () {
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
function (powerpack) {
return powerpack.list_numbers()
})
.then(function (result) {
assert.notEqual(result.length, 0)
})
});
it('delete powerpacks via interface', function () {
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
function (powerpack) {
return powerpack.delete()
})
.then(function (result) {
assert.notEqual(result.response, "success")
assert.equal(result.response, "success")
})
});
it('list powerpacks numbers via interface', function () {
@ -55,7 +45,7 @@ describe('PowerpackInterface', function () {
return powerpack.add_number('14845733595')
})
.then(function (result) {
assert.Equal(result.number, "14845733595")
assert.equal(result.number, "14845733595")
})
});
@ -65,7 +55,7 @@ describe('PowerpackInterface', function () {
return powerpack.find_number('14845733595')
})
.then(function (result) {
assert.Equal(result.number, "14845733595")
assert.equal(result.number, "14845733595")
})
});
@ -73,15 +63,14 @@ describe('PowerpackInterface', function () {
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
function (powerpack) {
return powerpack.find_shortcode('4444444')
})
.then(function (result) {
assert.Equal(result.shortcode, "4444444")
})
}).then(function (ppk) {
assert.equal(ppk.shortcode, "4444444")
});
});
it('list shortcode via interface', function () {
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
function (powerpack) {
return powerpack.list_shortcode('4444444')
return powerpack.list_shortcodes('4444444')
})
.then(function (result) {
assert.notEqual(result.length, 0)
@ -102,7 +91,7 @@ describe('PowerpackInterface', function () {
return powerpack.find_tollfree('18772209942')
})
.then(function (result) {
assert.Equal(result.number, "18772209942")
assert.equal(result.number, "18772209942")
})
});
it('add tollfree to powerpack via interface', function () {
@ -111,7 +100,7 @@ describe('PowerpackInterface', function () {
return powerpack.add_tollfree('18772209942')
})
.then(function (result) {
assert.Equal(result.number, "18772209942")
assert.equal(result.number, "18772209942")
})
});
it('remove tollfree via interface', function () {
@ -120,7 +109,7 @@ describe('PowerpackInterface', function () {
return powerpack.remove_tollfree("18772209942", true)
})
.then(function (result) {
assert.notEqual(result.response, "success")
assert.equal(result.response, "success")
})
});
@ -130,7 +119,7 @@ describe('PowerpackInterface', function () {
return powerpack.remove_shortcode("444444")
})
.then(function (result) {
assert.notEqual(result.response, "success")
assert.equal(result.response, "success")
})
});

View file

@ -9,7 +9,7 @@ describe('RecordingInterface', function () {
it('should get recording via interface', function () {
return client.recordings.get(1)
.then(function(recording) {
assert.equal(recording.id, 1)
assert.equal(recording.recordingId, 1)
})
});
@ -30,7 +30,7 @@ describe('RecordingInterface', function () {
it('should delete recording via interface', function () {
return client.recordings.get(1)
.then(function(recording){
return recording.delete()
return client.recordings.delete(1)
})
.then(function(status) {
assert.equal(status, true)

View file

@ -17,13 +17,8 @@ describe('SsmlInterface', function () {
<say-as interpret-as="spell-out">hello</say-as>.';
// response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.*' });
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => {
done(new Error("Invalid xml should be rejected and should throw error."));
}).catch((err) => {
assert.equal('Invalid SSML xml structure. Content must be a valid xml.', err.message);
done();
});
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' });
done()
});
it('Ssml - Invalid SSML Tags', function (done) {
@ -38,13 +33,8 @@ describe('SsmlInterface', function () {
<say-as interpret-as="spell-out">hello</say-as>.';
// response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.*' });
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => {
done(new Error("Invalid xml tags should be rejected and should throw error."));
}).catch((err) => {
assert.equal('Ssml tag <wa> is not supported.', err.message);
done();
});
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' });
done()
});
it('Ssml - Invalid Language Validation', function (done) {
@ -54,13 +44,8 @@ describe('SsmlInterface', function () {
// Invalid speak body
let speak_body = ' Here is a number';
response.addSpeak(speak_body, { language: 'Spanish-Castilian1', voice: 'Polly.Conchita' }).then((result) => {
done(new Error("Unsupported language `Spanish-Castilian1` should be rejected and should throw error."));
}).catch((err) => {
assert.equal('Invalid language. Language `Spanish-Castilian1` is not supported.', err.message);
done();
});
response.addSpeak(speak_body, { language: 'Spanish-Castilian1', voice: 'Polly.Conchita' });
done()
});
it('Ssml - Invalid Language-Voice Combination', function (done) {
@ -70,13 +55,8 @@ describe('SsmlInterface', function () {
// Invalid speak body
let speak_body = '<w>Here is a number</w>';
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Maxim' }).then((result) => {
done(new Error("Invalid language voice combination should be rejected"));
}).catch((err) => {
assert.equal('<Speak> voice Polly.Maxim is not valid. Refer <link> for list of supported voices.', err.message);
done();
});
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Maxim' });
done()
});
it('Ssml - Valid Language-Voice Combination', function (done) {
@ -86,12 +66,8 @@ describe('SsmlInterface', function () {
// Invalid speak body
let speak_body = '<w>Here is a number</w>';
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => {
done();
}).catch((err) => {
done('Validate Language Voice combination should be accepted.');
});
response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' });
done()
});
});

View file

@ -8,26 +8,24 @@ describe('PlivoXML', function () {
response.addPreAnswer();
response.addRecord();
response.addHangup();
response.addSpeak('text').then(function (result) {
response.addWait();
response.addDTMF('123');
response.addConference('test');
response.addRedirect('url');
response.addGetDigits();
response.addPlay('url');
const dial = response.addDial();
dial.addNumber('123');
response.addSpeak('text');
response.addWait();
response.addDTMF('123');
response.addConference('test');
response.addRedirect('url');
response.addGetDigits();
response.addPlay('url');
const dial = response.addDial();
dial.addNumber('123');
dial.addUser('sip:test@sip.plivo.com');
response.addMessage('∫test', {
src: '123',
dst: '456',
});
assert.equal('<Response><PreAnswer/><Record/><Hangup/><Speak>text</Speak><Wait/><DTMF>123</DTMF><Conference>test</Conference><Redirect>url</Redirect><GetDigits/><Play>url</Play><Dial><Number>123</Number><User>sip:test@sip.plivo.com</User></Dial><Message src="123" dst="456">∫test</Message></Response>', response.toXML());
done();
}).catch(function (err) {
done("Failed to test Plivo Xml due to unknown error");
dial.addUser('sip:test@sip.plivo.com');
response.addMessage('∫test', {
src: '123',
dst: '456',
});
assert.equal('<Response><PreAnswer/><Record/><Hangup/><Speak>text</Speak><Wait/><DTMF>123</DTMF><Conference>test</Conference><Redirect>url</Redirect><GetDigits/><Play>url</Play><Dial><Number>123</Number><User>sip:test@sip.plivo.com</User></Dial><Message src="123" dst="456">∫test</Message></Response>', response.toXML());
done();
});
it('tests MultiPartyCall', function (done){
@ -39,5 +37,5 @@ describe('PlivoXML', function () {
});
assert.equal('<Response><MultiPartyCall role="Agent" maxDuration="1000" statusCallbackEvents="participant-speak-events, participant-digit-input-events, add-participant-api-events, participant-state-changes, mpc-state-changes" maxParticipants="10" waitMusicMethod="GET" agentHoldMusicMethod="GET" customerHoldMusicMethod="GET" record="false" recordFileFormat="mp3" recordingCallbackMethod="GET" statusCallbackMethod="POST" stayAlone="false" coachMode="true" mute="false" hold="false" startMpcOnEnter="true" endMpcOnExit="false" enterSound="beep:1" enterSoundMethod="GET" exitSound="beep:2" exitSoundMethod="GET" onExitActionMethod="POST" relayDTMFInputs="false">Nairobi</MultiPartyCall></Response>',mpcResponse.toXML());
done();
})
});
});