kandimat/redaktions-app/src/backend/queries/category.mock.ts
2021-01-09 12:49:28 +01:00

75 lines
1.3 KiB
TypeScript

import { MockedResponse } from "@apollo/client/testing";
import {
BasicCategoryResponse,
GET_ALL_CATEGORIES,
GET_CATEGORY_BY_ID,
GetAllCategoriesResponse,
GetCategoryByIdResponse,
} from "./category";
export const categoryNodesMock: Array<BasicCategoryResponse> = [
{
id: "c1",
rowId: 1,
title: "Category 1",
description: "Further information for C1",
__typename: "Category",
},
{
id: "c2",
rowId: 2,
title: "Category 2",
description: "Further information for C2",
__typename: "Category",
},
];
export const getAllCategoriesMock: Array<
MockedResponse<GetAllCategoriesResponse>
> = [
{
request: {
query: GET_ALL_CATEGORIES,
},
result: {
data: {
allCategories: {
nodes: categoryNodesMock,
__typename: "CategoriesConnection",
},
},
},
},
];
export const getCategoryByIdMock: Array<
MockedResponse<GetCategoryByIdResponse>
> = [
...categoryNodesMock.map((c) => ({
request: {
query: GET_CATEGORY_BY_ID,
variables: {
id: c.id,
},
},
result: {
data: {
category: c,
},
},
})),
{
request: {
query: GET_CATEGORY_BY_ID,
variables: {
id: "",
},
},
result: {
data: {
category: null,
},
},
},
];