saleor-dashboard/testUtils/api.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

import { ApolloClient, InMemoryCache } from "@apollo/client";
import { BatchHttpLink } from "@apollo/client/link/batch-http";
import { getApiUrl } from "@dashboard/config";
2020-07-20 10:05:47 +00:00
import NodeHttpAdapter from "@pollyjs/adapter-node-http";
import FSPersister from "@pollyjs/persister-fs";
import { createFetch } from "@saleor/sdk";
2020-07-20 10:05:47 +00:00
import path from "path";
import { setupPolly } from "setup-polly-jest";
function setupApi() {
setupPolly({
adapters: [NodeHttpAdapter],
matchRequestsBy: {
headers: false,
url: {
hash: false,
hostname: false,
password: false,
pathname: false,
port: false,
protocol: false,
query: false,
username: false,
},
},
persister: FSPersister,
2020-07-20 10:05:47 +00:00
persisterOptions: {
fs: {
recordingsDir: path.resolve(__dirname, "../recordings"),
},
},
2020-07-20 10:05:47 +00:00
});
const cache = new InMemoryCache();
const link = new BatchHttpLink({
fetch: createFetch(),
uri: getApiUrl(),
2020-07-20 10:05:47 +00:00
});
const apolloClient = new ApolloClient({
cache,
link,
2020-07-20 10:05:47 +00:00
});
return apolloClient;
}
export default setupApi;