diff --git a/lib/util/args.js b/lib/util/args.js index 8408a23..da90eec 100644 --- a/lib/util/args.js +++ b/lib/util/args.js @@ -1 +1 @@ -const merge=require('./misc').merge;module.exports=a=>new Promise((b,c)=>{let d={commands:[],variables:{}},e={},f={},g={};const h=b=>{for(let c of b)for(let b in a.flags)if(c===b||0<=a.flags[b].indexOf(c)){d[b]=!0;break}};let j=process.argv.slice(2);for(let f=0;fi.push(a)),process.stdin.once('end',()=>{let a=i.join('').trim();if(0new Promise((b,c)=>{let d={commands:[],variables:{}},e={},f={},g={};const h=b=>{for(let c of b)for(let b in a.flags)if(c===b||0<=a.flags[b].indexOf(c)){d[b]=!0;break}};let j=process.argv.slice(2);for(let f=0;fi.push(a)),process.stdin.once('end',()=>{let a=i.join('').trim();if(0 { if (variable) { let value = (args.length) ? args.join('=') : rawArgs[++i] if (opts.variables[key]) { - variables[key] = (variables[key] || []).concat(value.split(',')) + variables[key] = (variables[key] || []).concat((value || '').split(',')) } else { variables[key] = value } diff --git a/test/commands/app.js b/test/commands/app.js index e3af2e0..11f7c79 100644 --- a/test/commands/app.js +++ b/test/commands/app.js @@ -22,7 +22,7 @@ describe('app', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') }) }) @@ -31,7 +31,7 @@ describe('app', () => { return Promise.resolve() .then(command) .then((app) => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } }) }) }) @@ -49,6 +49,6 @@ describe('app', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.app).toBeCalled()) + .then(() => expect(complete.app).toHaveBeenCalled()) ) }) diff --git a/test/commands/build.js b/test/commands/build.js index d08fbc3..37e4302 100644 --- a/test/commands/build.js +++ b/test/commands/build.js @@ -22,7 +22,7 @@ describe('build', () => { return Promise.resolve() .then(command) .then(() => { - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.args).toHaveBeenLastCalledWith(1) expect(validators.platform).toHaveBeenCalledTimes(2) expect(validators.id).toHaveBeenLastCalledWith('12') @@ -33,9 +33,9 @@ describe('build', () => { return Promise.resolve() .then(command) .then((cmd) => { - expect(pgb.api.buildApp).toBeCalledWith('12', ['']) - expect(wait).toBeCalledWith({ id: 12 }) - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) + expect(pgb.api.buildApp).toHaveBeenCalledWith('12', ['']) + expect(wait).toHaveBeenCalledWith({ id: 12 }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) }) }) @@ -44,9 +44,9 @@ describe('build', () => { return Promise.resolve() .then(command) .then((cmd) => { - expect(pgb.api.buildApp).toBeCalledWith('12', ['ios']) - expect(wait).toBeCalledWith({ id: 12 }) - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) + expect(pgb.api.buildApp).toHaveBeenCalledWith('12', ['ios']) + expect(wait).toHaveBeenCalledWith({ id: 12 }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) }) }) @@ -55,9 +55,9 @@ describe('build', () => { return Promise.resolve() .then(command) .then((cmd) => { - expect(pgb.api.buildApp).toBeCalledWith('12', ['ios', 'winphone', 'android']) - expect(wait).toBeCalledWith({ id: 12 }) - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) + expect(pgb.api.buildApp).toHaveBeenCalledWith('12', ['ios', 'winphone', 'android']) + expect(wait).toHaveBeenCalledWith({ id: 12 }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } }) }) }) @@ -75,6 +75,6 @@ describe('build', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.appAndPlatform).toBeCalled()) + .then(() => expect(complete.appAndPlatform).toHaveBeenCalled()) ) }) diff --git a/test/commands/completion.js b/test/commands/completion.js index 61915db..c59a3bc 100644 --- a/test/commands/completion.js +++ b/test/commands/completion.js @@ -65,7 +65,7 @@ describe('build', () => { .then(command) .then(() => { expect(console.log).not.toHaveBeenCalledWith('') - expect(pgb.debug).toBeCalledWith(new Error('an error')) + expect(pgb.debug).toHaveBeenCalledWith(new Error('an error')) }) }) diff --git a/test/commands/download.js b/test/commands/download.js index 0f67f03..9a228ed 100644 --- a/test/commands/download.js +++ b/test/commands/download.js @@ -21,7 +21,7 @@ describe('download', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.platform).toHaveBeenLastCalledWith('ios', true) }) }) @@ -30,7 +30,7 @@ describe('download', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '.') + expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '.') }) }) @@ -39,7 +39,7 @@ describe('download', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '/foo') + expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '/foo') }) }) @@ -53,14 +53,14 @@ describe('download', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).not.toBeCalled() + expect(pgb.print).not.toHaveBeenCalled() let call = pgb.api.downloadApp.mock.calls[0] expect(call[0]).toBe('12') expect(call[1]).toBe('ios') expect(call[2]).toBeInstanceOf(require('stream').Writable) expect(call[2]).toMatchObject({ _isStdio: true }) - expect(Progress).not.toBeCalledWith('downloading ', 100, 60) - expect(pgb.print).not.toBeCalled() + expect(Progress).not.toHaveBeenCalledWith('downloading ', 100, 60) + expect(pgb.print).not.toHaveBeenCalled() }) }) @@ -74,10 +74,10 @@ describe('download', () => { return Promise.resolve() .then(command) .then(() => { - expect(Progress.mock.instances[0].update).toBeCalledWith(100, '100 B / 100 B') - expect(Progress.mock.instances[0].stop).toBeCalledWith() - expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '.') - expect(Progress).toBeCalledWith('downloading ', 100, 40) + expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(100, '100 B / 100 B') + expect(Progress.mock.instances[0].stop).toHaveBeenCalledWith() + expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '.') + expect(Progress).toHaveBeenCalledWith('downloading ', 100, 40) }) }) @@ -90,7 +90,7 @@ describe('download', () => { .then(command) .then(done.fail) .catch(() => { - expect(Progress).not.toBeCalledWith() + expect(Progress).not.toHaveBeenCalledWith() done() }) }) @@ -107,6 +107,6 @@ describe('download', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.appAndPlatform).toBeCalled()) + .then(() => expect(complete.appAndPlatform).toHaveBeenCalled()) ) }) diff --git a/test/commands/helpers/bind-progress.js b/test/commands/helpers/bind-progress.js index 2c668f3..04a419e 100644 --- a/test/commands/helpers/bind-progress.js +++ b/test/commands/helpers/bind-progress.js @@ -34,7 +34,7 @@ describe('bind-progress', () => { test('should debug files on zip/files event', () => { process.emit('zip/files', { foo: 'bar' }) - expect(pgb.debug).toBeCalledWith({ foo: 'bar' }) + expect(pgb.debug).toHaveBeenCalledWith({ foo: 'bar' }) }) test('should stop progress on end events', () => { @@ -42,39 +42,39 @@ describe('bind-progress', () => { process.emit('zip/write', { size: 2000000, pos: 25 }) process.emit('api/connect') process.emit('zip/end') - expect(Progress.mock.instances[0].stop).toBeCalledWith() - expect(Progress.mock.instances[1].stop).toBeCalledWith() + expect(Progress.mock.instances[0].stop).toHaveBeenCalledWith() + expect(Progress.mock.instances[1].stop).toHaveBeenCalledWith() }) test('should instantiate and/or update progress on api/write', () => { process.emit('api/write', { size: 2000000, pos: 25 }) process.emit('api/write', { size: 2000000, pos: 25 }) - expect(Progress).toBeCalledWith('uploading ', 2000000, 40) - expect(Progress.mock.instances[0].update).toBeCalledWith(25, '25 B / 1.9 MB') + expect(Progress).toHaveBeenCalledWith('uploading ', 2000000, 40) + expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(25, '25 B / 1.9 MB') }) test('should not instantiate and/or update progress on api/write if too small', () => { process.emit('api/write', { size: 100, pos: 25 }) - expect(Progress).not.toBeCalledWith() + expect(Progress).not.toHaveBeenCalledWith() }) test('should instantiate and/or update progress on api/write if too small but has zipper', () => { process.emit('zip/write', { size: 2000000, pos: 25 }) - expect(Progress.mock.instances[0].update).toBeCalledWith(25, '25 B / 1.9 MB') + expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(25, '25 B / 1.9 MB') process.emit('api/write', { size: 100, pos: 22 }) - expect(Progress.mock.instances[1].update).toBeCalledWith(22, '22 B / 100 B') + expect(Progress.mock.instances[1].update).toHaveBeenCalledWith(22, '22 B / 100 B') }) test('should not instantiate and/or update progress on api/write if noprogress', () => { pgb.opts.noprogress = true process.emit('api/write', { size: 2000000, pos: 25 }) - expect(Progress).not.toBeCalledWith() + expect(Progress).not.toHaveBeenCalledWith() }) test('should instantiate and/or update progress on zip/write', () => { process.emit('zip/write', { size: 200000, pos: 25 }) process.emit('zip/write', { size: 200000, pos: 25 }) - expect(Progress).toBeCalledWith('archiving ', 200000, 40) + expect(Progress).toHaveBeenCalledWith('archiving ', 200000, 40) }) test('should not bind events if noprogress', () => { @@ -84,6 +84,6 @@ describe('bind-progress', () => { bindProgress = BindProgress() process.emit('zip/write', { size: 2000000, pos: 25 }) expect(process.eventNames()).not.toContain(['zip/files', 'zip/end', 'api/connect', 'zip/write', 'api/write']) - expect(Progress).not.toBeCalled() + expect(Progress).not.toHaveBeenCalled() }) }) diff --git a/test/commands/helpers/complete.js b/test/commands/helpers/complete.js index d41063f..7294c39 100644 --- a/test/commands/helpers/complete.js +++ b/test/commands/helpers/complete.js @@ -15,7 +15,7 @@ describe('complete', () => { .then(complete.app) .then((result) => { expect(result).toEqual([12, 13]) - expect(pgb.api.getApps).toBeCalledWith() + expect(pgb.api.getApps).toHaveBeenCalledWith() }) }) @@ -36,7 +36,7 @@ describe('complete', () => { .then(complete.appAndPlatform) .then((result) => { expect(result).toEqual([12, 13]) - expect(pgb.api.getApps).toBeCalledWith() + expect(pgb.api.getApps).toHaveBeenCalledWith() }) }) @@ -67,7 +67,7 @@ describe('complete', () => { .then(complete.key) .then((result) => { expect(result).toEqual([12, 13]) - expect(pgb.api.getKeys).toBeCalledWith('ios') + expect(pgb.api.getKeys).toHaveBeenCalledWith('ios') }) }) diff --git a/test/commands/helpers/validators.js b/test/commands/helpers/validators.js index 05a4b26..03b493e 100644 --- a/test/commands/helpers/validators.js +++ b/test/commands/helpers/validators.js @@ -47,7 +47,7 @@ describe('validators', () => { jest.mock('../../../src/commands/usage') expect(pgb.opts.short_usage).toBeFalsy() expect(() => validators.args(1)).toThrow('') - expect(pgb.error).lastCalledWith('command requires 1 argument(s)') + expect(pgb.error).toHaveBeenLastCalledWith('command requires 1 argument(s)') expect(pgb.opts.short_usage).toBeTruthy() pgb.opts = { commands: ['cmd', 'arg1'] } expect(() => validators.args(1)).not.toThrow() diff --git a/test/commands/helpers/wait.js b/test/commands/helpers/wait.js index f21e686..4928253 100644 --- a/test/commands/helpers/wait.js +++ b/test/commands/helpers/wait.js @@ -23,8 +23,8 @@ describe('progress', () => { return wait({ id: 12, package: 'com.example', status: {}, error: {}, completed: true }) .then((app) => { expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: {}, completed: true }) - expect(pgb.api.getApp).not.toBeCalled() - expect(pgb.api.getStatus).not.toBeCalled() + expect(pgb.api.getApp).not.toHaveBeenCalled() + expect(pgb.api.getStatus).not.toHaveBeenCalled() }) }) @@ -33,8 +33,8 @@ describe('progress', () => { return wait({ id: 12, package: 'com.example', status: {}, error: {}, completed: true }) .then((app) => { expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: {}, completed: true }) - expect(pgb.api.getApp).not.toBeCalled() - expect(pgb.api.getStatus).not.toBeCalled() + expect(pgb.api.getApp).not.toHaveBeenCalled() + expect(pgb.api.getStatus).not.toHaveBeenCalled() }) }) @@ -44,8 +44,8 @@ describe('progress', () => { .then(done.fail) .catch((err) => { expect(err).toEqual(new Error()) - expect(pgb.api.getApp).not.toBeCalled() - expect(pgb.api.getStatus).not.toBeCalled() + expect(pgb.api.getApp).not.toHaveBeenCalled() + expect(pgb.api.getStatus).not.toHaveBeenCalled() done() }) }) @@ -55,8 +55,8 @@ describe('progress', () => { return wait({ id: 12, package: 'com.example', status: {}, error: { }, completed: true }) .then((app) => { expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: { }, completed: true }) - expect(pgb.api.getApp).not.toBeCalled() - expect(pgb.api.getStatus).not.toBeCalled() + expect(pgb.api.getApp).not.toHaveBeenCalled() + expect(pgb.api.getStatus).not.toHaveBeenCalled() expect(stdout.flush().stderr).toHaveLength(1) }) }) @@ -66,8 +66,8 @@ describe('progress', () => { return wait({ id: 12, package: 'com.example', status: {}, error: { android: 'bad' }, completed: true }) .then((app) => { expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: { android: 'bad' }, completed: true }) - expect(pgb.api.getApp).not.toBeCalled() - expect(pgb.api.getStatus).not.toBeCalled() + expect(pgb.api.getApp).not.toHaveBeenCalled() + expect(pgb.api.getStatus).not.toHaveBeenCalled() expect(stdout.flush().stderr).toHaveLength(1) }) }) diff --git a/test/commands/key.js b/test/commands/key.js index e04f255..bc5f670 100644 --- a/test/commands/key.js +++ b/test/commands/key.js @@ -18,7 +18,7 @@ describe('key', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true) expect(validators.id).toHaveBeenLastCalledWith('12') }) @@ -28,8 +28,8 @@ describe('key', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } }) - expect(pgb.api.getKey).toBeCalledWith('ios', '12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } }) + expect(pgb.api.getKey).toHaveBeenCalledWith('ios', '12') }) }) @@ -47,6 +47,6 @@ describe('key', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.key).toBeCalledWith(true)) + .then(() => expect(complete.key).toHaveBeenCalledWith(true)) ) }) diff --git a/test/commands/keys.js b/test/commands/keys.js index 346eb78..dacc42e 100644 --- a/test/commands/keys.js +++ b/test/commands/keys.js @@ -30,7 +30,7 @@ describe('keys', () => { return Promise.resolve() .then(command) .then(() => { - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.key_platform).toHaveBeenLastCalledWith(undefined, false) }) }) @@ -83,6 +83,6 @@ describe('keys', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.platform).toBeCalledWith(true)) + .then(() => expect(complete.platform).toHaveBeenCalledWith(true)) ) }) diff --git a/test/commands/lock.js b/test/commands/lock.js index f05bad8..d830828 100644 --- a/test/commands/lock.js +++ b/test/commands/lock.js @@ -18,7 +18,7 @@ describe('key', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true) expect(validators.id).toHaveBeenLastCalledWith('12') }) @@ -28,8 +28,8 @@ describe('key', () => { return Promise.resolve() .then(command) .then((key) => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 locked' }) - expect(pgb.api.lockKey).toBeCalledWith('ios', '12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 locked' }) + expect(pgb.api.lockKey).toHaveBeenCalledWith('ios', '12') }) }) @@ -47,6 +47,6 @@ describe('key', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.key).toBeCalledWith()) + .then(() => expect(complete.key).toHaveBeenCalledWith()) ) }) diff --git a/test/commands/log.js b/test/commands/log.js index 36fe362..713073f 100644 --- a/test/commands/log.js +++ b/test/commands/log.js @@ -18,7 +18,7 @@ describe('log', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.platform).toHaveBeenLastCalledWith('ios', true) expect(validators.id).toHaveBeenLastCalledWith('12') }) @@ -28,8 +28,8 @@ describe('log', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith('full log', { id: 12, log: 'full log' }) - expect(pgb.api.getAppLog).toBeCalledWith('12', 'ios') + expect(pgb.print).toHaveBeenCalledWith('full log', { id: 12, log: 'full log' }) + expect(pgb.api.getAppLog).toHaveBeenCalledWith('12', 'ios') }) }) @@ -45,6 +45,6 @@ describe('log', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.appAndPlatform).toBeCalled()) + .then(() => expect(complete.appAndPlatform).toHaveBeenCalled()) ) }) diff --git a/test/commands/login.js b/test/commands/login.js index 09be9dc..18e9a62 100644 --- a/test/commands/login.js +++ b/test/commands/login.js @@ -26,9 +26,9 @@ describe('login', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) - expect(pgb.api.me).toBeCalled() - expect(prompt).not.toBeCalled() + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) + expect(pgb.api.me).toHaveBeenCalled() + expect(prompt).not.toHaveBeenCalled() }) }) @@ -39,8 +39,8 @@ describe('login', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) - expect(pgb.api.getToken).toBeCalledWith('user@example.com', 'password') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) + expect(pgb.api.getToken).toHaveBeenCalledWith('user@example.com', 'password') expect(pgb.api.me).toHaveBeenCalledTimes(2) expect(prompt).toHaveBeenCalledTimes(2) }) @@ -54,8 +54,8 @@ describe('login', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) - expect(pgb.api.getToken).not.toBeCalled() + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) + expect(pgb.api.getToken).not.toHaveBeenCalled() expect(pgb.api.me).toHaveBeenCalledTimes(2) expect(prompt).toHaveBeenCalledTimes(1) }) @@ -69,8 +69,8 @@ describe('login', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) - expect(pgb.api.getToken).not.toBeCalled() + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) + expect(pgb.api.getToken).not.toHaveBeenCalled() expect(pgb.api.me).toHaveBeenCalledTimes(2) expect(prompt).not.toHaveBeenCalled() }) @@ -84,8 +84,8 @@ describe('login', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) - expect(pgb.api.getToken).not.toBeCalled() + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'email': 'user@example.com', 'id': 12 }, 'pretty': 'signed in as user@example.com' }) + expect(pgb.api.getToken).not.toHaveBeenCalled() expect(pgb.api.me).toHaveBeenCalledTimes(2) expect(prompt).not.toHaveBeenCalled() }) diff --git a/test/commands/ls.js b/test/commands/ls.js index 157a288..2c0e9a8 100644 --- a/test/commands/ls.js +++ b/test/commands/ls.js @@ -23,7 +23,7 @@ describe('ls', () => { return Promise.resolve() .then(command) .then(() => { - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() }) }) diff --git a/test/commands/new-key.js b/test/commands/new-key.js index 744669d..6534c82 100644 --- a/test/commands/new-key.js +++ b/test/commands/new-key.js @@ -25,7 +25,7 @@ describe('new', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.variables).toHaveBeenLastCalledWith('title', 'key', 'profile') }) }) @@ -37,7 +37,7 @@ describe('new', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.variables).toHaveBeenLastCalledWith('title', 'alias', 'key') }) }) @@ -49,7 +49,7 @@ describe('new', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.variables).toHaveBeenLastCalledWith('title', 'key') }) }) @@ -61,7 +61,7 @@ describe('new', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.variables).toHaveBeenLastCalledWith('title', 'publisher_id') }) }) @@ -83,7 +83,7 @@ describe('new', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 added' }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 added' }) let call = pgb.api.addKey.mock.calls[0] expect(call[0]).toBe('ios') expect(call[1]).toMatchObject({ cert: { path: '/foo' }, profile: { path: '/bar' }, data: { title: 'a title' } }) @@ -102,6 +102,6 @@ describe('new', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.platform).toBeCalledWith(true)) + .then(() => expect(complete.platform).toHaveBeenCalledWith(true)) ) }) diff --git a/test/commands/new.js b/test/commands/new.js index 1d3a2a9..caec9b6 100644 --- a/test/commands/new.js +++ b/test/commands/new.js @@ -28,7 +28,7 @@ describe('new', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() }) }) @@ -36,9 +36,9 @@ describe('new', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith('app 12 added') - expect(pgb.api.addApp).toBeCalledWith('org/repo', { 'hydrates': true, 'keys': {}, ignore: [] }) - expect(BindTransfer).toBeCalled() + expect(pgb.print).toHaveBeenCalledWith('app 12 added') + expect(pgb.api.addApp).toHaveBeenCalledWith('org/repo', { 'hydrates': true, 'keys': {}, ignore: [] }) + expect(BindTransfer).toHaveBeenCalled() }) }) @@ -47,7 +47,7 @@ describe('new', () => { return Promise.resolve() .then(command) .catch((err) => { - expect(stop).toBeCalled() + expect(stop).toHaveBeenCalled() expect(err).toMatchObject(new Error('an error')) }) }) diff --git a/test/commands/pull.js b/test/commands/pull.js index e93db91..997f595 100644 --- a/test/commands/pull.js +++ b/test/commands/pull.js @@ -41,6 +41,6 @@ describe('pull', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.app).toBeCalled()) + .then(() => expect(complete.app).toHaveBeenCalled()) ) }) diff --git a/test/commands/rm-key.js b/test/commands/rm-key.js index 856a323..283904e 100644 --- a/test/commands/rm-key.js +++ b/test/commands/rm-key.js @@ -22,7 +22,7 @@ describe('rm', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true) }) @@ -33,8 +33,8 @@ describe('rm', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': '12', 'pretty': 'ios key 12 deleted' }) - expect(pgb.api.deleteKey).toBeCalledWith('ios', '12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': '12', 'pretty': 'ios key 12 deleted' }) + expect(pgb.api.deleteKey).toHaveBeenCalledWith('ios', '12') expect(prompt).not.toHaveBeenCalled() }) }) @@ -43,8 +43,8 @@ describe('rm', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': '12', 'pretty': 'ios key 12 deleted' }) - expect(pgb.api.deleteKey).toBeCalledWith('ios', '12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': '12', 'pretty': 'ios key 12 deleted' }) + expect(pgb.api.deleteKey).toHaveBeenCalledWith('ios', '12') expect(prompt).toHaveBeenCalledWith('are you sure? [yN] ', { confirm: true }) }) }) @@ -55,8 +55,8 @@ describe('rm', () => { .then(command) .then(done.fail) .catch(() => { - expect(pgb.print).not.toBeCalled() - expect(pgb.api.deleteKey).not.toBeCalled() + expect(pgb.print).not.toHaveBeenCalled() + expect(pgb.api.deleteKey).not.toHaveBeenCalled() expect(prompt).toHaveBeenCalledWith('are you sure? [yN] ', { confirm: true }) done() }) @@ -74,6 +74,6 @@ describe('rm', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.key).toBeCalledWith(true)) + .then(() => expect(complete.key).toHaveBeenCalledWith(true)) ) }) diff --git a/test/commands/rm.js b/test/commands/rm.js index 1bb8b03..87971fc 100644 --- a/test/commands/rm.js +++ b/test/commands/rm.js @@ -22,7 +22,7 @@ describe('rm', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') }) }) @@ -32,8 +32,8 @@ describe('rm', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': '12', 'pretty': 'app 12 deleted' }) - expect(pgb.api.deleteApp).toBeCalledWith('12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': '12', 'pretty': 'app 12 deleted' }) + expect(pgb.api.deleteApp).toHaveBeenCalledWith('12') expect(prompt).not.toHaveBeenCalled() }) }) @@ -42,8 +42,8 @@ describe('rm', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': '12', 'pretty': 'app 12 deleted' }) - expect(pgb.api.deleteApp).toBeCalledWith('12') + expect(pgb.print).toHaveBeenCalledWith({ 'bare': '12', 'pretty': 'app 12 deleted' }) + expect(pgb.api.deleteApp).toHaveBeenCalledWith('12') expect(prompt).toHaveBeenCalledWith('are you sure? [yN] ', { confirm: true }) }) }) @@ -54,8 +54,8 @@ describe('rm', () => { .then(command) .then(done.fail) .catch(() => { - expect(pgb.print).not.toBeCalled() - expect(pgb.api.deleteApp).not.toBeCalled() + expect(pgb.print).not.toHaveBeenCalled() + expect(pgb.api.deleteApp).not.toHaveBeenCalled() expect(prompt).toHaveBeenCalledWith('are you sure? [yN] ', { confirm: true }) done() }) @@ -73,6 +73,6 @@ describe('rm', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.app).toBeCalled()) + .then(() => expect(complete.app).toHaveBeenCalled()) ) }) diff --git a/test/commands/unlock.js b/test/commands/unlock.js index b9313cd..d1817ea 100644 --- a/test/commands/unlock.js +++ b/test/commands/unlock.js @@ -22,7 +22,7 @@ describe('unlock', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true) }) @@ -32,8 +32,8 @@ describe('unlock', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 unlocked' }) - expect(pgb.api.updateKey).toBeCalledWith('ios', '12', { data: { password: 'password' } }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 unlocked' }) + expect(pgb.api.updateKey).toHaveBeenCalledWith('ios', '12', { data: { password: 'password' } }) expect(prompt).toHaveBeenCalledWith('Key Password: ', { 'mask': true }) }) }) @@ -61,6 +61,6 @@ describe('unlock', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.key).toBeCalledWith()) + .then(() => expect(complete.key).toHaveBeenCalledWith()) ) }) diff --git a/test/commands/update-key.js b/test/commands/update-key.js index a6efd9a..4e84e69 100644 --- a/test/commands/update-key.js +++ b/test/commands/update-key.js @@ -19,7 +19,7 @@ describe('update', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(2) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true) }) @@ -30,8 +30,8 @@ describe('update', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 updated' }) - expect(pgb.api.updateKey).toBeCalledWith('ios', '12', { 'title': 'a title' }) + expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': 'ios key 12 updated' }) + expect(pgb.api.updateKey).toHaveBeenCalledWith('ios', '12', { 'title': 'a title' }) }) }) @@ -47,6 +47,6 @@ describe('update', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.key).toBeCalledWith(true)) + .then(() => expect(complete.key).toHaveBeenCalledWith(true)) ) }) diff --git a/test/commands/update.js b/test/commands/update.js index 2b414cf..f150f41 100644 --- a/test/commands/update.js +++ b/test/commands/update.js @@ -28,7 +28,7 @@ describe('update', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() expect(validators.id).toHaveBeenLastCalledWith('12') }) }) @@ -38,9 +38,9 @@ describe('update', () => { return Promise.resolve() .then(command) .then(() => { - expect(pgb.print).toBeCalledWith('app 12 updated') - expect(pgb.api.updateApp).toBeCalledWith('12', 'org/repo', { 'hydrates': true, 'keys': {}, ignore: [] }) - expect(BindTransfer).toBeCalled() + expect(pgb.print).toHaveBeenCalledWith('app 12 updated') + expect(pgb.api.updateApp).toHaveBeenCalledWith('12', 'org/repo', { 'hydrates': true, 'keys': {}, ignore: [] }) + expect(BindTransfer).toHaveBeenCalled() }) }) @@ -49,7 +49,7 @@ describe('update', () => { return Promise.resolve() .then(command) .catch((err) => { - expect(stop).toBeCalled() + expect(stop).toHaveBeenCalled() expect(err).toMatchObject(new Error('an error')) }) }) @@ -57,6 +57,6 @@ describe('update', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.app).toBeCalled()) + .then(() => expect(complete.app).toHaveBeenCalled()) ) }) diff --git a/test/commands/wait.js b/test/commands/wait.js index e9da1de..55ccf01 100644 --- a/test/commands/wait.js +++ b/test/commands/wait.js @@ -24,7 +24,7 @@ describe('wait', () => { .then(command) .then(() => { expect(validators.args).toHaveBeenLastCalledWith(1) - expect(validators.signed_in).toBeCalled() + expect(validators.signed_in).toHaveBeenCalled() }) }) @@ -32,7 +32,7 @@ describe('wait', () => { return Promise.resolve() .then(command) .then(() => { - expect(wait).toBeCalledWith({ id: 12 }) + expect(wait).toHaveBeenCalledWith({ id: 12 }) }) }) @@ -48,6 +48,6 @@ describe('wait', () => { test('should support completion', () => Promise.resolve() .then(command.completion) - .then(() => expect(complete.app).toBeCalled()) + .then(() => expect(complete.app).toHaveBeenCalled()) ) }) diff --git a/test/index.js b/test/index.js index 6a5b7b9..dd628d0 100644 --- a/test/index.js +++ b/test/index.js @@ -44,7 +44,7 @@ describe('index', () => { return pgb.run().then(() => { expect(parseArgs).toHaveBeenLastCalledWith(pgb.cliOpts) expect(pgb.runCommand).toHaveBeenLastCalledWith({ variables: {}, commands: [ 'command' ] }) - expect(pgb.handleError).not.toBeCalled() + expect(pgb.handleError).not.toHaveBeenCalled() }) }) @@ -296,7 +296,7 @@ describe('index', () => { pgb.opts.json = false pgb.opts.bare = false pgb.print({}) - expect(console.log).not.toBeCalled() + expect(console.log).not.toHaveBeenCalled() }) test('should print bare', () => { diff --git a/test/util/args.js b/test/util/args.js index 6abe7a2..0278adf 100644 --- a/test/util/args.js +++ b/test/util/args.js @@ -115,6 +115,22 @@ describe('args', () => { }) }) + test('should handle a dangling multiple variable without error', () => { + let opts = { flags: { }, aliases: {}, variables: { var1: true } } + argv('foo --var1') + return parseArgs(opts).then((result) => { + expect(result).toEqual({ commands: [ 'foo' ], variables: { var1: [''] } }) + }) + }) + + test('should handle a dangling variable without error', () => { + let opts = { flags: { }, aliases: {}, variables: { var1: false } } + argv('foo --var1') + return parseArgs(opts).then((result) => { + expect(result).toEqual({ commands: [ 'foo' ], variables: { var1: undefined } }) + }) + }) + test('should parse variables and use arrays for duplicate variables', () => { let opts = { flags: { }, aliases: {}, variables: { var2: true, var4: true } } argv('foo var1=abc --var2=bar=12 --var3=12 --var2=bar=24 --var3=24 --var4=1,2,3')