Skip to content

Commit

Permalink
fix: explicitly changing type if error
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Oct 14, 2024
1 parent 37c1d36 commit d6e5566
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FileSystem } from '@/types';
import type { VaultId } from '@/ids';
import type NodeManager from '@/nodes/NodeManager';
import type {
ErrorMessage,
LogEntryMessage,
SecretContentMessage,
VaultListMessage,
Expand Down Expand Up @@ -64,7 +65,6 @@ import {
vaultsSecretsStat,
vaultsVersion,
} from '@/client/callers';
import * as utils from '@/utils';
import * as keysUtils from '@/keys/utils';
import * as nodesUtils from '@/nodes/utils';
import * as vaultsUtils from '@/vaults/utils';
Expand Down Expand Up @@ -1371,9 +1371,11 @@ describe('vaultsSecretsMkdir', () => {
await writer.close();
for await (const data of response.readable) {
expect(data.type).toEqual('error');
if (data.type !== 'error') utils.never();
expect(data.code).toEqual('ENOENT');
expect(data.reason).toEqual(dirPath);
// TS cannot properly evaluate a type as nested as this, so we use the
// as keyword to help it. Inside this block, the type of data is 'error'.
const error = data as ErrorMessage;
expect(error.code).toEqual('ENOENT');
expect(error.reason).toEqual(dirPath);
}
await vaultManager.withVaults([vaultId], async (vault) => {
await vault.readF(async (efs) => {
Expand Down Expand Up @@ -1438,9 +1440,12 @@ describe('vaultsSecretsMkdir', () => {
await writer.close();
// Check if the operation concluded as expected
for await (const data of response.readable) {
if (data.type !== 'success') {
expect(data.code).toEqual('ENOENT');
expect(data.reason).toEqual(dirPath3);
if (data.type === 'error') {
// TS cannot properly evaluate a type as nested as this, so we use the
// as keyword to help it. Inside this block, the type of data is 'error'.
const error = data as ErrorMessage;
expect(error.code).toEqual('ENOENT');
expect(error.reason).toEqual(dirPath3);
}
}
await vaultManager.withVaults(
Expand Down Expand Up @@ -1474,9 +1479,11 @@ describe('vaultsSecretsMkdir', () => {
// Check if the operation concluded as expected
for await (const data of response.readable) {
expect(data.type).toEqual('error');
if (data.type !== 'error') utils.never();
expect(data.code).toEqual('EEXIST');
expect(data.reason).toEqual(dirPath);
// TS cannot properly evaluate a type as nested as this, so we use the
// as keyword to help it. Inside this block, the type of data is 'error'.
const error = data as ErrorMessage;
expect(error.code).toEqual('EEXIST');
expect(error.reason).toEqual(dirPath);
}
await vaultManager.withVaults([vaultId], async (vault) => {
await vault.readF(async (efs) => {
Expand Down

0 comments on commit d6e5566

Please sign in to comment.