From 77d3f899e93507a881f3a938134b90d4639dec26 Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Fri, 11 Oct 2024 17:14:02 +1100 Subject: [PATCH] chore: using type narrowing instead of using 'as' --- tests/client/handlers/vaults.test.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index 298f6da5f..6bd41b77d 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -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, @@ -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'; @@ -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) => { @@ -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( @@ -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) => {