/
population.spec.js
50 lines (41 loc) · 1.2 KB
/
population.spec.js
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
import mongoose from 'mongoose';
import { GraphQLInt, GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql';
import mongooseSchemaToGraphQL, {
generateDescriptionForSubField,
generateNameForSubField,
} from '../lib/index.min';
import { getRidOfThunks } from '../tools/util';
test('generates schemas with population usage correctly', () => {
const NAME = 'RecursiveTestSchema';
const DESCRIPTION = 'Testing';
const NothingSchema = new mongoose.Schema({
something: String,
});
const NothingType = mongooseSchemaToGraphQL({
name: 'Nothing',
description: 'just just',
schema: NothingSchema,
class: 'GraphQLObjectType',
});
const Schema = new mongoose.Schema({
whatever: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Nothing',
}],
});
const ExpectedType = getRidOfThunks(new GraphQLObjectType({
name: NAME,
description: DESCRIPTION,
fields: () => ({
whatever: { type: NothingType },
}),
}));
const ReceivedType = getRidOfThunks(mongooseSchemaToGraphQL({
name: NAME,
class: 'GraphQLObjectType',
description: DESCRIPTION,
schema: Schema,
exclude: ['_id'],
}));
expect(ReceivedType).toEqual(ExpectedType);
});