Skip to content

Commit d65aeb8

Browse files
committed
refactor: moved decode tests into its own file
TICKET: WP-5417
1 parent cca1545 commit d65aeb8

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import {
1515
import { UnlockLightningWalletBody, UnlockLightningWalletParams } from '../../../src/typedRoutes/api/v2/unlockWallet';
1616
import { OfcSignPayloadBody } from '../../../src/typedRoutes/api/v2/ofcSignPayload';
1717
import { CreateAddressBody, CreateAddressParams } from '../../../src/typedRoutes/api/v2/createAddress';
18-
import {
19-
KeychainChangePasswordBody,
20-
KeychainChangePasswordParams,
21-
} from '../../../src/typedRoutes/api/v2/keychainChangePassword';
2218

2319
export function assertDecode<T>(codec: t.Type<T, unknown>, input: unknown): T {
2420
const result = codec.decode(input);
@@ -247,24 +243,4 @@ describe('io-ts decode tests', function () {
247243
assertDecode(t.type(CreateAddressBody), { eip1559: { maxFeePerGas: 1, maxPriorityFeePerGas: 1 } });
248244
assertDecode(t.type(CreateAddressBody), {});
249245
});
250-
251-
it('express.keychain.changePassword', function () {
252-
// missing id
253-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordParams), { coin: 'btc' }));
254-
// invalid coin type
255-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordParams), { coin: 123, id: 'abc' }));
256-
// valid params
257-
assertDecode(t.type(KeychainChangePasswordParams), { coin: 'btc', id: 'abc' });
258-
// missing required fields
259-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), {}));
260-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a' }));
261-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { newPassword: 'b' }));
262-
// invalid types
263-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 1, newPassword: 'b' }));
264-
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 2 }));
265-
// valid minimal
266-
assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 'b' });
267-
// valid with optional otp
268-
assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 'b', otp: '123456' });
269-
});
270246
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as assert from 'assert';
2+
import * as t from 'io-ts';
3+
import {
4+
KeychainChangePasswordBody,
5+
KeychainChangePasswordParams,
6+
} from '../../../../src/typedRoutes/api/v2/keychainChangePassword';
7+
import { assertDecode } from '../decode';
8+
9+
describe('express.keychain.changePassword', function () {
10+
it('decodes params', function () {
11+
// missing id
12+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordParams), { coin: 'btc' }));
13+
// invalid coin type
14+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordParams), { coin: 123, id: 'abc' }));
15+
// valid params
16+
assertDecode(t.type(KeychainChangePasswordParams), { coin: 'btc', id: 'abc' });
17+
});
18+
19+
it('decodes body', function () {
20+
// missing required fields
21+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), {}));
22+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a' }));
23+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { newPassword: 'b' }));
24+
// invalid types
25+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 1, newPassword: 'b' }));
26+
assert.throws(() => assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 2 }));
27+
// valid minimal
28+
assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 'b' });
29+
// valid with optional otp
30+
assertDecode(t.type(KeychainChangePasswordBody), { oldPassword: 'a', newPassword: 'b', otp: '123456' });
31+
});
32+
});

0 commit comments

Comments
 (0)