Skip to content

Commit

Permalink
refactor - add method and reuse in both tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sundersc committed Sep 12, 2022
1 parent 9e767c1 commit db7411a
Showing 1 changed file with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,7 @@ describe('Invalid arguments should throw an error', () => {
{ title: 'task 1', description: 'task 1 description', priority: "invalid", dueDate: '2022-01-01T00:00:00.000Z' }, // Passing string in place of int
];

await Promise.all(
invalid_create_inputs.map(async (input) => {
try {
const createResult = await createTask(input);
expect(false).toBeTruthy();
} catch (error) {
expect(error.errors).toBeDefined();
expect(error.errors.length).toBeGreaterThanOrEqual(1);
}
}),
);
await runQueryAndExpectError(createTask, invalid_create_inputs);
});

it('list query should error on invalid filter arguments', async () => {
Expand All @@ -65,17 +55,7 @@ describe('Invalid arguments should throw an error', () => {
{ or: [ { priority: { between: [1, 2.5] } }, { title: { gt: "test" } } ] }, // Incorrect argument value for between operator with 'or' condition
];

await Promise.all(
invalid_filter_inputs.map(async (input) => {
try {
const listResult = await listTasks(input);
expect(false).toBeTruthy();
} catch (error) {
expect(error.errors).toBeDefined();
expect(error.errors.length).toBeGreaterThanOrEqual(1);
}
}),
);
await runQueryAndExpectError(listTasks, invalid_filter_inputs);
});

const createTask = async (
Expand Down Expand Up @@ -148,4 +128,18 @@ describe('Invalid arguments should throw an error', () => {
aws_appsync_apiKey: apiKey,
});
}

const runQueryAndExpectError = async (query: (input: any) => any, inputs: any[]) => {
await Promise.all(
inputs.map(async (input) => {
try {
const queryResult = await query(input);
expect(false).toBeTruthy();
} catch (error) {
expect(error.errors).toBeDefined();
expect(error.errors.length).toBeGreaterThanOrEqual(1);
}
}),
);
}
});

0 comments on commit db7411a

Please sign in to comment.