Skip to content

Commit

Permalink
wip - #305 fix for test
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Mar 8, 2022
1 parent c0f6c17 commit 9ab86d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/client/service/vaultsClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as grpc from '@grpc/grpc-js';
import { utils as grpcUtils } from '../../grpc';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';
import * as validationUtils from '../../validation/utils';
import * as vaultsUtils from '../../vaults/utils';

function vaultsClone({
authenticate,
Expand Down Expand Up @@ -35,8 +36,8 @@ function vaultsClone({
// Vault id
let vaultId;
const vaultNameOrId = vaultMessage.getNameOrId();
vaultId = vaultManager.getVaultId(vaultNameOrId);
vaultId = vaultId ?? validationUtils.parseVaultId(vaultId);
vaultId = vaultsUtils.decodeVaultId(vaultNameOrId);
vaultId = vaultId ?? vaultNameOrId;
// Node id
const nodeId = validationUtils.parseNodeId(nodeMessage.getNodeId());
await vaultManager.cloneVault(nodeId, vaultId);
Expand Down
14 changes: 7 additions & 7 deletions tests/bin/vaults/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('CLI vaults', () => {
command = [
'vaults',
'rename',
'InvalidVaultId', // Vault does not exist
'z4iAXFwgHGeyUrdC5CiCNU4', // Vault does not exist
'RenamedVault',
'-np',
dataDir,
Expand All @@ -167,7 +167,7 @@ describe('CLI vaults', () => {

const result = await testBinUtils.pkStdio([...command], {}, dataDir);
// Exit code of the exception
expect(result.exitCode).toBe(10);
expect(result.exitCode).toBe(sysexits.USAGE);

const list = (await polykeyAgent.vaultManager.listVaults()).keys();
const namesList: string[] = [];
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('CLI vaults', () => {
targetNodeIdEncoded,
];
result = await testBinUtils.pkStdio([...command], {}, dataDir);
expect(result.exitCode).toBe(10);
expect(result.exitCode).toBe(sysexits.USAGE);
expect(result.stderr).toContain('ErrorVaultsVaultUndefined');

command = [
Expand All @@ -352,8 +352,7 @@ describe('CLI vaults', () => {
'InvalidNodeId',
];
result = await testBinUtils.pkStdio([...command], {}, dataDir);
expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('ErrorInvalidId');
expect(result.exitCode).toBe(sysexits.USAGE);

await targetPolykeyAgent.stop();
await targetPolykeyAgent.destroy();
Expand Down Expand Up @@ -487,6 +486,7 @@ describe('CLI vaults', () => {
const vaultIdEncoded1 = vaultsUtils.encodeVaultId(vaultId1);
const vaultIdEncoded2 = vaultsUtils.encodeVaultId(vaultId2);
const targetNodeId = testUtils.generateRandomNodeId();
const targetNodeIdEncoded = nodesUtils.encodeNodeId(targetNodeId);
await polykeyAgent.gestaltGraph.setNode({
id: nodesUtils.encodeNodeId(targetNodeId),
chain: {},
Expand All @@ -504,14 +504,14 @@ describe('CLI vaults', () => {
command = ['vaults', 'permissions', '-np', dataDir, vaultIdEncoded1];
const result = await testBinUtils.pkStdio([...command], {}, dataDir);
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain(targetNodeId);
expect(result.stdout).toContain(targetNodeIdEncoded);
expect(result.stdout).toContain('clone');
expect(result.stdout).toContain('pull');

command = ['vaults', 'permissions', '-np', dataDir, vaultIdEncoded2];
const result2 = await testBinUtils.pkStdio([...command], {}, dataDir);
expect(result2.exitCode).toBe(0);
expect(result2.stdout).toContain(targetNodeId);
expect(result2.stdout).toContain(targetNodeIdEncoded);
expect(result2.stdout).not.toContain('clone');
expect(result2.stdout).toContain('pull');
});
Expand Down

0 comments on commit 9ab86d0

Please sign in to comment.