-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheventListMocks.ts
More file actions
130 lines (119 loc) · 3.37 KB
/
Copy patheventListMocks.ts
File metadata and controls
130 lines (119 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type { FetchResult, GraphQLRequest } from '@apollo/client';
import type { MockedResponse } from '@apollo/client/testing';
import type {
EventListQueryVariables,
EventListResponse,
EventType,
QueryEventListArgs,
} from '@events-helsinki/components';
import {
EVENT_SEARCH_FILTERS,
EventListDocument,
EventTypeId,
HELSINKI_OCD_DIVISION_ID,
} from '@events-helsinki/components';
import AppConfig from '../../../src/domain/app/AppConfig';
export const baseVariables = {
audienceMinAgeLt: '',
audienceMaxAgeGt: '',
suitableFor: [],
end: '',
include: ['keywords', 'location'],
isFree: undefined,
keywordAnd: [],
keywordNot: [],
location: [],
pageSize: 10,
publisher: null,
sort: 'end_time',
start: 'now',
startsAfter: undefined,
// Always filter with HELSINKI_OCD_DIVISION_ID to limit the results to city of Helsinki events.
[EVENT_SEARCH_FILTERS.DIVISIONS]: [HELSINKI_OCD_DIVISION_ID],
// Removed to experiment:
// LIIKUNTA-512 (https://helsinkisolutionoffice.atlassian.net/browse/LIIKUNTA-512).
// superEventType: ['umbrella', 'none'],
// Added for courses in LIIKUNTA-512 (https://helsinkisolutionoffice.atlassian.net/browse/LIIKUNTA-512).
superEvent: 'none',
[EVENT_SEARCH_FILTERS.ONGOING]: true,
};
export const eventListBaseVariables: QueryEventListArgs = {
...baseVariables,
keywordOrSet2: [],
keywordOrSet3: [],
};
export const getOtherEventsVariables = (
superEvent: EventListQueryVariables['superEvent']
): EventListQueryVariables => ({
include: ['in_language', 'keywords', 'location', 'audience'],
sort: 'end_time',
start: 'now',
superEvent,
eventType: AppConfig.supportedEventTypes,
});
const createRequest = (
type: EventType = 'course',
variablesOverride: EventListQueryVariables = {}
): GraphQLRequest => ({
query: EventListDocument,
variables: {
...eventListBaseVariables,
...variablesOverride,
eventType: type === 'event' ? [EventTypeId.General] : [EventTypeId.Course],
},
});
const createResult = (
expectedResponse: EventListResponse | undefined
): FetchResult => ({
data: {
eventList: expectedResponse,
},
});
export type EventListMockArguments = {
type?: EventType;
superEventId?: EventListQueryVariables['superEvent'];
variables?: EventListQueryVariables;
response?: EventListResponse;
};
export const createEventListRequestAndResultMocks = ({
type = 'course',
variables = {},
response,
}: EventListMockArguments): MockedResponse => ({
request: createRequest(type, variables),
result: createResult(response),
});
export const createEventListRequestThrowsErrorMocks = ({
type = 'course',
variables = {},
}: EventListMockArguments = {}): MockedResponse => ({
request: createRequest(type, variables),
error: new Error('not found'),
});
export const createOtherEventTimesRequestAndResultMocks = ({
superEventId,
variables,
response,
}: EventListMockArguments): MockedResponse => ({
request: {
query: EventListDocument,
variables: {
...getOtherEventsVariables(superEventId),
...variables,
},
},
result: createResult(response),
});
export const createOtherEventTimesRequestThrowsErrorMocks = ({
superEventId,
variables,
}: EventListMockArguments): MockedResponse => ({
request: {
query: EventListDocument,
variables: {
...getOtherEventsVariables(superEventId),
...variables,
},
},
error: new Error('not found'),
});