Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmartin committed Dec 5, 2023
1 parent 6c5fb68 commit f92b2c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions commander/src/bootstrapping/commands/config/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ export class CreateCommand extends Command {
if (!userResponse.confirm) {
this.error('Operation cancelled, config file already present at the desired location');
} else {
const res = await handleOutputFlag(configPath, defaultConfig, 'config', 'config.json');
const res = await handleOutputFlag(configPath, defaultConfig, 'config');
this.log(res);
}
} else {
fs.mkdirSync(configPath, { recursive: true });

const res = await handleOutputFlag(configPath, defaultConfig, 'config', 'config.json');
const res = await handleOutputFlag(configPath, defaultConfig, 'config');
this.log(res);
}
}
Expand Down
1 change: 0 additions & 1 deletion commander/src/bootstrapping/commands/keys/export.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
/*
* Copyright © 2022 Lisk Foundation
*
Expand Down
2 changes: 1 addition & 1 deletion commander/src/bootstrapping/commands/passphrase/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class EncryptCommand extends Command {
const result = await encryptPassphrase(passphrase, password, outputPublicKey);

if (output) {
const res = await handleOutputFlag(output, result, 'passphrase', 'keys.json');
const res = await handleOutputFlag(output, result, 'passphrase');
this.log(res);
} else {
this.log(JSON.stringify(result, undefined, ' '));
Expand Down
21 changes: 9 additions & 12 deletions commander/test/bootstrapping/commands/passphrase/encrypt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ describe('passphrase:encrypt', () => {
jest
.spyOn(outputUtils, 'handleOutputFlag')
.mockImplementation(async () =>
Promise.resolve('Successfully written data to /my/path/keys.json'),
Promise.resolve('Successfully written data to /mypath/passphrase.json'),
);

await EncryptCommand.run(['--output-public-key', '--output=/mypath/keys.json'], config);
await EncryptCommand.run(['--output-public-key', '--output=/mypath/passphrase.json'], config);

expect(cryptography.encrypt.encryptMessageWithPassword).toHaveBeenCalledWith(
defaultInputs.passphrase,
Expand All @@ -108,13 +108,12 @@ describe('passphrase:encrypt', () => {
expect(readerUtils.getPasswordFromPrompt).toHaveBeenCalledWith('password', true);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledTimes(1);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledWith(
'/mypath/keys.json',
'/mypath/passphrase.json',
{
encryptedPassphrase: encryptedPassphraseObject,
publicKey: defaultKeys.publicKey.toString('hex'),
},
'passphrase',
'keys.json',
);
});
});
Expand All @@ -124,13 +123,13 @@ describe('passphrase:encrypt', () => {
jest
.spyOn(outputUtils, 'handleOutputFlag')
.mockImplementation(async () =>
Promise.resolve('Successfully written data to /my/path/keys.json'),
Promise.resolve('Successfully written data to /mypath/passphrase.json'),
);

await EncryptCommand.run(
[
'--passphrase=enemy pill squeeze gold spoil aisle awake thumb congress false box wagon',
'--output=/mypath/keys.json',
'--output=/mypath/passphrase.json',
],
config,
);
Expand All @@ -143,12 +142,11 @@ describe('passphrase:encrypt', () => {
expect(readerUtils.getPasswordFromPrompt).toHaveBeenCalledWith('password', true);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledTimes(1);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledWith(
'/mypath/keys.json',
'/mypath/passphrase.json',
{
encryptedPassphrase: encryptedPassphraseObject,
},
'passphrase',
'keys.json',
);
});
});
Expand All @@ -158,14 +156,14 @@ describe('passphrase:encrypt', () => {
jest
.spyOn(outputUtils, 'handleOutputFlag')
.mockImplementation(async () =>
Promise.resolve('Successfully written data to /my/path/keys.json'),
Promise.resolve('Successfully written data to /mypath/passphrase.json'),
);

await EncryptCommand.run(
[
'--passphrase=enemy pill squeeze gold spoil aisle awake thumb congress false box wagon',
'--password=LbYpLpV9Wpec6ux8',
'--output=/mypath/keys.json',
'--output=/mypath/passphrase.json',
],
config,
);
Expand All @@ -177,12 +175,11 @@ describe('passphrase:encrypt', () => {
expect(readerUtils.getPasswordFromPrompt).not.toHaveBeenCalledWith('password', true);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledTimes(1);
expect(outputUtils.handleOutputFlag).toHaveBeenCalledWith(
'/mypath/keys.json',
'/mypath/passphrase.json',
{
encryptedPassphrase: encryptedPassphraseObject,
},
'passphrase',
'keys.json',
);
});
});
Expand Down

0 comments on commit f92b2c5

Please sign in to comment.