Skip to content
This repository has been archived by the owner on Jan 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'autoComplete' of https://github.com/HAECHI-LABS/henesis…
Browse files Browse the repository at this point in the history
…-cli into autoComplete
  • Loading branch information
HaruHuey authored and Wonyoung Chae committed Sep 27, 2019
2 parents b7386ce + bbe0fad commit dd958fb
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 47 deletions.
83 changes: 71 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ USAGE
$ henesis [COMMAND]
COMMANDS
changepw change password
account manage your account
help display help for henesis
init create the folder structure required for your project
integration manage integrations
login perform a login
logout perform a logout
node get node status
```


Expand All @@ -35,6 +36,8 @@ COMMANDS
$ henesis autocomplete
```

Enter the following script according to your shell type.

zsh:
> $ printf "$(henesis autocomplete:script zsh)" >> ~/.zshrc; source ~/.zshrc
Expand Down Expand Up @@ -83,6 +86,56 @@ password: ***********



### logout

```
$ henesis logout
🤗 Logout Success 👍
```



### account

*_**You must be logged in to use this features.**_*

```
manage your account
USAGE
$ henesis account:COMMAND
COMMANDS
account:changepw change account password
account:describe describe account information
```

#### account:changepw

##### Command Line

```
$ henesis account:changepw
Password: ******
New Password: ******
Again New Password: ******
🦄 Password changed!
```

#### account:describe

##### Command Line

```
$ henesis account:describe
Email: haechi@haechi.io
Name: haechi
Organization: haechi-labs
clientId: 49e77d0be585ef71c337f758e61e1f16
```



### init

*_**The directory in which the init command is run must be empty.**_*
Expand Down Expand Up @@ -166,23 +219,29 @@ henesis integration:describe <integrationId>



### change password

*_**You must be logged in to use this feature.**_*
### node

```
$ henesis changepw
Password: ******
New Password: ******
Again New Password: ******
🦄 Password changed!
get node status
USAGE
$ henesis node:COMMAND
COMMANDS
node:status get node status
```

### logout
#### node:status

##### Command Line

```
$ henesis logout
🤗 Logout Success 👍
Platform Network Endpoint Status
ethereum mainnet http://network.henesis.io/ethereum/mainnet Synced
ethereum ropsten http://network.henesis.io/ethereum/ropsten Synced
ethereum rinkeby http://network.henesis.io/ethereum/rinkeby Synced
klaytn mainnet http://network.henesis.io/klaytn/mainnet Synced
klaytn baobab http://network.henesis.io/klaytn/baobab Synced
```


Expand Down
16 changes: 7 additions & 9 deletions bin/setup.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const os = require("os");
require('os');

