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

90 lines
1.6 KiB
TypeScript

import { MockedResponse } from "@apollo/client/testing";
import {
BasicQuestionResponse,
GET_ALL_QUESTIONS,
GET_QUESTION_BY_ID,
GetAllQuestionsResponse,
GetQuestionByIdResponse,
} from "./question";
export const questionNodesMock: Array<BasicQuestionResponse> = [
{
id: "q1",
rowId: 1,
title: "Question 1?",
description: "Further information for Q1",
categoryByCategoryRowId: {
id: "c1",
rowId: 1,
title: "Category 1",
__typename: "Category",
},
__typename: "Question",
},
{
id: "q2",
rowId: 2,
title: "Question 2?",
description: "Further information for Q2",
categoryByCategoryRowId: null,
__typename: "Question",
},
{
id: "q3",
rowId: 3,
title: "Question 3?",
description: null,
categoryByCategoryRowId: null,
__typename: "Question",
},
];
export const getAllQuestionsMock: Array<
MockedResponse<GetAllQuestionsResponse>
> = [
{
request: {
query: GET_ALL_QUESTIONS,
},
result: {
data: {
allQuestions: {
nodes: questionNodesMock,
__typename: "QuestionsConnection",
},
},
},
},
];
export const getQuestionByIdMock: Array<
MockedResponse<GetQuestionByIdResponse>
> = [
...questionNodesMock.map((q) => ({
request: {
query: GET_QUESTION_BY_ID,
variables: {
id: q.id,
},
},
result: {
data: {
question: q,
},
},
})),
{
request: {
query: GET_QUESTION_BY_ID,
variables: {
id: "",
},
},
result: {
data: {
question: null,
},
},
},
];