Skip to content

Commit 2d124f6

Browse files
Merge pull request #6739 from BitGo/WP-5407-fix-test-case-and-move-file
fix(express): fix testcases and move to correct file
2 parents d77e411 + bfac86e commit 2d124f6

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

modules/express/src/typedRoutes/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GetPingExpress } from './common/pingExpress';
77
import { PostLogin } from './common/login';
88
import { PostDecrypt } from './common/decrypt';
99
import { PostVerifyAddress } from './common/verifyAddress';
10-
import { PostAcceptShare } from './common/acceptShare';
10+
import { PostAcceptShare } from './v1/acceptShare';
1111
import { PostSimpleCreate } from './v1/simpleCreate';
1212
import { PutPendingApproval } from './v1/pendingApproval';
1313
export const ExpressApi = apiSpec({

modules/express/src/typedRoutes/api/common/acceptShare.ts renamed to modules/express/src/typedRoutes/api/v1/acceptShare.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const AcceptShareRequestBody = {
1010
userPassword: optional(t.string),
1111
newWalletPassphrase: optional(t.string),
1212
overrideEncryptedXprv: optional(t.string),
13-
walletShareId: t.string,
1413
};
1514

1615
/**

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

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
AcceptShareRequestParams,
55
AcceptShareRequestBody,
66
PostAcceptShare,
7-
} from '../../../src/typedRoutes/api/common/acceptShare';
7+
} from '../../../src/typedRoutes/api/v1/acceptShare';
88

99
/**
1010
* Helper function to test io-ts codec decoding
@@ -54,53 +54,26 @@ describe('AcceptShare codec tests', function () {
5454
userPassword: 'mySecurePassword',
5555
newWalletPassphrase: 'myNewPassphrase',
5656
overrideEncryptedXprv: 'encryptedXprvString',
57-
walletShareId: 'walletShare123',
5857
};
5958

6059
const decoded = assertDecode(t.type(AcceptShareRequestBody), validBody);
6160
assert.strictEqual(decoded.userPassword, validBody.userPassword);
6261
assert.strictEqual(decoded.newWalletPassphrase, validBody.newWalletPassphrase);
6362
assert.strictEqual(decoded.overrideEncryptedXprv, validBody.overrideEncryptedXprv);
64-
assert.strictEqual(decoded.walletShareId, validBody.walletShareId);
6563
});
6664

67-
it('should validate body with only required fields', function () {
68-
const validBody = {
69-
walletShareId: 'walletShare123',
70-
};
65+
it('should validate empty body since all fields are optional', function () {
66+
const validBody = {};
7167

7268
const decoded = assertDecode(t.type(AcceptShareRequestBody), validBody);
73-
assert.strictEqual(decoded.walletShareId, validBody.walletShareId);
7469
assert.strictEqual(decoded.userPassword, undefined);
7570
assert.strictEqual(decoded.newWalletPassphrase, undefined);
7671
assert.strictEqual(decoded.overrideEncryptedXprv, undefined);
7772
});
7873

79-
it('should reject body with missing walletShareId', function () {
80-
const invalidBody = {
81-
userPassword: 'mySecurePassword',
82-
newWalletPassphrase: 'myNewPassphrase',
83-
};
84-
85-
assert.throws(() => {
86-
assertDecode(t.type(AcceptShareRequestBody), invalidBody);
87-
});
88-
});
89-
90-
it('should reject body with non-string walletShareId', function () {
91-
const invalidBody = {
92-
walletShareId: 12345, // number instead of string
93-
};
94-
95-
assert.throws(() => {
96-
assertDecode(t.type(AcceptShareRequestBody), invalidBody);
97-
});
98-
});
99-
10074
it('should reject body with non-string optional fields', function () {
10175
const invalidBody = {
10276
userPassword: 12345, // number instead of string
103-
walletShareId: 'walletShare123',
10477
};
10578

10679
assert.throws(() => {
@@ -110,16 +83,6 @@ describe('AcceptShare codec tests', function () {
11083
});
11184

11285
describe('Edge cases', function () {
113-
it('should handle empty strings for required fields', function () {
114-
const body = {
115-
walletShareId: '', // empty string
116-
};
117-
118-
// Empty strings are still valid strings
119-
const decoded = assertDecode(t.type(AcceptShareRequestBody), body);
120-
assert.strictEqual(decoded.walletShareId, '');
121-
});
122-
12386
describe('PostAcceptShare route definition', function () {
12487
it('should have the correct path', function () {
12588
assert.strictEqual(PostAcceptShare.path, '/api/v1/walletshare/:shareId/acceptShare');
@@ -146,7 +109,6 @@ describe('AcceptShare codec tests', function () {
146109
userPassword: '',
147110
newWalletPassphrase: '',
148111
overrideEncryptedXprv: '',
149-
walletShareId: 'walletShare123',
150112
};
151113

152114
const decoded = assertDecode(t.type(AcceptShareRequestBody), body);
@@ -157,13 +119,13 @@ describe('AcceptShare codec tests', function () {
157119

158120
it('should handle additional unknown properties', function () {
159121
const body = {
160-
walletShareId: 'walletShare123',
122+
userPassword: 'password123',
161123
unknownProperty: 'some value',
162124
};
163125

164126
// io-ts with t.exact() strips out additional properties
165127
const decoded = assertDecode(t.exact(t.type(AcceptShareRequestBody)), body);
166-
assert.strictEqual(decoded.walletShareId, 'walletShare123');
128+
assert.strictEqual(decoded.userPassword, 'password123');
167129
// @ts-expect-error - unknownProperty doesn't exist on the type
168130
assert.strictEqual(decoded.unknownProperty, undefined);
169131
});

0 commit comments

Comments
 (0)