Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Nov 21, 2024
1 parent 8ca3240 commit bc39ee0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 62 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildAmplifyConfig,
mockedGenerateClient,
optionsAndHeaders,
expectGraphqlMatches,
} from '../../utils';

const sampleTodo = {
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('Manipulated MIS cannot be used to call the wrong model', () => {
jest.clearAllMocks();
});

test('create an item', async () => {
test('create performs operation against intended model', async () => {
// #region mocking
const { spy, generateClient } = mockedGenerateClient([
{
Expand All @@ -69,13 +70,18 @@ describe('Manipulated MIS cannot be used to call the wrong model', () => {
// #endregion

// #region assertions
expect(optionsAndHeaders(spy)).toMatchSnapshot();
expectGraphqlMatches(
optionsAndHeaders(spy)[0][0].query,
`mutation($input: CreateTodoInput!) {
createTodo(input: $input) { id content createdAt updatedAt }
}`,
);
expect(errors).toBeUndefined();
expect(newTodo).toEqual(sampleTodo);
// #endregion assertions
});

test('update an item', async () => {
test('update performs operation against intended model', async () => {
// #region mocking
const { spy, generateClient } = mockedGenerateClient([
{
Expand All @@ -99,13 +105,18 @@ describe('Manipulated MIS cannot be used to call the wrong model', () => {
// #endregion

// #region assertions
expect(optionsAndHeaders(spy)).toMatchSnapshot();
expectGraphqlMatches(
optionsAndHeaders(spy)[0][0].query,
`mutation($input: UpdateTodoInput!) {
updateTodo(input: $input) { id content createdAt updatedAt }
}`,
);
expect(errors).toBeUndefined();
expect(updatedTodo).toEqual(sampleTodo);
// #endregion assertions
});

test('delete an item', async () => {
test('delete performs operation against intended model', async () => {
// #region mocking
const { spy, generateClient } = mockedGenerateClient([
{
Expand All @@ -131,7 +142,12 @@ describe('Manipulated MIS cannot be used to call the wrong model', () => {
// #endregion

// #region assertions
expect(optionsAndHeaders(spy)).toMatchSnapshot();
expectGraphqlMatches(
optionsAndHeaders(spy)[0][0].query,
`mutation($input: DeleteTodoInput!) {
deleteTodo(input: $input) { id content createdAt updatedAt }
}`,
);
expect(errors).toBeUndefined();
expect(deletedTodo).toEqual(sampleTodo);
// #endregion assertions
Expand Down

0 comments on commit bc39ee0

Please sign in to comment.