Skip to content

Commit b4b9107

Browse files
committed
refactor: added decoding test and new codec for 200 response
TICKET: WP-5446
1 parent 63e47a7 commit b4b9107

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

modules/express/src/typedRoutes/api/v2/unlockWallet.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ export const UnlockLightningWalletBody = {
2323
passphrase: t.string,
2424
} as const;
2525

26+
export const UnlockLightningWalletReponse200 = t.type({
27+
message: t.string,
28+
});
29+
2630
/**
2731
* Response for unlocking a lightning wallet.
2832
*/
2933
export const UnlockLightningWalletReponse = {
3034
/** Confirmation message. */
31-
200: t.type({
32-
message: t.string,
33-
}),
35+
200: UnlockLightningWalletReponse200,
3436
/** BitGo Express error payload. */
3537
400: BitgoExpressError,
3638
} as const;

modules/express/test/unit/clientRoutes/lightning/lightningSignerRoutes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
22
import { BitGo } from 'bitgo';
3-
import { common } from '@bitgo/sdk-core';
3+
import { common, decodeOrElse } from '@bitgo/sdk-core';
44
import nock from 'nock';
55
import * as express from 'express';
66
import * as sinon from 'sinon';
77
import * as fs from 'fs';
8+
import { UnlockLightningWalletReponse200 } from '../../../../src/typedRoutes/api/v2/unlockWallet';
89

910
import { lightningSignerConfigs, apiData, signerApiData } from './lightningSignerFixture';
1011
import {
@@ -178,7 +179,10 @@ describe('Lightning signer routes', () => {
178179
decoded: { coin: 'tlnbtc', id: 'fakeid', passphrase: apiData.unlockWalletRequestBody.passphrase },
179180
} as unknown as ExpressApiRouteRequest<'express.lightning.unlockWallet', 'post'>;
180181

181-
await handleUnlockLightningWallet(req);
182+
const res = await handleUnlockLightningWallet(req);
183+
decodeOrElse('UnlockLightningWalletReponse200', UnlockLightningWalletReponse200, res, (_) => {
184+
throw new Error('Response did not match expected codec');
185+
});
182186

183187
unlockwalletNock.done();
184188
readFileStub.calledOnceWith('lightningSignerFileSystemPath').should.be.true();

0 commit comments

Comments
 (0)