Skip to content

Commit 1ca816a

Browse files
authored
Merge pull request #226 from BitGo/WCN-742
feat: implement client to abstract bridge calls
2 parents 99d42cd + 7241174 commit 1ca816a

6 files changed

Lines changed: 614 additions & 105 deletions

File tree

src/__tests__/api/advancedWalletManager/keyProviderClient.test.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('postMpcV2Key', () => {
9393

9494
response.status.should.equal(500);
9595
response.body.should.have.property('error', 'Internal Server Error');
96-
response.body.should.have.property('details', 'This is an error message');
96+
response.body.details.should.match(/This is an error message/);
9797
});
9898

9999
it('should handle unexpected key provider errors', async () => {
@@ -106,10 +106,7 @@ describe('postMpcV2Key', () => {
106106

107107
response.status.should.equal(500);
108108
response.body.should.have.property('error', 'Internal Server Error');
109-
response.body.should.have.property(
110-
'details',
111-
'key provider returned unexpected response. 502: Unexpected error',
112-
);
109+
response.body.details.should.match(/502.*Unexpected error/);
113110
});
114111
});
115112

@@ -150,27 +147,17 @@ describe('KeyProviderClient.generateKey', () => {
150147
});
151148

152149
[
153-
{
154-
url: endPointPath,
155-
statusCode: 400,
156-
mockedError: 'bad request',
157-
expectedError: 'bad request',
158-
},
159-
{ url: endPointPath, statusCode: 404, mockedError: 'not found', expectedError: 'not found' },
160-
{ url: endPointPath, statusCode: 409, mockedError: 'conflict', expectedError: 'conflict' },
161-
{
162-
url: endPointPath,
163-
statusCode: 500,
164-
mockedError: 'internal error',
165-
expectedError: 'internal error',
166-
},
167-
].forEach(({ url, statusCode, mockedError, expectedError }) => {
150+
{ url: endPointPath, statusCode: 400, mockedError: 'bad request' },
151+
{ url: endPointPath, statusCode: 404, mockedError: 'not found' },
152+
{ url: endPointPath, statusCode: 409, mockedError: 'conflict' },
153+
{ url: endPointPath, statusCode: 500, mockedError: 'internal error' },
154+
].forEach(({ url, statusCode, mockedError }) => {
168155
it(`should bubble up ${statusCode} errors`, async () => {
169156
const nockMocked = nock(keyProviderUrl)
170157
.post(url)
171158
.reply(statusCode, { message: mockedError })
172159
.persist();
173-
await client.generateKey(params).should.be.rejectedWith(expectedError);
160+
await client.generateKey(params).should.be.rejectedWith(new RegExp(mockedError));
174161
nockMocked.done();
175162
});
176163
});
@@ -222,17 +209,17 @@ describe('KeyProviderClient.sign', () => {
222209
});
223210

224211
[
225-
{ statusCode: 400, mockedError: 'bad request', expectedError: 'bad request' },
226-
{ statusCode: 404, mockedError: 'not found', expectedError: 'not found' },
227-
{ statusCode: 409, mockedError: 'conflict', expectedError: 'conflict' },
228-
{ statusCode: 500, mockedError: 'internal error', expectedError: 'internal error' },
229-
].forEach(({ statusCode, mockedError, expectedError }) => {
212+
{ statusCode: 400, mockedError: 'bad request' },
213+
{ statusCode: 404, mockedError: 'not found' },
214+
{ statusCode: 409, mockedError: 'conflict' },
215+
{ statusCode: 500, mockedError: 'internal error' },
216+
].forEach(({ statusCode, mockedError }) => {
230217
it(`should bubble up ${statusCode} errors`, async () => {
231218
const nockMocked = nock(keyProviderUrl)
232219
.post(endPointPath)
233220
.reply(statusCode, { message: mockedError })
234221
.persist();
235-
await client.sign(params).should.be.rejectedWith(expectedError);
222+
await client.sign(params).should.be.rejectedWith(new RegExp(mockedError));
236223
nockMocked.done();
237224
});
238225
});

0 commit comments

Comments
 (0)