Skip to content

Commit

Permalink
test: adding error testing and a nock clean
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Jun 18, 2024
1 parent 159112c commit c73067d
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions testHelpers/vonageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import { getResults } from './getResults';
*/
export const VonageTest = <T>(testDataSets: TestTuple[]) => {
describe.each<TestTuple>(testDataSets)('$label', ({ tests }) => {
test.each<SDKTestCase<T>>(tests)(
afterEach(function () {
nock.cleanAll();
});

const successTests = tests.filter(({ error }) => !error);
const failureTests = tests.filter(({ error }) => !!error);

test.each<SDKTestCase<T>>(successTests)(
'Can $label',
async ({
baseUrl,
Expand Down Expand Up @@ -42,8 +49,38 @@ export const VonageTest = <T>(testDataSets: TestTuple[]) => {

expect(results).toEqual(expected);
expect(nock.isDone()).toBeTruthy();
},
);

if (failureTests.length < 1) {
return;
}

test.each(failureTests)(
'Will throw $label',
async ({
baseUrl,
reqHeaders,
requests,
responses,
client,
clientMethod,
parameters,
}) => {
const scope = nock(baseUrl, {
reqheaders: reqHeaders,
});

requests.forEach((request, index) => {
(scope as nock.Scope)
.intercept(...request)
.reply(...responses[index]);
});

await expect(() => client[clientMethod](...parameters)).rejects.toThrow(
error,
);

expect(results).toEqual(expected);
expect(nock.isDone()).toBeTruthy();
},
);
Expand Down

0 comments on commit c73067d

Please sign in to comment.