134 lines
3.2 KiB
TypeScript
134 lines
3.2 KiB
TypeScript
import { MockedResponse } from "@apollo/client/testing";
|
|
import {
|
|
AnswerPositionResponse,
|
|
FullAnswerResponse,
|
|
GET_ALL_QUESTION_ANSWERS,
|
|
GET_ANSWER_BY_QUESTION_AND_PERSON,
|
|
GetAllQuestionAnswersResponse,
|
|
GetAllQuestionAnswersVariables,
|
|
GetAnswerByQuestionAndPersonResponse,
|
|
GetAnswerByQuestionAndPersonVariables,
|
|
QuestionAnswerResponse,
|
|
} from "./answer";
|
|
import { CandidatePosition } from "../../components/CandidatePositionLegend";
|
|
|
|
export const answersMock: Array<FullAnswerResponse> = [
|
|
{
|
|
id: "a12",
|
|
text: null,
|
|
position: CandidatePosition.neutral,
|
|
questionRowId: 1,
|
|
personRowId: 2,
|
|
__typename: "Answer",
|
|
},
|
|
{
|
|
id: "a22",
|
|
text: "Answer 2",
|
|
position: CandidatePosition.positive,
|
|
questionRowId: 2,
|
|
personRowId: 2,
|
|
__typename: "Answer",
|
|
},
|
|
];
|
|
|
|
const getAnswersForQuestionRowId = (
|
|
questionRowId: number
|
|
): Array<FullAnswerResponse> => {
|
|
return answersMock.filter((answ) => answ.questionRowId === questionRowId);
|
|
};
|
|
|
|
const getAnswersPositionForQuestionRowId = (
|
|
questionRowId: number
|
|
): Array<AnswerPositionResponse> => {
|
|
return getAnswersForQuestionRowId(questionRowId).map((answer) => ({
|
|
__typename: answer.__typename,
|
|
id: answer.id,
|
|
position: answer.position,
|
|
}));
|
|
};
|
|
|
|
export const questionAnswersMock: Array<QuestionAnswerResponse> = [
|
|
{
|
|
id: "q1",
|
|
rowId: 1,
|
|
title: "Question 1?",
|
|
description: "Further information for Q1",
|
|
categoryByCategoryRowId: {
|
|
id: "c1",
|
|
rowId: 1,
|
|
title: "Category 1",
|
|
__typename: "Category",
|
|
},
|
|
answersByQuestionRowId: {
|
|
nodes: getAnswersPositionForQuestionRowId(1),
|
|
__typename: "AnswersConnection",
|
|
},
|
|
__typename: "Question",
|
|
},
|
|
{
|
|
id: "q2",
|
|
rowId: 2,
|
|
title: "Question 2?",
|
|
description: "Further information for Q2",
|
|
categoryByCategoryRowId: null,
|
|
answersByQuestionRowId: {
|
|
nodes: getAnswersPositionForQuestionRowId(2),
|
|
__typename: "AnswersConnection",
|
|
},
|
|
__typename: "Question",
|
|
},
|
|
{
|
|
id: "q3",
|
|
rowId: 3,
|
|
title: "Question 3?",
|
|
description: null,
|
|
categoryByCategoryRowId: null,
|
|
answersByQuestionRowId: {
|
|
nodes: getAnswersPositionForQuestionRowId(3),
|
|
__typename: "AnswersConnection",
|
|
},
|
|
__typename: "Question",
|
|
},
|
|
];
|
|
|
|
export const getAllQuestionAnswersMock: Array<
|
|
MockedResponse<GetAllQuestionAnswersResponse>
|
|
> = [
|
|
{
|
|
request: {
|
|
query: GET_ALL_QUESTION_ANSWERS,
|
|
variables: {
|
|
personRowId: 2,
|
|
} as GetAllQuestionAnswersVariables,
|
|
},
|
|
result: {
|
|
data: {
|
|
allQuestions: {
|
|
nodes: questionAnswersMock,
|
|
__typename: "QuestionsConnection",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
export const getAnswerByQuestionAndPersonMock: Array<
|
|
MockedResponse<GetAnswerByQuestionAndPersonResponse>
|
|
> = [
|
|
...questionAnswersMock.map((q, index) => ({
|
|
request: {
|
|
query: GET_ANSWER_BY_QUESTION_AND_PERSON,
|
|
variables: {
|
|
personRowId: 2,
|
|
questionRowId: index + 1,
|
|
} as GetAnswerByQuestionAndPersonVariables,
|
|
},
|
|
result: {
|
|
data: {
|
|
answerByQuestionRowIdAndPersonRowId:
|
|
getAnswersForQuestionRowId(index + 1)[0] || null,
|
|
},
|
|
},
|
|
})),
|
|
];
|