diff --git a/gulpfile.js b/gulpfile.js index 371cdcb5..f272484d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -43,6 +43,8 @@ gulp.task('pre-test', function () { gulp.task('test', ['pre-test'], function (cb) { var mochaErr; + console.log('Running tests with node version', process.version); + gulp.src('test/**/*.js') .pipe(plumber()) .pipe(mocha({ reporter: 'spec' })) @@ -62,6 +64,7 @@ gulp.task('watch', function () { gulp.task('coveralls', ['test'], function () { if (!process.env.CI) { + console.log('ignoring coveralls report generation.'); return; } diff --git a/lib/base.js b/lib/base.js index aa7701bf..6471b67f 100644 --- a/lib/base.js +++ b/lib/base.js @@ -25,14 +25,14 @@ export class PlivoResource { this[clientKey] = request; } - update(params, id) { + update(params, id, requestConfig) { let client = this[clientKey]; let action = this[actionKey]; let that = this; id = typeof id !== 'undefined' ? id : that.id; return new Promise((resolve, reject) => { - client('POST', action + id + '/', params) + client('POST', action + id + '/', params, requestConfig) .then(response => { extend(that, response.body); extend(that, params); @@ -125,13 +125,13 @@ export class PlivoResourceInterface { }); } - create(params) { + create(params, requestConfig) { let client = this[clientKey]; let idField = this[idKey]; let action = this[actionKey] + (this.id ? this.id + '/' : ''); return new Promise((resolve, reject) => { - client('POST', action, params) + client('POST', action, params, requestConfig) .then(response => { resolve(new PlivoGenericResponse(response.body, idField)); }) diff --git a/lib/resources/addresses.js b/lib/resources/addresses.js new file mode 100644 index 00000000..c99d0d10 --- /dev/null +++ b/lib/resources/addresses.js @@ -0,0 +1,92 @@ +import { extend, validate } from '../utils/common.js'; +import { PlivoResource, PlivoResourceInterface } from '../base'; + +const clientKey = Symbol(); +const action = 'Verification/Address/'; +const idField = 'id'; + +/* ---------------Address method----------*/ +export class Address extends PlivoResource { + constructor(client, data = {}) { + super(action, Address, idField, client); + this[clientKey] = client; + if (idField in data) { + this.id = data[idField]; + } + + extend(this, data); + } +} + +export class AddressInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, Address, idField, client); + extend(this, data); + this[clientKey] = client; + } + + get(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + if (errors) { + return errors; + } + return super.get(id); + } + + list(params) { + return super.list(params, 'POST'); + } + + create(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, fiscal_identification_code, street_code, municipal_code) { + return super.create({ + phone_number_country: phone_number_country, + number_type: number_type, + salutation: salutation, + first_name: first_name, + last_name: last_name, + address_line1: address_line1, + address_line2: address_line2, + city: city, + region: region, + postal_code: postal_code, + country_iso: country_iso, + callback_url: callback_url, + alias: alias, + file: file, + proof_type: proof_type, + id_number: id_number, + fiscal_identification_code: fiscal_identification_code, + street_code: street_code, + municipal_code: municipal_code + }, { isMultipart: true }); + } + + update(dataToUpdate) { + + let errors = validate([ + { field: 'address_id', value: dataToUpdate.address_id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return (new Address(this[clientKey], { + id: dataToUpdate.address_id + })).update(dataToUpdate, this.id, { isMultipart: true }); + } + + delete(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return (new Address(this[clientKey], { id: id })).delete(id); + } +} diff --git a/lib/resources/identities.js b/lib/resources/identities.js new file mode 100644 index 00000000..c4f7d0e5 --- /dev/null +++ b/lib/resources/identities.js @@ -0,0 +1,92 @@ +import { extend, validate } from '../utils/common.js'; +import { PlivoResource, PlivoResourceInterface } from '../base'; + +const clientKey = Symbol(); +const action = 'Verification/Identity/'; +const idField = 'id'; + +/* ---------------Identity method----------*/ +export class Identity extends PlivoResource { + constructor(client, data = {}) { + super(action, Identity, idField, client); + this[clientKey] = client; + if (idField in data) { + this.id = data[idField]; + } + + extend(this, data); + } +} + +export class IdentityInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, Identity, idField, client); + extend(this, data); + this[clientKey] = client; + } + + get(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + if (errors) { + return errors; + } + return super.get(id); + } + + list(params) { + return super.list(params, 'POST'); + } + + create(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, fiscal_identification_code, street_code, municipal_code) { + return super.create({ + phone_number_country: phone_number_country, + number_type: number_type, + salutation: salutation, + first_name: first_name, + last_name: last_name, + address_line1: address_line1, + address_line2: address_line2, + city: city, + region: region, + postal_code: postal_code, + country_iso: country_iso, + callback_url: callback_url, + alias: alias, + file: file, + proof_type: proof_type, + id_number: id_number, + fiscal_identification_code: fiscal_identification_code, + street_code: street_code, + municipal_code: municipal_code + }, { isMultipart: true }); + } + + update(dataToUpdate) { + + let errors = validate([ + { field: 'identity_id', value: dataToUpdate.identity_id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return (new Identity(this[clientKey], { + id: dataToUpdate.identity_id + })).update(dataToUpdate, this.id, { isMultipart: true }); + } + + delete(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return (new Identity(this[clientKey], { id: id })).delete(id); + } +} diff --git a/lib/resources/verification.js b/lib/resources/verification.js new file mode 100644 index 00000000..20c8a849 --- /dev/null +++ b/lib/resources/verification.js @@ -0,0 +1,172 @@ +import { + extend, + validate +} from '../utils/common.js'; +import { + PlivoResource, + PlivoResourceInterface +} from '../base'; + +const clientKey = Symbol(); +const addressVerificationAction = 'Verification/Address/'; +const identityVerificationAction = 'Verification/Identity/'; +const idField = 'id'; + +/* ---------------Identity method----------*/ + +export class IdentityVerification extends PlivoResource { + constructor(client, data = {}) { + super(identityVerificationAction, IdentityVerification, idField, client); + + this[clientKey] = client; + + if (idField in data) { + this.id = data[idField]; + } + + extend(this, data); + } + delete_identity(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return (new IdentityVerification(this[clientKey], { + id: id + })).delete(id); + } + + update_identity(dataToUpdate) { + + return (new IdentityVerification(this[clientKey], { + id: dataToUpdate.identity_id + })).update(dataToUpdate, this.id, { isMultipart: true }); + } + +} + +export class IdentityVerificationInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(identityVerificationAction, IdentityVerification, idField, client); + extend(this, data); + + this[clientKey] = client; + } + + retreive_identity(id) { + let errors = validate([ + { field: 'id', value: id, validators: ['isRequired'] } + ]); + + if (errors) { + return errors; + } + + return super.get(id); + + } + + list_all_identity() { + return super.list(); + } + + create_identity(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, nationality, id_nationality, birth_place, birth_date, id_issue_date, business_name, fiscal_identification_code, street_code, municipal_code) { + return super.create({ + phone_number_country: phone_number_country, + number_type: number_type, + salutation: salutation, + first_name: first_name, + last_name: last_name, + address_line1: address_line1, + address_line2: address_line2, + city: city, + region: region, + postal_code: postal_code, + country_iso: country_iso, + callback_url: callback_url, + alias: alias, + file: file, + proof_type: proof_type, + id_number: id_number, + nationality: nationality, + id_nationality: id_nationality, + birth_place: birth_place, + birth_date: birth_date, + id_issue_date: id_issue_date, + business_name: business_name, + fiscal_identification_code: fiscal_identification_code, + street_code: street_code, + municipal_code: municipal_code + }, { isMultipart: true }); + } + + +} + + +/* ---------------Verificatiob Address and Identity method----------*/ +export class Verification { + + constructor(client, data = {}) { + this.addressVerificationResource = new exports.AddressVerification(client); + this.addressVerificationInterface = new exports.AddressVerificationInterface(client); + this.identityVerificationResource = new exports.IdentityVerification(client); + this.identityVerificationInterface = new exports.IdentityVerificationInterface(client); + } + + retreive_address(id) { + return this.addressVerificationInterface.retreive_address(id); + } + + list_all_addresses() { + return this.addressVerificationInterface.list_all_addresses(); + } + + create_address(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, fiscal_identification_code, street_code, municipal_code) { + + return this.addressVerificationInterface.create_address(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, fiscal_identification_code, street_code, municipal_code); + + } + + delete_address(id) { + return this.addressVerificationResource.delete_address(id); + } + update_address(dataToUpdate) { + // If address_id is nor provided in key throw error + return this.addressVerificationResource.update_address(dataToUpdate); + } + + + + + retreive_identity(id) { + return this.identityVerificationInterface.retreive_identity(id); + } + + list_all_identity() { + return this.identityVerificationInterface.list_all_identity(); + } + + create_identity(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, nationality, id_nationality, birth_place, birth_date, id_issue_date, business_name, fiscal_identification_code, street_code, municipal_code) { + + return this.identityVerificationInterface.create_identity(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, country_iso, callback_url, alias, file, proof_type, id_number, nationality, id_nationality, birth_place, birth_date, id_issue_date, business_name, fiscal_identification_code, street_code, municipal_code); + + } + + delete_identity(id) { + return this.identityVerificationResource.delete_identity(id); + } + + update_identity(dataToUpdate) { + + // If identity_id is nor provided in key throw error + + return this.identityVerificationResource.update_identity(dataToUpdate); + } + +} + diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index 03620873..6954150d 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -11,6 +11,8 @@ import { NumberInterface } from '../resources/numbers.js'; import { PricingInterface } from '../resources/pricings.js'; import { RecordingInterface } from '../resources/recordings.js'; import { camelCaseRequestWrapper } from './utils'; +import { AddressInterface } from "../resources/addresses"; +import { IdentityInterface } from "../resources/identities"; export class Client { constructor(authId, authToken, proxy) { @@ -50,6 +52,8 @@ export class Client { this.numbers = new NumberInterface(client); this.pricings = new PricingInterface(client); this.recordings = new RecordingInterface(client); + this.addresses = new AddressInterface(client); + this.identities = new IdentityInterface(client); } } diff --git a/lib/rest/client.js b/lib/rest/client.js index a132b1cb..4e38557e 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -13,6 +13,8 @@ import { PricingInterface } from "../resources/pricings"; import { RecordingInterface } from "../resources/recordings"; import { Response } from "../utils/plivoxml"; import { validateSignature } from "../utils/security"; +import { AddressInterface } from "../resources/addresses"; +import { IdentityInterface } from "../resources/identities"; exports.Response = function () { return new Response(); @@ -46,10 +48,14 @@ export class Client { authId: authId, authToken: authToken, version: 'v1', - url: 'https://api.plivo.com/v1/Account/' + authId, + // url: 'https://api.plivo.com/v1/Account/' + authId, + // url: 'https://api.test.plivo.com/v1/Account/' + authId, + url: 'https://api.numbers.plivodev.com/v1/Account/' + authId, + userAgent: `${'plivo-node'}/${version || 'Unknown Version'} (Node: ${process.version})`, }, options); + let client = camelCaseRequestWrapper(Request(options)); this.calls = new CallInterface(client); @@ -62,6 +68,9 @@ export class Client { this.numbers = new NumberInterface(client); this.pricings = new PricingInterface(client); this.recordings = new RecordingInterface(client); + this.addresses = new AddressInterface(client); + this.identities = new IdentityInterface(client); + } } diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index e03aa132..a329f1a7 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -1,5 +1,6 @@ import request from 'request'; import queryString from 'querystring'; +import { InvalidRequestError } from './../utils/exceptions'; export function Request(config) { let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken) @@ -11,13 +12,33 @@ export function Request(config) { 'Content-Type': 'application/json' }; - return (method, action, params) => { + //Here config is an optional parameter can have following keys + // isMultipart, saying if request to be made is multipart + return (method, action, params, requestConfig) => { + + // console.log('request ==>', method, action, requestConfig); + + // Build copy of original headers + var currentHeaders = JSON.parse(JSON.stringify(headers)); + + if (requestConfig && requestConfig.isMultipart == true) { + currentHeaders['Content-Type'] = 'multipart/form-data'; + if (params.file) { + params.file = require('fs').createReadStream(params.file); + for (var key in params) { + if (params[key] === undefined || params[key] == null) { + params[key] = ''; + } + } + } + } + params = params || {}; var options = { url: config.url + '/' + action, method: method, formData: params || '', - headers: headers, + headers: currentHeaders, json: true }; @@ -1071,6 +1092,273 @@ export function Request(config) { }); } + // *************=================== Identity Verification *************=================== // + + // List identities + else if (method == 'GET' && action == 'Verification/Identity/') { + resolve({ + response: {}, + body: + { + api_id: '0b163520-2443-11e9-8480-0242ac110004', + meta: + { + limit: 3, + next: + 'https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Identity/?offset=3', + offset: 0, + previous: null, + total_count: 116 + }, + objects: [{ + "id": "11200986643200", + "account": "MAMTI0ZWVIMDC5MMRIOT", + "addressLine1": "32432", + "addressLine2": "23432", + "addressProofType": "identity", + "alias": null, + "city": "324", + "countryIso": "US", + "documentDetails": { + "addressLine1": "32432", + "addressLine2": "23432", + "city": "324", + "firstName": "test", + "idNumber": "ashish", + "lastName": "test", + "nationality": "TT", + "postalCode": "23432", + "proofType": "ed", + "region": "324", + "salutation": "Mr" + }, + "firstName": "test", + "idNumber": "ashish", + "iso3": "USA", + "lastName": "test", + "nationality": "TT", + "pk": 216, + "postalCode": "23432", + "proofType": "ed", + "region": "324", + "salutation": "Mr", + "subaccount": null, + "url": "https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Download/Document/11200986643200/", + "validationStatus": "accepted", + "verificationStatus": "pending" + }] + } + }); + } + //Get identity details + else if (method == 'GET' && action == 'Verification/Identity/27658110766647/') { + resolve({ + response: {}, + body: + { + "id": "11200986643200", + "account": "MAMTI0ZWVIMDC5MMRIOT", + "addressLine1": "32432", + "addressLine2": "23432", + "addressProofType": "identity", + "alias": null, + "city": "324", + "countryIso": "US", + "documentDetails": { + "addressLine1": "32432", + "addressLine2": "23432", + "city": "324", + "firstName": "test", + "idNumber": "ashish", + "lastName": "test", + "nationality": "TT", + "postalCode": "23432", + "proofType": "ed", + "region": "324", + "salutation": "Mr" + }, + "firstName": "test", + "idNumber": "ashish", + "iso3": "USA", + "lastName": "test", + "nationality": "TT", + "pk": 216, + "postalCode": "23432", + "proofType": "ed", + "region": "324", + "salutation": "Mr", + "subaccount": null, + "url": "https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Download/Document/11200986643200/", + "validationStatus": "accepted", + "verificationStatus": "pending" + } + }); + } + + //Create Identity Detail By Document Id - Valid input data + else if (method == 'POST' && action == 'Verification/Identity/' && params.first_name == '') { + var response = { + error: 'first_name field is mandatory.', + message: 'Could not complete identity verification.', + status: 'error' + } + throw new InvalidRequestError(JSON.stringify(response)); + } + + //Create Identity Detail By Document Id - Valid input data + else if (method == 'POST' && action == 'Verification/Identity/') { + resolve({ + response: {}, + body: { "apiId": "3269e592-2478-11e9-b01f-0242ac110002", "message": "Your request has been accepted." } + }); + } + + //Update Identity => - Invalid input data + else if (method == 'POST' && action == 'Verification/Identity//' && params.first_name == '') { + var response = { + error: 'first_name field is mandatory.', + message: 'Could not complete Identity verification.', + status: 'error' + } + throw new InvalidRequestError(JSON.stringify(response)); + } + + //Update Identity => Valid input data + else if (method == 'POST' && action == 'Verification/Identity//') { + resolve({ + response: {}, + body: { "apiId": "3269e592-2478-11e9-b01f-0242ac110002", "message": "Your request has been accepted." } + }); + } + + //Delete Identity => input data + else if (method == 'DELETE' && action == 'Verification/Identity/18294047791076/') { + resolve({ + response: {}, + body: undefined + }); + } + + // *************=================== Address Verification *************=================== // + + // List Addresses + else if (method == 'GET' && action == 'Verification/Address/') { + resolve({ + response: {}, + body: { + meta: + { + limit: 3, + next: + 'https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Address/?offset=3', + offset: 0, + previous: null, + total_count: 378 + }, + objects: + [{ + account: 'MAMTI0ZWVIMDC5MMRIOT', + address_line1: '2929 Walker Ave NW', + address_line2: 'MI', + address_proof_type: 'address', + alias: '', + city: 'Grand Rapids', + country_iso: 'US', + document_details: [Object], + first_name: 'Ashish', + id: '', + iso3: 'USA', + last_name: 'Ranjan', + pk: 154, + postal_code: '49544', + region: 'Grand Rapids', + salutation: 'Mr', + subaccount: null, + url: + 'https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Download/Document//', + validation_status: 'rejected', + verification_status: 'pending' + }] + } + }); + } + + // Address Detail => By Document Id + else if (method == 'GET' && action == 'Verification/Address/14632037725844/') { + resolve({ + response: {}, + body: + { + account: 'MAMTI0ZWVIMDC5MMRIOT', + address_line1: '2929 Walker Ave NW', + address_line2: 'MI', + address_proof_type: 'address', + alias: '', + city: 'Grand Rapids', + country_iso: 'US', + document_details: [Object], + first_name: 'Ashish', + id: '', + iso3: 'USA', + last_name: 'Ranjan', + pk: 154, + postal_code: '49544', + region: 'Grand Rapids', + salutation: 'Mr', + subaccount: null, + url: + 'https://api.test.plivo.com/v1/Account/MAMTI0ZWVIMDC5MMRIOT/Verification/Download/Document//', + validation_status: 'rejected', + verification_status: 'pending' + } + }); + } + + //Create Address => Invalid input data + else if (method == 'POST' && action == 'Verification/Address/' && params.first_name == '') { + var response = { + error: 'first_name field is mandatory.', + message: 'Could not complete Address verification.', + status: 'error' + } + throw new InvalidRequestError(JSON.stringify(response)); + } + + //Create Address - Valid input data + else if (method == 'POST' && action == 'Verification/Address/') { + resolve({ + response: {}, + body: { "apiId": "3269e592-2478-11e9-b01f-0242ac110002", "message": "Your request has been accepted." } + }); + } + + //Update Address => - Invalid input data + else if (method == 'POST' && action == 'Verification/Address/73529957241107/' && params.first_name == '') { + var response = { + error: 'first_name field is mandatory.', + message: 'Could not complete Address verification.', + status: 'error' + } + throw new InvalidRequestError(JSON.stringify(response)); + } + + //Update Address => Valid input data + else if (method == 'POST' && action == 'Verification/Address/23991395742603/') { + resolve({ + response: {}, + body: { "apiId": "3269e592-2478-11e9-b01f-0242ac110002", "message": "Your request has been accepted." } + }); + } + + + //Delete Address => input data + else if (method == 'DELETE' && action == 'Verification/Address/87928077747492/') { + resolve({ + response: {}, + body: undefined + }); + } + // =========== PHLO ============================ // Get phlo details else if (method == 'GET' && action == 'phlo/sample-phlo-id/') { diff --git a/lib/rest/request.js b/lib/rest/request.js index 30b59686..c65e3efb 100644 --- a/lib/rest/request.js +++ b/lib/rest/request.js @@ -13,12 +13,32 @@ export function Request(config) { 'Content-Type': 'application/json' }; - return (method, action, params) => { + //Here config is an optional parameter can have following keys + // isMultipart, saying if request to be made is multipart + return (method, action, params, requestConfig) => { + + // Build copy of original headers + var currentHeaders = JSON.parse(JSON.stringify(headers)); + + console.log('at requset =>', method, action, params, requestConfig); + if (requestConfig && requestConfig.isMultipart == true) { + currentHeaders['Content-Type'] = 'multipart/form-data'; + // If file provided, read the file + if (params.file) { + params.file = require('fs').createReadStream(params.file); + for (var key in params) { + if (params[key] === undefined || params[key] == null) { + params[key] = ''; + } + } + } + } + var options = { url: config.url + '/' + action, method: method, formData: params || '', - headers: headers, + headers: currentHeaders, json: true }; @@ -34,14 +54,15 @@ export function Request(config) { if (typeof config.timeout !== 'undefined') { options.timeout = config.timeout; } - + console.log('==> dummy data', action, method); return new Promise((resolve, reject) => { + console.log('request options', options); request(options, (error, response, body) => { if (error) { reject(error); return; } - + console.log('Response =>', response.statusCode, body); const exceptionClass = { 400: Exceptions.InvalidRequestError, 401: Exceptions.AuthenticationError, diff --git a/lib/rest/utils.js b/lib/rest/utils.js index 81f4cf3b..1a5fd2c6 100644 --- a/lib/rest/utils.js +++ b/lib/rest/utils.js @@ -19,10 +19,24 @@ function recursivelyRenameObject(object, renameFunc) { } export function camelCaseRequestWrapper(requestFunc) { - return (method, action, params) => { + return (method, action, params, requestConfig) => { params = recursivelyRenameObject(params, function (value, key) { - if(typeof key !== 'string') return key; + if (typeof key !== 'string') return key; + + if (key == 'address_line1' || key == 'address_line2') { + return key; + } + + // Snake Case logic has issue, it replaces double underscores with single + // So dont run snake case logic for following params + let skipParamsFromSnakeCasing = [ + 'message_time__lt', 'message_time__lte', + 'message_time__gt', 'message_time__gte', + ] + if (skipParamsFromSnakeCasing.indexOf(key) >= 0) { + return key; + } return _snakeCase(key) .replace('_less_than', '__lt') @@ -33,9 +47,9 @@ export function camelCaseRequestWrapper(requestFunc) { .replace('_equals', ''); }); - return requestFunc(method, action, params).then(res => { + return requestFunc(method, action, params, requestConfig).then(res => { res.body = recursivelyRenameObject(res.body, function (value, key) { - if(typeof key !== 'string') return key; + if (typeof key !== 'string') return key; return _camelCase(key); }); diff --git a/lib/utils/plivoxml.js b/lib/utils/plivoxml.js index 73d08853..a7ab1cc4 100644 --- a/lib/utils/plivoxml.js +++ b/lib/utils/plivoxml.js @@ -2,7 +2,7 @@ var qs = require('querystring'); var xmlBuilder = require('xmlbuilder'); var util = require('util'); -export class PlivoXMLError extends Error {} +export class PlivoXMLError extends Error { } /** * Response element @@ -227,7 +227,7 @@ Response.prototype = { * @param {string} [attributes.callbackMethod] */ addRecord: function (attributes) { - return this.add(new Record(Response),'', attributes); + return this.add(new Record(Response), '', attributes); }, /** @@ -251,9 +251,23 @@ Response.prototype = { * @param {number} [attributes.loop] */ addSpeak: function (body, attributes) { - return this.add(new Speak(Response), body, attributes); + //Convert accented characters to numerical references first + let accentedCharsList = { + "Á": "A", "Ă": "A", "Ắ": "A", "Ặ": "A", "Ằ": "A", "Ẳ": "A", "Ẵ": "A", "Ǎ": "A", "Â": "A", "Ấ": "A", "Ậ": "A", "Ầ": "A", "Ẩ": "A", "Ẫ": "A", "Ä": "A", "Ǟ": "A", "Ȧ": "A", "Ǡ": "A", "Ạ": "A", "Ȁ": "A", "À": "A", "Ả": "A", "Ȃ": "A", "Ā": "A", "Ą": "A", "Å": "A", "Ǻ": "A", "Ḁ": "A", "Ⱥ": "A", "Ã": "A", "Ꜳ": "AA", "Æ": "AE", "Ǽ": "AE", "Ǣ": "AE", "Ꜵ": "AO", "Ꜷ": "AU", "Ꜹ": "AV", "Ꜻ": "AV", "Ꜽ": "AY", "Ḃ": "B", "Ḅ": "B", "Ɓ": "B", "Ḇ": "B", "Ƀ": "B", "Ƃ": "B", "Ć": "C", "Č": "C", "Ç": "C", "Ḉ": "C", "Ĉ": "C", "Ċ": "C", "Ƈ": "C", "Ȼ": "C", "Ď": "D", "Ḑ": "D", "Ḓ": "D", "Ḋ": "D", "Ḍ": "D", "Ɗ": "D", "Ḏ": "D", "Dz": "D", "Dž": "D", "Đ": "D", "Ƌ": "D", "DZ": "DZ", "DŽ": "DZ", "É": "E", "Ĕ": "E", "Ě": "E", "Ȩ": "E", "Ḝ": "E", "Ê": "E", "Ế": "E", "Ệ": "E", "Ề": "E", "Ể": "E", "Ễ": "E", "Ḙ": "E", "Ë": "E", "Ė": "E", "Ẹ": "E", "Ȅ": "E", "È": "E", "Ẻ": "E", "Ȇ": "E", "Ē": "E", "Ḗ": "E", "Ḕ": "E", "Ę": "E", "Ɇ": "E", "Ẽ": "E", "Ḛ": "E", "Ꝫ": "ET", "Ḟ": "F", "Ƒ": "F", "Ǵ": "G", "Ğ": "G", "Ǧ": "G", "Ģ": "G", "Ĝ": "G", "Ġ": "G", "Ɠ": "G", "Ḡ": "G", "Ǥ": "G", "Ḫ": "H", "Ȟ": "H", "Ḩ": "H", "Ĥ": "H", "Ⱨ": "H", "Ḧ": "H", "Ḣ": "H", "Ḥ": "H", "Ħ": "H", "Í": "I", "Ĭ": "I", "Ǐ": "I", "Î": "I", "Ï": "I", "Ḯ": "I", "İ": "I", "Ị": "I", "Ȉ": "I", "Ì": "I", "Ỉ": "I", "Ȋ": "I", "Ī": "I", "Į": "I", "Ɨ": "I", "Ĩ": "I", "Ḭ": "I", "Ꝺ": "D", "Ꝼ": "F", "Ᵹ": "G", "Ꞃ": "R", "Ꞅ": "S", "Ꞇ": "T", "Ꝭ": "IS", "Ĵ": "J", "Ɉ": "J", "Ḱ": "K", "Ǩ": "K", "Ķ": "K", "Ⱪ": "K", "Ꝃ": "K", "Ḳ": "K", "Ƙ": "K", "Ḵ": "K", "Ꝁ": "K", "Ꝅ": "K", "Ĺ": "L", "Ƚ": "L", "Ľ": "L", "Ļ": "L", "Ḽ": "L", "Ḷ": "L", "Ḹ": "L", "Ⱡ": "L", "Ꝉ": "L", "Ḻ": "L", "Ŀ": "L", "Ɫ": "L", "Lj": "L", "Ł": "L", "LJ": "LJ", "Ḿ": "M", "Ṁ": "M", "Ṃ": "M", "Ɱ": "M", "Ń": "N", "Ň": "N", "Ņ": "N", "Ṋ": "N", "Ṅ": "N", "Ṇ": "N", "Ǹ": "N", "Ɲ": "N", "Ṉ": "N", "Ƞ": "N", "Nj": "N", "Ñ": "N", "NJ": "NJ", "Ó": "O", "Ŏ": "O", "Ǒ": "O", "Ô": "O", "Ố": "O", "Ộ": "O", "Ồ": "O", "Ổ": "O", "Ỗ": "O", "Ö": "O", "Ȫ": "O", "Ȯ": "O", "Ȱ": "O", "Ọ": "O", "Ő": "O", "Ȍ": "O", "Ò": "O", "Ỏ": "O", "Ơ": "O", "Ớ": "O", "Ợ": "O", "Ờ": "O", "Ở": "O", "Ỡ": "O", "Ȏ": "O", "Ꝋ": "O", "Ꝍ": "O", "Ō": "O", "Ṓ": "O", "Ṑ": "O", "Ɵ": "O", "Ǫ": "O", "Ǭ": "O", "Ø": "O", "Ǿ": "O", "Õ": "O", "Ṍ": "O", "Ṏ": "O", "Ȭ": "O", "Ƣ": "OI", "Ꝏ": "OO", "Ɛ": "E", "Ɔ": "O", "Ȣ": "OU", "Ṕ": "P", "Ṗ": "P", "Ꝓ": "P", "Ƥ": "P", "Ꝕ": "P", "Ᵽ": "P", "Ꝑ": "P", "Ꝙ": "Q", "Ꝗ": "Q", "Ŕ": "R", "Ř": "R", "Ŗ": "R", "Ṙ": "R", "Ṛ": "R", "Ṝ": "R", "Ȑ": "R", "Ȓ": "R", "Ṟ": "R", "Ɍ": "R", "Ɽ": "R", "Ꜿ": "C", "Ǝ": "E", "Ś": "S", "Ṥ": "S", "Š": "S", "Ṧ": "S", "Ş": "S", "Ŝ": "S", "Ș": "S", "Ṡ": "S", "Ṣ": "S", "Ṩ": "S", "Ť": "T", "Ţ": "T", "Ṱ": "T", "Ț": "T", "Ⱦ": "T", "Ṫ": "T", "Ṭ": "T", "Ƭ": "T", "Ṯ": "T", "Ʈ": "T", "Ŧ": "T", "Ɐ": "A", "Ꞁ": "L", "Ɯ": "M", "Ʌ": "V", "Ꜩ": "TZ", "Ú": "U", "Ŭ": "U", "Ǔ": "U", "Û": "U", "Ṷ": "U", "Ü": "U", "Ǘ": "U", "Ǚ": "U", "Ǜ": "U", "Ǖ": "U", "Ṳ": "U", "Ụ": "U", "Ű": "U", "Ȕ": "U", "Ù": "U", "Ủ": "U", "Ư": "U", "Ứ": "U", "Ự": "U", "Ừ": "U", "Ử": "U", "Ữ": "U", "Ȗ": "U", "Ū": "U", "Ṻ": "U", "Ų": "U", "Ů": "U", "Ũ": "U", "Ṹ": "U", "Ṵ": "U", "Ꝟ": "V", "Ṿ": "V", "Ʋ": "V", "Ṽ": "V", "Ꝡ": "VY", "Ẃ": "W", "Ŵ": "W", "Ẅ": "W", "Ẇ": "W", "Ẉ": "W", "Ẁ": "W", "Ⱳ": "W", "Ẍ": "X", "Ẋ": "X", "Ý": "Y", "Ŷ": "Y", "Ÿ": "Y", "Ẏ": "Y", "Ỵ": "Y", "Ỳ": "Y", "Ƴ": "Y", "Ỷ": "Y", "Ỿ": "Y", "Ȳ": "Y", "Ɏ": "Y", "Ỹ": "Y", "Ź": "Z", "Ž": "Z", "Ẑ": "Z", "Ⱬ": "Z", "Ż": "Z", "Ẓ": "Z", "Ȥ": "Z", "Ẕ": "Z", "Ƶ": "Z", "IJ": "IJ", "Œ": "OE", "ᴀ": "A", "ᴁ": "AE", "ʙ": "B", "ᴃ": "B", "ᴄ": "C", "ᴅ": "D", "ᴇ": "E", "ꜰ": "F", "ɢ": "G", "ʛ": "G", "ʜ": "H", "ɪ": "I", "ʁ": "R", "ᴊ": "J", "ᴋ": "K", "ʟ": "L", "ᴌ": "L", "ᴍ": "M", "ɴ": "N", "ᴏ": "O", "ɶ": "OE", "ᴐ": "O", "ᴕ": "OU", "ᴘ": "P", "ʀ": "R", "ᴎ": "N", "ᴙ": "R", "ꜱ": "S", "ᴛ": "T", "ⱻ": "E", "ᴚ": "R", "ᴜ": "U", "ᴠ": "V", "ᴡ": "W", "ʏ": "Y", "ᴢ": "Z", "á": "a", "ă": "a", "ắ": "a", "ặ": "a", "ằ": "a", "ẳ": "a", "ẵ": "a", "ǎ": "a", "â": "a", "ấ": "a", "ậ": "a", "ầ": "a", "ẩ": "a", "ẫ": "a", "ä": "a", "ǟ": "a", "ȧ": "a", "ǡ": "a", "ạ": "a", "ȁ": "a", "à": "a", "ả": "a", "ȃ": "a", "ā": "a", "ą": "a", "ᶏ": "a", "ẚ": "a", "å": "a", "ǻ": "a", "ḁ": "a", "ⱥ": "a", "ã": "a", "ꜳ": "aa", "æ": "ae", "ǽ": "ae", "ǣ": "ae", "ꜵ": "ao", "ꜷ": "au", "ꜹ": "av", "ꜻ": "av", "ꜽ": "ay", "ḃ": "b", "ḅ": "b", "ɓ": "b", "ḇ": "b", "ᵬ": "b", "ᶀ": "b", "ƀ": "b", "ƃ": "b", "ɵ": "o", "ć": "c", "č": "c", "ç": "c", "ḉ": "c", "ĉ": "c", "ɕ": "c", "ċ": "c", "ƈ": "c", "ȼ": "c", "ď": "d", "ḑ": "d", "ḓ": "d", "ȡ": "d", "ḋ": "d", "ḍ": "d", "ɗ": "d", "ᶑ": "d", "ḏ": "d", "ᵭ": "d", "ᶁ": "d", "đ": "d", "ɖ": "d", "ƌ": "d", "ı": "i", "ȷ": "j", "ɟ": "j", "ʄ": "j", "dz": "dz", "dž": "dz", "é": "e", "ĕ": "e", "ě": "e", "ȩ": "e", "ḝ": "e", "ê": "e", "ế": "e", "ệ": "e", "ề": "e", "ể": "e", "ễ": "e", "ḙ": "e", "ë": "e", "ė": "e", "ẹ": "e", "ȅ": "e", "è": "e", "ẻ": "e", "ȇ": "e", "ē": "e", "ḗ": "e", "ḕ": "e", "ⱸ": "e", "ę": "e", "ᶒ": "e", "ɇ": "e", "ẽ": "e", "ḛ": "e", "ꝫ": "et", "ḟ": "f", "ƒ": "f", "ᵮ": "f", "ᶂ": "f", "ǵ": "g", "ğ": "g", "ǧ": "g", "ģ": "g", "ĝ": "g", "ġ": "g", "ɠ": "g", "ḡ": "g", "ᶃ": "g", "ǥ": "g", "ḫ": "h", "ȟ": "h", "ḩ": "h", "ĥ": "h", "ⱨ": "h", "ḧ": "h", "ḣ": "h", "ḥ": "h", "ɦ": "h", "ẖ": "h", "ħ": "h", "ƕ": "hv", "í": "i", "ĭ": "i", "ǐ": "i", "î": "i", "ï": "i", "ḯ": "i", "ị": "i", "ȉ": "i", "ì": "i", "ỉ": "i", "ȋ": "i", "ī": "i", "į": "i", "ᶖ": "i", "ɨ": "i", "ĩ": "i", "ḭ": "i", "ꝺ": "d", "ꝼ": "f", "ᵹ": "g", "ꞃ": "r", "ꞅ": "s", "ꞇ": "t", "ꝭ": "is", "ǰ": "j", "ĵ": "j", "ʝ": "j", "ɉ": "j", "ḱ": "k", "ǩ": "k", "ķ": "k", "ⱪ": "k", "ꝃ": "k", "ḳ": "k", "ƙ": "k", "ḵ": "k", "ᶄ": "k", "ꝁ": "k", "ꝅ": "k", "ĺ": "l", "ƚ": "l", "ɬ": "l", "ľ": "l", "ļ": "l", "ḽ": "l", "ȴ": "l", "ḷ": "l", "ḹ": "l", "ⱡ": "l", "ꝉ": "l", "ḻ": "l", "ŀ": "l", "ɫ": "l", "ᶅ": "l", "ɭ": "l", "ł": "l", "lj": "lj", "ſ": "s", "ẜ": "s", "ẛ": "s", "ẝ": "s", "ḿ": "m", "ṁ": "m", "ṃ": "m", "ɱ": "m", "ᵯ": "m", "ᶆ": "m", "ń": "n", "ň": "n", "ņ": "n", "ṋ": "n", "ȵ": "n", "ṅ": "n", "ṇ": "n", "ǹ": "n", "ɲ": "n", "ṉ": "n", "ƞ": "n", "ᵰ": "n", "ᶇ": "n", "ɳ": "n", "ñ": "n", "nj": "nj", "ó": "o", "ŏ": "o", "ǒ": "o", "ô": "o", "ố": "o", "ộ": "o", "ồ": "o", "ổ": "o", "ỗ": "o", "ö": "o", "ȫ": "o", "ȯ": "o", "ȱ": "o", "ọ": "o", "ő": "o", "ȍ": "o", "ò": "o", "ỏ": "o", "ơ": "o", "ớ": "o", "ợ": "o", "ờ": "o", "ở": "o", "ỡ": "o", "ȏ": "o", "ꝋ": "o", "ꝍ": "o", "ⱺ": "o", "ō": "o", "ṓ": "o", "ṑ": "o", "ǫ": "o", "ǭ": "o", "ø": "o", "ǿ": "o", "õ": "o", "ṍ": "o", "ṏ": "o", "ȭ": "o", "ƣ": "oi", "ꝏ": "oo", "ɛ": "e", "ᶓ": "e", "ɔ": "o", "ᶗ": "o", "ȣ": "ou", "ṕ": "p", "ṗ": "p", "ꝓ": "p", "ƥ": "p", "ᵱ": "p", "ᶈ": "p", "ꝕ": "p", "ᵽ": "p", "ꝑ": "p", "ꝙ": "q", "ʠ": "q", "ɋ": "q", "ꝗ": "q", "ŕ": "r", "ř": "r", "ŗ": "r", "ṙ": "r", "ṛ": "r", "ṝ": "r", "ȑ": "r", "ɾ": "r", "ᵳ": "r", "ȓ": "r", "ṟ": "r", "ɼ": "r", "ᵲ": "r", "ᶉ": "r", "ɍ": "r", "ɽ": "r", "ↄ": "c", "ꜿ": "c", "ɘ": "e", "ɿ": "r", "ś": "s", "ṥ": "s", "š": "s", "ṧ": "s", "ş": "s", "ŝ": "s", "ș": "s", "ṡ": "s", "ṣ": "s", "ṩ": "s", "ʂ": "s", "ᵴ": "s", "ᶊ": "s", "ȿ": "s", "ɡ": "g", "ᴑ": "o", "ᴓ": "o", "ᴝ": "u", "ť": "t", "ţ": "t", "ṱ": "t", "ț": "t", "ȶ": "t", "ẗ": "t", "ⱦ": "t", "ṫ": "t", "ṭ": "t", "ƭ": "t", "ṯ": "t", "ᵵ": "t", "ƫ": "t", "ʈ": "t", "ŧ": "t", "ᵺ": "th", "ɐ": "a", "ᴂ": "ae", "ǝ": "e", "ᵷ": "g", "ɥ": "h", "ʮ": "h", "ʯ": "h", "ᴉ": "i", "ʞ": "k", "ꞁ": "l", "ɯ": "m", "ɰ": "m", "ᴔ": "oe", "ɹ": "r", "ɻ": "r", "ɺ": "r", "ⱹ": "r", "ʇ": "t", "ʌ": "v", "ʍ": "w", "ʎ": "y", "ꜩ": "tz", "ú": "u", "ŭ": "u", "ǔ": "u", "û": "u", "ṷ": "u", "ü": "u", "ǘ": "u", "ǚ": "u", "ǜ": "u", "ǖ": "u", "ṳ": "u", "ụ": "u", "ű": "u", "ȕ": "u", "ù": "u", "ủ": "u", "ư": "u", "ứ": "u", "ự": "u", "ừ": "u", "ử": "u", "ữ": "u", "ȗ": "u", "ū": "u", "ṻ": "u", "ų": "u", "ᶙ": "u", "ů": "u", "ũ": "u", "ṹ": "u", "ṵ": "u", "ᵫ": "ue", "ꝸ": "um", "ⱴ": "v", "ꝟ": "v", "ṿ": "v", "ʋ": "v", "ᶌ": "v", "ⱱ": "v", "ṽ": "v", "ꝡ": "vy", "ẃ": "w", "ŵ": "w", "ẅ": "w", "ẇ": "w", "ẉ": "w", "ẁ": "w", "ⱳ": "w", "ẘ": "w", "ẍ": "x", "ẋ": "x", "ᶍ": "x", "ý": "y", "ŷ": "y", "ÿ": "y", "ẏ": "y", "ỵ": "y", "ỳ": "y", "ƴ": "y", "ỷ": "y", "ỿ": "y", "ȳ": "y", "ẙ": "y", "ɏ": "y", "ỹ": "y", "ź": "z", "ž": "z", "ẑ": "z", "ʑ": "z", "ⱬ": "z", "ż": "z", "ẓ": "z", "ȥ": "z", "ẕ": "z", "ᵶ": "z", "ᶎ": "z", "ʐ": "z", "ƶ": "z", "ɀ": "z", "ff": "ff", "ffi": "ffi", "ffl": "ffl", "fi": "fi", "fl": "fl", "ij": "ij", "œ": "oe", "st": "st", "ₐ": "a", "ₑ": "e", "ᵢ": "i", "ⱼ": "j", "ₒ": "o", "ᵣ": "r", "ᵤ": "u", "ᵥ": "v", "ₓ": "x" + + }; + let newBody = ''; + for (var i = 0; i < body.length; i++) { + if (accentedCharsList[body[i]]) { + newBody += '&#' + body.charCodeAt(i) + ';'; + } else { + newBody += body[i]; + } + } + return this.add(new Speak(Response), newBody, attributes); }, + /** * Add a Wait element * @method @@ -291,7 +305,7 @@ function Conference(Response) { this.element = 'Conference'; this.valid_attributes = ['muted', 'beep', 'startConferenceOnEnter', 'endConferenceOnExit', 'waitSound', 'enterSound', 'exitSound', - 'timeLimit', 'hangupOnStar', 'maxMembers', 'record','recordWhenAlone', + 'timeLimit', 'hangupOnStar', 'maxMembers', 'record', 'recordWhenAlone', 'recordFileFormat', 'action', 'method', 'redirect', 'digitsMatch', 'callbackUrl', 'callbackMethod', 'stayAlone', 'floorEvent', 'transcriptionType', 'transcriptionUrl', diff --git a/package-lock.json b/package-lock.json index bfdb65a4..952e1aef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.0.5", + "version": "4.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1214,9 +1214,9 @@ "dev": true }, "core-js": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.2.tgz", - "integrity": "sha512-NdBPF/RVwPW6jr0NCILuyN9RiqLo2b1mddWHkUL+VnvcB7dzlnBJ1bXYntjpTGOgkZiiLWj2JxmOr7eGE3qK6g==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.3.tgz", + "integrity": "sha512-l00tmFFZOBHtYhN4Cz7k32VM7vTn3rE2ANjQDxdEN6zmXZ/xq1jQuutnmHvMG1ZJ7xd72+TA5YpUK8wz3rWsfQ==", "dev": true }, "core-util-is": { @@ -4205,9 +4205,9 @@ } }, "parse-node-version": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.0.tgz", - "integrity": "sha512-02GTVHD1u0nWc20n2G7WX/PgdhNFG04j5fi1OkaJzPWLTcf6vh6229Lta1wTmXG/7Dg42tCssgkccVt7qvd8Kg==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz", + "integrity": "sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==", "dev": true }, "parse-passwd": { @@ -4574,9 +4574,9 @@ } }, "resolve": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz", - "integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", + "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", "dev": true, "requires": { "path-parse": "^1.0.6" @@ -4921,9 +4921,9 @@ "dev": true }, "sshpk": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.0.tgz", - "integrity": "sha512-Zhev35/y7hRMcID/upReIvRse+I9SVhyVre/KTJSJQWMz3C3+G+HpO7m1wK/yckEtujKZ7dS4hkVxAnmHaIGVQ==", + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -5577,4 +5577,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/test/api_uploads/address_proof.png b/test/api_uploads/address_proof.png new file mode 100644 index 00000000..21675498 Binary files /dev/null and b/test/api_uploads/address_proof.png differ diff --git a/test/test.address.js b/test/test.address.js new file mode 100644 index 00000000..d674fa09 --- /dev/null +++ b/test/test.address.js @@ -0,0 +1,141 @@ +// import { Client } from '../lib/rest/client'; +import { Client } from '../lib/rest/client-test'; + +let authId = 'auth_id'; +let authToken = 'auth_token'; + +let client = new Client(authId, authToken); + + +describe('Address Interface', function () { + + it('Get Address List', function (done) { + client.addresses.list().then(function (addressList) { + done(); + }).catch(function (err) { + done(new Error("Test Failed. - Failed to fetch address list")) + }) + }); + + it('Get Address Details', function (done) { + client.addresses.get(14632037725844).then(function (identityDetails) { + // console.log('identity detail is =>', JSON.stringify(identityDetails)); + done(); + }).catch(function (err) { + done(new Error("Test Failed. - Failed to fetch address details")) + }) + }); + + + it('Create Address - In-valid Fields', function (done) { + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + client.addresses.create("in", "9898997510", 'Mr', null, 'DEF', 'bhagwati heritage 1201', 'sector-21', 'mumbai', 'maharashtra', '410209', 'IN', 'https://www.google.com/', 'Null', addressProofPath, 'passport', '123', 'IN', 'ind-123', 'gujarat', '01-02-1991', 'id-date-12/10/2017', 'bus-plivo', 'fascal123', 'st12', 'mu34') + .then(function (addressDetails) { + // console.log('address Create result =>', JSON.stringify(addressDetails)); + done(new Error("Invalid result. Create address should throw error with invalid data.")) + }) + .catch(function (Erroraddress) { + done(); + // console.log("address result==>", Erroraddress); + }) + }); + + it('Create Address - Valid Fields', function (done) { + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + client.addresses.create("in", "9898997510", 'Mr', "ABC", 'DEF', 'bhagwati heritage 1201', 'sector-21', 'mumbai', 'maharashtra', '410209', 'IN', 'https://www.google.com/', 'Null', addressProofPath, 'passport', '123', 'IN', 'ind-123', 'gujarat', '01-02-1991', 'id-date-12/10/2017', 'bus-plivo', 'fascal123', 'st12', 'mu34') + .then(function (addressDetails) { + // console.log('address Create result =>', JSON.stringify(addressDetails)); + done(); + }) + .catch(function (err) { + done(new Error("Invalid result. Create address should not throw error with valid data.")) + console.log(err); + }) + }); + + it('Update Address with valid data', function (done) { + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + var params = { + address_id: "23991395742603", + proof_type: "PASSPORT", + phone_number_country: "in", + number_type: "9898989685", + salutation: "Mr", + // first_name: first_name, + // last_name: last_name, + // address_line1: address_line1, + // address_line2: address_line2, + // city: city, + // region: region, + // postal_code: postal_code, + // country_iso: country_iso, + // callback_url: callback_url, + // alias: alias, + // file: addressProofPath, + // proof_type: proof_type, + // id_number: id_number, + // fiscal_identification_code: fiscal_identification_code, + // street_code: street_code, + // municipal_code: municipal_code + }; + + + client.addresses.update(params).then(function (updateResult) { + done(); + }).catch((err) => { + done(err); + }); + + }); + + it('Update Address - Without address_id', function (done) { + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + var params = { + // address_id: "73529957241107", + proof_type: "PASSPORT", + phone_number_country: "in", + number_type: "9898989685", + salutation: "Mr", + // first_name: first_name, + // last_name: last_name, + // address_line1: address_line1, + // address_line2: address_line2, + // city: city, + // region: region, + // postal_code: postal_code, + // country_iso: country_iso, + // callback_url: callback_url, + // alias: alias, + // file: addressProofPath, + // proof_type: proof_type, + // id_number: id_number, + // fiscal_identification_code: fiscal_identification_code, + // street_code: street_code, + // municipal_code: municipal_code + }; + + + client.addresses.update(params).then(function (updateResult) { + done(new Error("Invalid result. Update address should throw error when address_id not provided.")) + }).catch((err) => { + done(); + }); + + }); + + + it('Delete Address', function (done) { + client.addresses.delete(87928077747492).then(function (deleteResult) { + // console.log('address delete result =>', JSON.stringify(deleteResult)); + done(); + }).catch(function (err) { + done(err); + }); + }); + +}); diff --git a/test/test.identity.js b/test/test.identity.js new file mode 100644 index 00000000..e9cadf59 --- /dev/null +++ b/test/test.identity.js @@ -0,0 +1,156 @@ +// import { Client } from '../lib/rest/client'; +import { Client } from '../lib/rest/client-test'; + +let authId = 'auth_id'; +let authToken = 'auth_token'; + +let client = new Client(authId, authToken); + + +describe('Identity Interface', function () { + + it('Get Identity List', function (done) { + client.identities.list().then(function (identityList) { + // console.log('identity list is =>', JSON.stringify(identityList)); + done() + }).catch(function (err) { + done(err); + }); + }); + + it('Get Identity Details', function (done) { + client.identities.get(27658110766647).then(function (identityDetails) { + // console.log('identity detail is =>', JSON.stringify(identityDetails)); + done() + }).catch(function (err) { + done(err); + }); + }); + + it('Create Identity - In-valid Fields', function (done) { + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + client.identities.create("in", "9898997510", 'Mr', null, 'DEF', 'bhagwati heritage 1201', 'sector-21', 'mumbai', 'maharashtra', '410209', 'IN', 'https://www.google.com/', 'Null', addressProofPath, 'passport', '123', 'IN', 'ind-123', 'gujarat', '01-02-1991', 'id-date-12/10/2017', 'bus-plivo', 'fascal123', 'st12', 'mu34') + .then(function (identityDetails) { + // console.log('identity Create result =>', JSON.stringify(identityDetails)); + done(new Error("Invalid result. Create identity should throw error with invalid data.")) + }) + .catch(function (Erroridentity) { + done(); + // console.log("identity result==>", Erroridentity); + + }) + }); + + it('Create Identity - Valid Fields', function (done) { + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + + var addressProofPath = __dirname + '/api_uploads/address_proof.png'; + client.identities.create("in", "9898997510", 'Mr', "ABC", 'DEF', 'bhagwati heritage 1201', 'sector-21', 'mumbai', 'maharashtra', '410209', 'IN', 'https://www.google.com/', 'Null', addressProofPath, 'passport', '123', 'IN', 'ind-123', 'gujarat', '01-02-1991', 'id-date-12/10/2017', 'bus-plivo', 'fascal123', 'st12', 'mu34') + .then(function (identityDetails) { + // console.log('identity Create result =>', JSON.stringify(identityDetails)); + done(); + }) + .catch(function (Erroridentity) { + done(new Error("Invalid result. Create identity should not throw error with valid data.")) + // console.log("identity result==>", Erroridentity); + + }) + }); + + it('Update Identity with valid fields', function (done) { + + var params = { + identity_id: "", + proof_type: "PASSPORT", + phone_number_country: "in", + number_type: "9898989685", + // salutation: salutation, + // first_name: first_name, + // last_name: last_name, + // address_line1: address_line1, + // address_line2: address_line2, + // city: city, + // region: region, + // postal_code: postal_code, + // country_iso: country_iso, + // callback_url: callback_url, + // alias: alias, + // file: file, + // proof_type: proof_type, + // id_number: id_number, + // nationality: nationality, + // id_nationality: id_nationality, + // birth_place: birth_place, + // birth_date: birth_date, + // id_issue_date: id_issue_date, + // business_name: business_name, + // fiscal_identification_code: fiscal_identification_code, + // street_code: street_code, + // municipal_code: municipal_code + }; + + + client.identities.update(params).then(function (updateResult) { + // console.log('identity update result =>', JSON.stringify(updateResult)); + done(); + }).catch(function (err) { + done(err); + }); + + }); + + it('Update Identity Without id', function (done) { + + var params = { + proof_type: "PASSPORT", + phone_number_country: "in", + number_type: "9898989685", + // salutation: salutation, + // first_name: first_name, + // last_name: last_name, + // address_line1: address_line1, + // address_line2: address_line2, + // city: city, + // region: region, + // postal_code: postal_code, + // country_iso: country_iso, + // callback_url: callback_url, + // alias: alias, + // file: file, + // proof_type: proof_type, + // id_number: id_number, + // nationality: nationality, + // id_nationality: id_nationality, + // birth_place: birth_place, + // birth_date: birth_date, + // id_issue_date: id_issue_date, + // business_name: business_name, + // fiscal_identification_code: fiscal_identification_code, + // street_code: street_code, + // municipal_code: municipal_code + }; + + client.identities.update(params).then(function (updateResult) { + // console.log('identity update result =>', JSON.stringify(updateResult)); + done(new Error("Invalid result. Update identity should throw error if identity_id not provided.")) + }).catch(function (err) { + done(); + }); + + }); + + + // // Delete identity + it('Delete Identity', function (done) { + client.identities.delete(18294047791076).then(function (deleteResult) { + // console.log('identity delete result =>', JSON.stringify(deleteResult)); + done(); + }).catch(function (err) { + done(err); + }); + }); + + +}); +