Skip to content

Commit

Permalink
chore: using type narrowing instead of using 'as'
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Oct 11, 2024
1 parent 040e457 commit 77d3f89
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 @@ -65,6 +64,7 @@ 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,9 @@ describe('vaultsSecretsMkdir', () => {
await writer.close();
for await (const data of response.readable) {
expect(data.type).toEqual('error');
const error = data as ErrorMessage;
expect(error.code).toEqual('ENOENT');
expect(error.reason).toEqual(dirPath);
if (data.type !== 'error') utils.never();
expect(data.code).toEqual('ENOENT');
expect(data.reason).toEqual(dirPath);
}
await vaultManager.withVaults([vaultId], async (vault) => {
await vault.readF(async (efs) => {
Expand Down Expand Up @@ -1439,9 +1439,8 @@ describe('vaultsSecretsMkdir', () => {
// Check if the operation concluded as expected
for await (const data of response.readable) {
if (data.type !== 'success') {
const error = data as ErrorMessage;
expect(error.code).toEqual('ENOENT');
expect(error.reason).toEqual(dirPath3);
expect(data.code).toEqual('ENOENT');
expect(data.reason).toEqual(dirPath3);
}
}
await vaultManager.withVaults(
Expand Down Expand Up @@ -1475,9 +1474,9 @@ describe('vaultsSecretsMkdir', () => {
// Check if the operation concluded as expected
for await (const data of response.readable) {
expect(data.type).toEqual('error');
const error = data as ErrorMessage;
expect(error.code).toEqual('EEXIST');
expect(error.reason).toEqual(dirPath);
if (data.type !== 'error') utils.never();
expect(data.code).toEqual('EEXIST');
expect(data.reason).toEqual(dirPath);
}
await vaultManager.withVaults([vaultId], async (vault) => {
await vault.readF(async (efs) => {
Expand Down

0 comments on commit 77d3f89

Please sign in to comment.