Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
♻️ Update to latest config branch
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Jul 18, 2018
1 parent cfd55ec commit abc9bdf
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 88 deletions.
63 changes: 33 additions & 30 deletions test/commands/account/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import { expect, test } from '../../test';
import { expect, test } from '@oclif/test';
import * as config from '../../../src/utils/config';
import * as print from '../../../src/utils/print';
import cryptography from '../../../src/utils/cryptography';
Expand All @@ -31,34 +31,37 @@ describe('account:create', () => {
'whale acoustic sword work scene frame assume ensure hawk federal upgrade angry';

const printMethodStub = sandbox.stub();
const setupStub = test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({}))
.stub(cryptography, 'getKeys', sandbox.stub().returns(defaultKeys))
.stub(
cryptography,
'getAddressFromPublicKey',
sandbox.stub().returns(defaultAddress),
)
.stub(
mnemonic,
'createMnemonicPassphrase',
sandbox.stub().returns(defaultMnemonic),
);

setupStub
.stdout()
.command(['account:create'])
.it('should create account', () => {
expect(print.default).to.be.called;
expect(cryptography.getKeys).to.be.calledWithExactly(defaultMnemonic);
expect(cryptography.getAddressFromPublicKey).to.be.calledWithExactly(
defaultKeys.publicKey,
);
return expect(printMethodStub).to.be.calledWith(
Object.assign({}, defaultKeys, defaultAddress, {
passphrase: defaultMnemonic,
}),
const setupStub = () =>
test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({}))
.stub(cryptography, 'getKeys', sandbox.stub().returns(defaultKeys))
.stub(
cryptography,
'getAddressFromPublicKey',
sandbox.stub().returns(defaultAddress),
)
.stub(
mnemonic,
'createMnemonicPassphrase',
sandbox.stub().returns(defaultMnemonic),
);
});

describe('account:create', () => {
setupStub()
.stdout()
.command(['account:create'])
.it('should create account', () => {
expect(print.default).to.be.called;
expect(cryptography.getKeys).to.be.calledWithExactly(defaultMnemonic);
expect(cryptography.getAddressFromPublicKey).to.be.calledWithExactly(
defaultKeys.publicKey,
);
return expect(printMethodStub).to.be.calledWith(
Object.assign({}, defaultKeys, defaultAddress, {
passphrase: defaultMnemonic,
}),
);
});
});
});
35 changes: 20 additions & 15 deletions test/commands/account/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,35 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import { test } from '../../test';
import { expect, test } from '@oclif/test';
import * as config from '../../../src/utils/config';
import * as print from '../../../src/utils/print';
import * as api from '../../../src/utils/api';
import * as query from '../../../src/utils/query';

describe('account:get', () => {
describe('account:get command', () => {
const endpoint = 'accounts';
const apiConfig = {
nodes: ['http://local.host'],
network: 'main',
};
const printMethodStub = sandbox.stub();
const apiClientStub = sandbox.stub();
const setupStub = test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({ api: apiConfig }))
.stub(api, 'default', sandbox.stub().returns(apiClientStub));
const setupStub = () =>
test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({ api: apiConfig }))
.stub(api, 'default', sandbox.stub().returns(apiClientStub));

setupStub
.stdout()
.command(['account:get'])
.catch(error => expect(error.message).to.contain('Missing 1 required arg'))
.it('should throw an error when arg is not provided');
describe('account:get', () => {
setupStub()
.stdout()
.command(['account:get'])
.catch(error =>
expect(error.message).to.contain('Missing 1 required arg'),
)
.it('should throw an error when arg is not provided');
});

describe('account:get account', () => {
const account = '3520445367460290306L';
Expand All @@ -45,9 +50,9 @@ describe('account:get', () => {
name: 'i am owner',
};

setupStub
.stdout()
setupStub()
.stub(query, 'default', sandbox.stub().resolves(queryResult))
.stdout()
.command(['account:get', account])
.it('should get an account info and display as an object', () => {
expect(api.default).to.be.calledWithExactly(apiConfig);
Expand All @@ -72,9 +77,9 @@ describe('account:get', () => {
},
];

setupStub
.stdout()
setupStub()
.stub(query, 'default', sandbox.stub().resolves(queryResult))
.stdout()
.command(['account:get', accounts.join(',')])
.it('should get accounts info and display as an array', () => {
expect(api.default).to.be.calledWithExactly(apiConfig);
Expand Down
89 changes: 46 additions & 43 deletions test/commands/account/show.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import { expect, test } from '../../test';
import { expect, test } from '@oclif/test';
import * as config from '../../../src/utils/config';
import * as print from '../../../src/utils/print';
import cryptography from '../../../src/utils/cryptography';
Expand All @@ -33,50 +33,53 @@ describe('account:show', () => {
};

const printMethodStub = sandbox.stub();
const setupStub = test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({}))
.stub(cryptography, 'getKeys', sandbox.stub().returns(defaultKeys))
.stub(
cryptography,
'getAddressFromPublicKey',
sandbox.stub().returns(defaultAddress),
)
.stub(
getInputsFromSources,
'default',
sandbox.stub().resolves(passphraseInput),
);
const setupStub = () =>
test
.stub(print, 'default', sandbox.stub().returns(printMethodStub))
.stub(config, 'getConfig', sandbox.stub().returns({}))
.stub(cryptography, 'getKeys', sandbox.stub().returns(defaultKeys))
.stub(
cryptography,
'getAddressFromPublicKey',
sandbox.stub().returns(defaultAddress),
)
.stub(
getInputsFromSources,
'default',
sandbox.stub().resolves(passphraseInput),
);

setupStub
.stdout()
.command(['account:show'])
.it('should show account with prompt', () => {
expect(print.default).to.be.called;
expect(getInputsFromSources.default).to.be.calledWithExactly({
passphrase: {
source: undefined,
repeatPrompt: true,
},
describe('account:show', () => {
setupStub()
.stdout()
.command(['account:show'])
.it('should show account with prompt', () => {
expect(print.default).to.be.called;
expect(getInputsFromSources.default).to.be.calledWithExactly({
passphrase: {
source: undefined,
repeatPrompt: true,
},
});
return expect(printMethodStub).to.be.calledWithExactly(
Object.assign({}, defaultKeys, defaultAddress),
);
});
return expect(printMethodStub).to.be.calledWithExactly(
Object.assign({}, defaultKeys, defaultAddress),
);
});

setupStub
.stdout()
.command(['account:show', '--passphrase=pass:123'])
.it('should show account with pass', () => {
expect(print.default).to.be.called;
expect(getInputsFromSources.default).to.be.calledWithExactly({
passphrase: {
source: 'pass:123',
repeatPrompt: true,
},
setupStub()
.stdout()
.command(['account:show', '--passphrase=pass:123'])
.it('should show account with pass', () => {
expect(print.default).to.be.called;
expect(getInputsFromSources.default).to.be.calledWithExactly({
passphrase: {
source: 'pass:123',
repeatPrompt: true,
},
});
return expect(printMethodStub).to.be.calledWith(
Object.assign({}, defaultKeys, defaultAddress),
);
});
return expect(printMethodStub).to.be.calledWith(
Object.assign({}, defaultKeys, defaultAddress),
);
});
});
});

0 comments on commit abc9bdf

Please sign in to comment.