Skip to content

Commit febcb33

Browse files
committed
[exoframe-client] Fix add new token format from server
Use format that exoframe-server uses instead of outdated one
1 parent 1a00c7a commit febcb33

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

packages/exoframe-cli/src/handlers/token/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const tokenAddHandler = async (name) => {
3838
try {
3939
const generatedToken = await createToken({ name: tokenName, endpoint, token });
4040

41-
console.log(chalk.bold('New token generated:'));
41+
spinner.succeed('New token generated:');
4242
console.log('');
4343
console.log(` > Name: ${generatedToken.name}`);
4444
console.log(` > Value: ${generatedToken.value}`);

packages/exoframe-cli/test/token.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ test('Should generate new token via interactive input', async () => {
102102
// spy on console
103103
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
104104
// handle correct request
105-
const tokenServer = nock('http://localhost:8080').post('/deployToken').reply(200, { name: 'test', value: 'val' });
105+
const tokenServer = nock('http://localhost:8080').post('/deployToken').reply(200, { name: 'test', token: 'val' });
106106

107107
// mock enquirer reply
108108
const enqSpy = vi.spyOn(inquirer, 'prompt').mockImplementationOnce(() => Promise.resolve({ tokenName: 'test' }));
@@ -157,7 +157,7 @@ test('Should generate new token via flags', async () => {
157157
// spy on console
158158
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
159159
// handle correct request
160-
const tokenServer = nock('http://localhost:8080').post('/deployToken').reply(200, { name: 'test', value: 'val' });
160+
const tokenServer = nock('http://localhost:8080').post('/deployToken').reply(200, { name: 'test', token: 'val' });
161161

162162
// execute logs
163163
await program.parseAsync(['token', 'add', 'test'], { from: 'user' });

packages/exoframe-client/src/token.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const listTokens = async ({ endpoint, token }) => {
4848
* @param {string} params.name - new token name
4949
* @param {string} params.endpoint - exoframe server endpoint
5050
* @param {string} params.token - exoframe auth token
51-
* @returns {Token}
51+
* @returns {Promise<Token>}
5252
*/
5353
export const createToken = async ({ name, endpoint, token }) => {
5454
// services request url
@@ -67,7 +67,10 @@ export const createToken = async ({ name, endpoint, token }) => {
6767
// try sending request
6868
try {
6969
const { body } = await got(remoteUrl, options);
70-
return body;
70+
return {
71+
name,
72+
value: body.token,
73+
};
7174
} catch (e) {
7275
// if authorization is expired/broken/etc
7376
if (e.response.statusCode === 401) {

packages/exoframe-client/test/token.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ const token = 'test-123';
77

88
test('Should generate token', async () => {
99
// handle correct request
10-
const response = { value: 'test', name: 'new' };
10+
const response = { token: 'test', name: 'new' };
1111
const tokenServer = nock(endpoint).post('/deployToken').reply(200, response);
1212
// execute token creation
1313
const result = await createToken({ name: response.name, endpoint, token });
1414
// make sure it was successful
15-
expect(result).toEqual(response);
15+
expect(result).toEqual({
16+
name: response.name,
17+
value: response.token,
18+
});
1619
// check that server was called
1720
expect(tokenServer.isDone()).toBeTruthy();
1821
// tear down nock

0 commit comments

Comments
 (0)