2020-11-02 10:08:52 -05:00
|
|
|
const defaultPageInfo = {
|
|
|
|
hasNextPage: false,
|
|
|
|
hasPreviousPage: false,
|
|
|
|
startCursor: null,
|
|
|
|
endCursor: null,
|
|
|
|
};
|
2020-10-16 14:09:04 -04:00
|
|
|
|
2020-11-06 10:09:14 -05:00
|
|
|
export const mockApolloResponse = ({ hasNextPage = false, key, data }) => ({
|
2020-11-02 10:08:52 -05:00
|
|
|
data: {
|
|
|
|
[key]: {
|
|
|
|
pageInfo: { ...defaultPageInfo, hasNextPage },
|
|
|
|
nodes: data,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-11-06 10:09:14 -05:00
|
|
|
export const mockQueryResponse = ({ key, data = [], loading = false, additionalData = [] }) => {
|
|
|
|
const hasNextPage = Boolean(additionalData.length);
|
2020-11-02 10:08:52 -05:00
|
|
|
const response = mockApolloResponse({ hasNextPage, key, data });
|
|
|
|
if (loading) {
|
|
|
|
return jest.fn().mockReturnValue(new Promise(() => {}));
|
|
|
|
}
|
|
|
|
if (hasNextPage) {
|
|
|
|
return jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValueOnce(response)
|
|
|
|
.mockResolvedValueOnce(
|
|
|
|
mockApolloResponse({
|
|
|
|
hasNextPage: false,
|
|
|
|
key,
|
|
|
|
data: additionalData,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return jest.fn().mockResolvedValue(response);
|
|
|
|
};
|