101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import {MockedResponse} from "@apollo/client/testing";
|
|
import {
|
|
ADD_CATEGORY, AddCategoryResponse,
|
|
AddCategoryVariables, DELETE_CATEGORY, DeleteCategoryPayload, DeleteCategoryResponse, DeleteCategoryVariables,
|
|
EDIT_CATEGORY, EditCategoryPayload,
|
|
EditCategoryResponse,
|
|
EditCategoryVariables
|
|
} from "./category";
|
|
import {BasicCategoryResponse} from "../queries/category";
|
|
import {categoryNodesMock} from "../queries/category.mock";
|
|
|
|
|
|
const editCategoryVariables: EditCategoryVariables = {
|
|
id: 'c1',
|
|
title: 'New title for Category 1',
|
|
description: 'Further information for C1',
|
|
};
|
|
|
|
const getEditedCategoryMock = (): EditCategoryPayload | null => {
|
|
const originalCategory = categoryNodesMock.find(c => c.id === editCategoryVariables.id)
|
|
return originalCategory ? {
|
|
category: {
|
|
...originalCategory,
|
|
title: editCategoryVariables.title === undefined ? originalCategory.title : editCategoryVariables.title,
|
|
description: editCategoryVariables.description === undefined ? originalCategory.description : null,
|
|
},
|
|
__typename: "UpdateCategoryPayload",
|
|
} : null
|
|
}
|
|
|
|
export const editCategoryMock: Array<MockedResponse<EditCategoryResponse>> = [
|
|
{
|
|
request: {
|
|
query: EDIT_CATEGORY,
|
|
variables: editCategoryVariables,
|
|
},
|
|
result: {
|
|
data: {
|
|
updateCategory: getEditedCategoryMock(),
|
|
}
|
|
},
|
|
},
|
|
]
|
|
|
|
const addCategoryVariables: AddCategoryVariables = {
|
|
title: 'New category',
|
|
description: "",
|
|
};
|
|
|
|
const addedCategoryMock: BasicCategoryResponse = {
|
|
id: `newC`,
|
|
rowId: 3,
|
|
title: addCategoryVariables.title as string,
|
|
description: addCategoryVariables.description as string,
|
|
__typename: "Category"
|
|
}
|
|
|
|
export const addCategoryMock: Array<MockedResponse<AddCategoryResponse>> = [
|
|
{
|
|
request: {
|
|
query: ADD_CATEGORY,
|
|
variables: addCategoryVariables,
|
|
},
|
|
result: {
|
|
data: {
|
|
createCategory: {
|
|
category: addedCategoryMock,
|
|
__typename: "CreateCategoryPayload",
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
|
|
const deleteCategoryVariables: DeleteCategoryVariables = {
|
|
id: 'c2'
|
|
};
|
|
|
|
const getDeletedCategoryMock = (): DeleteCategoryPayload | null => {
|
|
const categoryToBeDeleted = categoryNodesMock.find(q => q.id === deleteCategoryVariables.id)
|
|
return categoryToBeDeleted ? {
|
|
category: categoryToBeDeleted,
|
|
__typename: "DeleteCategoryPayload",
|
|
} : null
|
|
}
|
|
|
|
export const deleteCategoryMock: Array<MockedResponse<DeleteCategoryResponse>> = [
|
|
{
|
|
request: {
|
|
query: DELETE_CATEGORY,
|
|
variables: deleteCategoryVariables,
|
|
},
|
|
result: {
|
|
data: {
|
|
deleteCategory: getDeletedCategoryMock(),
|
|
}
|
|
},
|
|
},
|
|
]
|
|
|