-
Notifications
You must be signed in to change notification settings - Fork 38
/
EnumField.test.ts
52 lines (41 loc) · 1.37 KB
/
EnumField.test.ts
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
51
52
import 'reflect-metadata';
import { IntrospectionEnumType, IntrospectionSchema } from 'graphql';
import { ObjectType, Query, Resolver } from 'type-graphql';
import { getSchemaInfo } from '../schema';
import { EnumField } from './EnumField';
describe('Enums', () => {
let schemaIntrospection: IntrospectionSchema;
beforeAll(async () => {
// TODO: should we set this up as part of the test harness?
// Container.set('warthog.generated-folder', process.cwd());
enum StringEnum {
Foo = 'FOO',
Bar = 'BAR'
}
@ObjectType()
class StringEnumInput {
@EnumField('StringEnum', StringEnum, { nullable: true })
stringEnumField?: StringEnum;
}
@Resolver(() => StringEnumInput)
class SampleResolver {
@Query(() => StringEnum)
getStringEnumValue(): StringEnum {
return StringEnum.Foo;
}
}
const schemaInfo = await getSchemaInfo({
resolvers: [SampleResolver]
});
schemaIntrospection = schemaInfo.schemaIntrospection;
});
describe('EnumField', () => {
test('Puts an enum in the GraphQL schema', async () => {
const myEnum = schemaIntrospection.types.find((type: any) => {
return type.kind === 'ENUM' && type.name === 'StringEnum';
}) as IntrospectionEnumType;
expect(myEnum).toBeDefined();
expect(myEnum.enumValues.length).toEqual(2);
});
});
});