2021-01-29 00:20:46 +05:30
|
|
|
const defaultPageInfo = {
|
|
|
|
hasNextPage: false,
|
|
|
|
hasPreviousPage: false,
|
|
|
|
startCursor: null,
|
|
|
|
endCursor: null,
|
|
|
|
};
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
export const mockApolloResponse = ({ hasNextPage = false, key, data }) => ({
|
|
|
|
data: {
|
|
|
|
[key]: {
|
|
|
|
pageInfo: { ...defaultPageInfo, hasNextPage },
|
|
|
|
nodes: data,
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const mockQueryResponse = ({ key, data = [], loading = false, additionalData = [] }) => {
|
|
|
|
const hasNextPage = Boolean(additionalData.length);
|
|
|
|
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);
|
|
|
|
};
|