diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml new file mode 100644 index 0000000..4ce6018 --- /dev/null +++ b/.github/workflows/unitTests.yml @@ -0,0 +1,26 @@ +name: UnitTests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [4.x, 5.x, 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 \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 36f37db..d67521b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -41,7 +41,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,13 +57,13 @@ 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 () { +gulp.task('coveralls', gulp.series('test', function () { if (!process.env.CI) { console.log('ignoring coveralls report generation.'); return; @@ -71,9 +71,13 @@ gulp.task('coveralls', ['test'], function () { 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 +85,7 @@ gulp.task('babel', ['clean'], function () { .pipe(babel()) .pipe(gulp.dest('dist')) ]); -}); +})); gulp.task('lintFix', function () { return gulp.src('lib/**/*.js') @@ -96,5 +100,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', 'coveralls')); diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index 848c901..eb77ed7 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -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)) { diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index 012a817..43a1a13 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -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//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//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: {}, diff --git a/package.json b/package.json index e0851d5..88b41de 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "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", diff --git a/test/accounts.js b/test/accounts.js index cb9dbee..ebf3e7a 100644 --- a/test/accounts.js +++ b/test/accounts.js @@ -9,8 +9,8 @@ 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') }) }); diff --git a/test/calls.js b/test/calls.js index 4e623a6..064987d 100644 --- a/test/calls.js +++ b/test/calls.js @@ -59,7 +59,7 @@ describe('calls', function () { it('should get call by id!', function (done) { client.calls.get(1) .then(function(call){ - assert.equal(call.id, 1) + assert.equal(call.callUuid, 'aaa-deeiei3-dfddd') done() }) }); diff --git a/test/media.js b/test/media.js index bc33ad2..65d1567 100644 --- a/test/media.js +++ b/test/media.js @@ -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) + return client.media.get('0178eb8a-461a-4fd1-bc37-13eebfdc0676') .then(function (media) { - assert.equal(media.media_id, 1) + assert.equal(res.mediaId, '0178eb8a-461a-4fd1-bc37-13eebfdc0676') }) }); }); diff --git a/test/messages.js b/test/messages.js index 7a43d98..4071ec7 100644 --- a/test/messages.js +++ b/test/messages.js @@ -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) }) }); @@ -60,16 +60,6 @@ describe('message', function () { }) }); - 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) { diff --git a/test/powerpacks.js b/test/powerpacks.js index a7cc897..e4ea231 100644 --- a/test/powerpacks.js +++ b/test/powerpacks.js @@ -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(res.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") }) }); @@ -75,13 +65,13 @@ describe('PowerpackInterface', function () { return powerpack.find_shortcode('4444444') }) .then(function (result) { - assert.Equal(result.shortcode, "4444444") + assert.equal(result.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 +92,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 +101,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 +110,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 +120,7 @@ describe('PowerpackInterface', function () { return powerpack.remove_shortcode("444444") }) .then(function (result) { - assert.notEqual(result.response, "success") + assert.equal(result.response, "success") }) });