Skip to content

Commit c0b322c

Browse files
committed
refactor: removed unneccessary UTs and modified existing ones
TICKET: WP-5444
1 parent dd93ddf commit c0b322c

File tree

3 files changed

+11
-142
lines changed

3 files changed

+11
-142
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ export const LightningInitWalletParams = {
1414

1515
/**
1616
* Request body for initializing a Lightning wallet
17-
* @property passphrase - Passphrase to encrypt the admin macaroon of the signer node.
1817
*/
1918
export const LightningInitWalletBody = {
19+
/** Passphrase to encrypt the admin macaroon of the signer node. */
2020
passphrase: t.string,
21+
/** Optional hostname or IP address to set the `expressHost` field of the wallet. */
2122
expressHost: optional(t.string),
2223
} as const;
2324

2425
/**
25-
* Response
26-
* - 200: Returns the updated wallet. On success, the wallet's `coinSpecific` will include the encrypted admin macaroon for the Lightning signer node.
27-
* - 400: BitGo Express error payload when initialization cannot proceed (for example: invalid coin, unsupported environment, wallet not in an initializable state).
26+
* Response for initializing a Lightning wallet
2827
*/
2928
export const LightningInitWalletResponse = {
29+
/** Returns the updated wallet. On success, the wallet's `coinSpecific` will include the encrypted admin macaroon for the Lightning signer node. */
3030
200: t.unknown,
31+
/** BitGo Express error payload when initialization cannot proceed (for example: invalid coin, unsupported environment, wallet not in an initializable state). */
3132
400: BitgoExpressError,
3233
} as const;
3334

@@ -36,8 +37,6 @@ export const LightningInitWalletResponse = {
3637
* Returns the updated wallet with the encrypted admin macaroon in the `coinSpecific` response field.
3738
*
3839
* @operationId express.lightning.initWallet
39-
*
40-
* POST /api/v2/{coin}/wallet/{walletId}/initwallet
4140
*/
4241
export const PostLightningInitWallet = httpRoute({
4342
path: '/api/v2/:coin/wallet/:walletId/initwallet',

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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';
@@ -14,6 +14,7 @@ import {
1414
handleUnlockLightningWallet,
1515
} from '../../../../src/lightning/lightningSignerRoutes';
1616
import { ExpressApiRouteRequest } from '../../../../src/typedRoutes/api';
17+
import { PostLightningInitWallet } from '../../../../src/typedRoutes/api/v2/lightningInitWallet';
1718

1819
describe('Lightning signer routes', () => {
1920
let bitgo: TestBitGoAPI;
@@ -83,7 +84,10 @@ describe('Lightning signer routes', () => {
8384
},
8485
} as unknown as ExpressApiRouteRequest<'express.lightning.initWallet', 'post'>;
8586

86-
await handleInitLightningWallet(req);
87+
const res = await handleInitLightningWallet(req);
88+
decodeOrElse('PostLightningInitWallet.response.200', PostLightningInitWallet.response[200], res, (_) => {
89+
throw new Error('Response did not match expected codec');
90+
});
8791

8892
wpWalletUpdateNock.done();
8993
signerInitWalletNock.done();

modules/express/test/unit/typedRoutes/decode.ts

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import {
1010
LightningInitWalletBody,
1111
LightningInitWalletParams,
1212
} from '../../../src/typedRoutes/api/v2/lightningInitWallet';
13-
import { agent as supertest } from 'supertest';
14-
import nock from 'nock';
15-
import { DefaultConfig } from '../../../src/config';
16-
import { app as expressApp } from '../../../src/expressApp';
17-
import * as sinon from 'sinon';
18-
import { BitGo } from 'bitgo';
1913

2014
export function assertDecode<T>(codec: t.Type<T, unknown>, input: unknown): T {
2115
const result = codec.decode(input);
@@ -158,131 +152,3 @@ describe('io-ts decode tests', function () {
158152
assertDecode(t.type(LightningInitWalletBody), { passphrase: 'p', expressHost: 'host.example' });
159153
});
160154
});
161-
162-
describe('e2e tests for io-ts routes', function () {
163-
let agent;
164-
let authenticateStub: sinon.SinonStub;
165-
let walletsStub: sinon.SinonStub;
166-
let decryptStub: sinon.SinonStub;
167-
let encryptStub: sinon.SinonStub;
168-
let verifyAddressStub: sinon.SinonStub;
169-
before(function () {
170-
nock.restore();
171-
172-
const args = {
173-
...DefaultConfig,
174-
debug: false,
175-
env: 'test' as const,
176-
logfile: '/dev/null',
177-
};
178-
179-
const app = expressApp(args);
180-
agent = supertest(app);
181-
182-
authenticateStub = sinon.stub(BitGo.prototype, 'authenticate').callsFake(async (body: any) => {
183-
return {
184-
email: `${body.username}@example.com`,
185-
password: body.password,
186-
forceSMS: false,
187-
} as any;
188-
});
189-
encryptStub = sinon.stub(BitGo.prototype, 'encrypt').callsFake((params: any) => `enc:${params.input}`);
190-
decryptStub = sinon.stub(BitGo.prototype, 'decrypt').callsFake((params: any) => {
191-
const inputStr = String(params.input);
192-
return inputStr.startsWith('enc:') ? inputStr.substring(4) : inputStr;
193-
});
194-
verifyAddressStub = sinon.stub(BitGo.prototype, 'verifyAddress').callsFake((_params: any) => true);
195-
walletsStub = sinon.stub(BitGo.prototype, 'wallets').callsFake(() => {
196-
return {
197-
createWalletWithKeychains: async () => ({
198-
wallet: 'wallet-id-123',
199-
userKeychain: 'user-keychain',
200-
backupKeychain: 'backup-keychain',
201-
}),
202-
};
203-
});
204-
});
205-
beforeEach(function () {
206-
authenticateStub.resetHistory();
207-
walletsStub.resetHistory();
208-
decryptStub.resetHistory();
209-
encryptStub.resetHistory();
210-
verifyAddressStub.resetHistory();
211-
});
212-
after(function () {
213-
authenticateStub.restore();
214-
walletsStub.restore();
215-
decryptStub.restore();
216-
encryptStub.restore();
217-
verifyAddressStub.restore();
218-
});
219-
220-
it('POST /api/v2/user/login success', async function () {
221-
const res = await agent.post('/api/v2/user/login').send({ username: 'alice', password: 'pw' });
222-
res.status.should.equal(200);
223-
res.body.email.should.equal('[email protected]');
224-
res.body.password.should.equal('pw');
225-
sinon.assert.calledOnce(authenticateStub);
226-
sinon.assert.calledWithMatch(authenticateStub, { username: 'alice', password: 'pw' });
227-
});
228-
229-
it('POST /api/v2/user/login decode failure', async function () {
230-
const res = await agent.post('/api/v2/user/login').send({ username: 'alice' });
231-
res.status.should.equal(400);
232-
sinon.assert.notCalled(authenticateStub);
233-
});
234-
235-
it('POST /api/v2/encrypt success', async function () {
236-
const res = await agent.post('/api/v2/encrypt').send({ input: 'hello' });
237-
res.status.should.equal(200);
238-
res.body.encrypted.should.equal('enc:hello');
239-
sinon.assert.calledOnce(encryptStub);
240-
sinon.assert.calledWithMatch(encryptStub, { input: 'hello' });
241-
});
242-
243-
it('POST /api/v2/encrypt decode failure', async function () {
244-
const res = await agent.post('/api/v2/encrypt').send({ input: 123 });
245-
res.status.should.equal(400);
246-
sinon.assert.notCalled(encryptStub);
247-
});
248-
249-
it('POST /api/v2/decrypt success', async function () {
250-
const res = await agent.post('/api/v2/decrypt').send({ input: 'enc:secret', password: 'pw' });
251-
res.status.should.equal(200);
252-
res.body.decrypted.should.equal('secret');
253-
sinon.assert.calledOnce(decryptStub);
254-
sinon.assert.calledWithMatch(decryptStub, { input: 'enc:secret', password: 'pw' });
255-
});
256-
257-
it('POST /api/v2/decrypt decode failure', async function () {
258-
const res = await agent.post('/api/v2/decrypt').send({ password: 'pw' });
259-
res.status.should.equal(400);
260-
sinon.assert.notCalled(decryptStub);
261-
});
262-
263-
it('POST /api/v2/verifyaddress success', async function () {
264-
const res = await agent.post('/api/v2/verifyaddress').send({ address: 'addr1' });
265-
res.status.should.equal(200);
266-
res.body.should.have.property('verified', true);
267-
sinon.assert.calledOnce(verifyAddressStub);
268-
});
269-
270-
it('POST /api/v2/verifyaddress decode failure - invalid address', async function () {
271-
const res = await agent.post('/api/v2/verifyaddress').send({ address: 42 });
272-
res.status.should.equal(400);
273-
sinon.assert.notCalled(verifyAddressStub);
274-
});
275-
276-
it('POST /api/v1/wallets/simplecreate success', async function () {
277-
const res = await agent.post('/api/v1/wallets/simplecreate').send({ passphrase: 'pass' });
278-
res.status.should.equal(200);
279-
res.body.wallet.should.equal('wallet-id-123');
280-
sinon.assert.calledOnce(walletsStub);
281-
});
282-
283-
it('POST /api/v1/wallets/simplecreate decode - missing passphrase', async function () {
284-
const res = await agent.post('/api/v1/wallets/simplecreate').send({});
285-
res.status.should.equal(400);
286-
sinon.assert.notCalled(walletsStub);
287-
});
288-
});

0 commit comments

Comments
 (0)