if (os.type() === "Windows_NT") {
const exec = require('child_process').exec;
exec('%cd%/bin/setup.cmd', function callback(error, stdout, stderr){
});
if (os.type() === 'Windows_NT') {
const exec = require('child_process').exec;
exec('%cd%/bin/setup.cmd', function callback(error, stdout, stderr) {});
} else {
const exec = require('child_process').exec;
exec('sh ./bin/setup', function callback(error, stdout, stderr){
});
}
const exec = require('child_process').exec;
exec('sh ./bin/setup', function callback(error, stdout, stderr) {});
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
"init": "./lib/hooks/init/wretch"
},
"topics": {
"account": {
"description": "manage your account"
},
"integration": {
"description": "manage integrations"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect, test } from '@oclif/test';
import * as utils from '../utils';
import configstore from '../common/configstore';
import * as utils from '../../utils';
import configstore from '../../common/configstore';
import { Scope } from 'nock';

describe('changepw', (): void => {
describe('account:changepw', (): void => {
context(
'error occurred cases',
async (): Promise<void> => {
test
.stdout()
.command(['changepw'])
.command(['account:changepw'])
.exit(2)
.it('should be fail not logged in');
},
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('changepw', (): void => {
},
)
.stdout()
.command(['changepw'])
.command(['account:changepw'])
.it('should be success Password change', (ctx): void => {
expect(ctx.stdout).to.equal('🦄 Password changed!\n');
});
Expand Down
12 changes: 6 additions & 6 deletions src/commands/changepw.ts → src/commands/account/changepw.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import cli from 'cli-ux';
import configstore from '../common/configstore';
import { default as UserRPC } from '../rpc/user';
import Command from '../common/base';
import { passwordPrompt } from '../utils';
import configstore from '../../common/configstore';
import { default as UserRPC } from '../../rpc/user';
import Command from '../../common/base';
import { passwordPrompt } from '../../utils';

export default class Changepw extends Command {
public static description = 'change password';
public static description = 'change account password';

public static examples = [
`$ henesis user:changepw
`$ henesis account:changepw
Password:
New Password:
Again New Password:
Expand Down
17 changes: 17 additions & 0 deletions src/commands/account/describe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@oclif/test';
import * as utils from '../../utils';
import configstore from '../../common/configstore';
import { Scope } from 'nock';

describe('account:describe', (): void => {
context(
'error occurred cases',
async (): Promise<void> => {
test
.stdout()
.command(['account:describe'])
.exit(2)
.it('should be fail not logged in');
},
);
});
31 changes: 31 additions & 0 deletions src/commands/account/describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import userRpc from '../../rpc/user';
import Command from '../../common/base';
import configstore from '../../common/configstore';

export default class Describe extends Command {
public static description = 'describe account information';

public static examples = [`$ henesis account:describe`];

public static flags = {};

public static args = [];

public async run(): Promise<void> {
const user = configstore.get('user');
if (!user) {
this.error('You are not logged in.');
//TODO: Enhancement: redirect to login prompt
}

try {
const userResponse = await userRpc.describe();
this.log(`Email: ${userResponse.email}`);
this.log(`Name: ${userResponse.name}`);
this.log(`Organization: ${userResponse.organization}`);
this.log(`clientId: ${userResponse.clientId}`);
} catch (err) {
this.error(err.message);
}
}
}
11 changes: 10 additions & 1 deletion src/mock/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
LoginResponse,
Filter,
Provider,
Blockchain,
Blockchain, DescribeResponse,
} from '../types';
import * as faker from 'faker';
import { Status } from '../types';
Expand All @@ -20,6 +20,15 @@ export function newMockLogin(): LoginResponse {
);
}

export function newMockAccount(): DescribeResponse {
return new DescribeResponse(
faker.internet.email(),
faker.name.findName(),
faker.commerce.productName(),
'jcashd8uoa9p012i31kod',
);
}

export function newMockIntegration(): Integration {
return new Integration(
faker.random.alphaNumeric(15),
Expand Down
1 change: 1 addition & 0 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
newMockLogin,
newMockAccount,
newMockIntegration,
newMockIntegrationSpec,
} from './factory';
39 changes: 33 additions & 6 deletions src/rpc/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import wretch from 'wretch';
import { baseUrl, rpcVersion } from './config';
import * as mockhttp from 'mockttp';
import { UserRpc } from './user';
import { LoginResponse } from '../types';
import { newMockLogin } from '../mock';
import { DescribeResponse, LoginResponse } from '../types';
import { newMockLogin, newMockAccount } from '../mock';

wretch().polyfills({
fetch: require('node-fetch'),
Expand Down Expand Up @@ -76,18 +76,45 @@ describe('UserRpc', (): void => {
it('should be failed when jwt Token is expire.', async (): Promise<
void
> => {
await mockServer
.patch('/users/v1/passwd')
.thenJson(401, { error: { message: 'unauthenticated token' } });
await mockServer.patch('/users/v1/passwd').thenJson(401, {
error: { message: 'expired token (please log in again)' },
});

try {
await userRpc.changePassword(
'existing password',
'To be changed password',
);
} catch (err) {
expect(err.toString()).to.equal('Error: unauthenticated token');
expect(err.toString()).to.equal(
'Error: expired token (please log in again)',
);
}
});
});

describe('#describeAccount()', (): void => {
it('should be failed when jwt Token is expire.', async (): Promise<
void
> => {
await mockServer.get('/users/v1/me').thenJson(401, {
error: { message: 'expired token (please log in again)' },
});

try {
await userRpc.describe();
} catch (err) {
expect(err.toString()).to.equal(
'Error: expired token (please log in again)',
);
}
});

it('success describe account.', async (): Promise<void> => {
const accountData = newMockAccount();
await mockServer.get('/users/v1/me').thenJson(200, accountData);
const response: DescribeResponse = await userRpc.describe();
expect(response).to.deep.equal(accountData);
});
});
});
29 changes: 22 additions & 7 deletions src/rpc/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { LoginRequest, LoginResponse, ChangePassword } from '../types';
import {
LoginRequest,
LoginResponse,
ChangePassword,
DescribeResponse,
} from '../types';
import { plainToClass } from 'class-transformer';
import { baseUrl, rpcVersion } from './config';
import { getWretcher } from './wretch';
Expand Down Expand Up @@ -36,18 +41,28 @@ export class UserRpc {
await getWretcher()
.url(`${this.server}/passwd`)
.patch(payload)
.unauthorized(
(): Error => {
throw new Error(`unauthenticated token`);
},
)
.error(
403,
(): Error => {
throw new Error(`failed to change password`);
},
)
.json();
.json()
.catch((err: any) => {
throw err;
});
}

public async describe(): Promise<DescribeResponse> {
const json = await getWretcher()
.url(`${this.server}/me`)
.get()
.json()
.catch((err: any) => {
throw err;
});

return plainToClass(DescribeResponse, json) as DescribeResponse;
}
}

Expand Down
Loading

0 comments on commit dd958fb

Please sign in to comment.