summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/mockMang.js
blob: 5a98c6a2923eaff91f61a0ab2bd5170278fb6b8b (plain)
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
import { importSchema } from 'graphql-import';
import GraphQLMock from 'graphql-mock';
import casual from 'casual';
import PropTypes from 'prop-types';

// seed it so we get consistent results
casual.seed(123);

const typeDefs = importSchema('../backend/src/schema.graphql');

// By default graphql-mock will generate random numbers, IDs, and Strings of "Hello World"
// We can overwrite any of those if we need to

const mocks = {
  ID: () => casual.uuid,
  Item: () => ({
    title: casual.title,
    description: casual.description,
    price: () => 50000,
  }),
  User: () => ({
    email: casual.email,
    name: casual.name,
  }),
};

// Creates a mocked client
const mocked = new GraphQLMock(typeDefs, mocks);

const mountOptions = {
  context: {
    client: mocked.client,
  },
  childContextTypes: {
    client: PropTypes.object,
  },
};

export default mountOptions;