Skip to content

Commit 7cbf245

Browse files
committed
chore(test): replace strings with TypeKind enum
1 parent e96612b commit 7cbf245

File tree

7 files changed

+111
-106
lines changed

7 files changed

+111
-106
lines changed

tests/functional/circular-refs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "reflect-metadata";
2-
import { IntrospectionObjectType } from "graphql";
2+
import { IntrospectionObjectType, TypeKind } from "graphql";
33

44
import { Query, ObjectType, Field } from "../../src";
55
import { MetadataStorage } from "../../src/metadata/metadata-storage";
@@ -35,9 +35,9 @@ describe("Circular references", () => {
3535
) as IntrospectionObjectType;
3636

3737
expect(circularRef1).toBeDefined();
38-
expect(circularRef1.kind).toEqual("OBJECT");
38+
expect(circularRef1.kind).toEqual(TypeKind.OBJECT);
3939
expect(circularRef2).toBeDefined();
40-
expect(circularRef2.kind).toEqual("OBJECT");
40+
expect(circularRef2.kind).toEqual(TypeKind.OBJECT);
4141
});
4242

4343
// tslint:disable-next-line:max-line-length

tests/functional/enums.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IntrospectionEnumType,
99
graphql,
1010
GraphQLSchema,
11+
TypeKind,
1112
} from "graphql";
1213

1314
import { getSchemaInfo } from "../helpers/getSchemaInfo";
@@ -99,9 +100,9 @@ describe("Enums", () => {
99100
queryType.fields.find(field => field.name === "getStringEnumValue")!,
100101
);
101102

102-
expect(getNumberEnumValueType.kind).toEqual("ENUM");
103+
expect(getNumberEnumValueType.kind).toEqual(TypeKind.ENUM);
103104
expect(getNumberEnumValueType.name).toEqual("NumberEnum");
104-
expect(getStringEnumValue.kind).toEqual("ENUM");
105+
expect(getStringEnumValue.kind).toEqual(TypeKind.ENUM);
105106
expect(getStringEnumValue.name).toEqual("StringEnum");
106107
});
107108

@@ -115,9 +116,9 @@ describe("Enums", () => {
115116
const numberEnumInputType = getInnerInputFieldType(numberEnumInput, "numberEnumField");
116117
const stringEnumInputType = getInnerInputFieldType(stringEnumInput, "stringEnumField");
117118

118-
expect(numberEnumInputType.kind).toEqual("ENUM");
119+
expect(numberEnumInputType.kind).toEqual(TypeKind.ENUM);
119120
expect(numberEnumInputType.name).toEqual("NumberEnum");
120-
expect(stringEnumInputType.kind).toEqual("ENUM");
121+
expect(stringEnumInputType.kind).toEqual(TypeKind.ENUM);
121122
expect(stringEnumInputType.name).toEqual("StringEnum");
122123
});
123124

@@ -129,9 +130,9 @@ describe("Enums", () => {
129130
queryType.fields.find(type => type.name === "isStringEnumEqualOne")!.args[0],
130131
);
131132

132-
expect(numberEnumArgType.kind).toEqual("ENUM");
133+
expect(numberEnumArgType.kind).toEqual(TypeKind.ENUM);
133134
expect(numberEnumArgType.name).toEqual("NumberEnum");
134-
expect(stringEnumArgType.kind).toEqual("ENUM");
135+
expect(stringEnumArgType.kind).toEqual(TypeKind.ENUM);
135136
expect(stringEnumArgType.name).toEqual("StringEnum");
136137
});
137138

@@ -141,7 +142,7 @@ describe("Enums", () => {
141142
) as IntrospectionEnumType;
142143

143144
expect(numberEnumType.name).toEqual("NumberEnum");
144-
expect(numberEnumType.kind).toEqual("ENUM");
145+
expect(numberEnumType.kind).toEqual(TypeKind.ENUM);
145146
expect(numberEnumType.enumValues).toHaveLength(4);
146147
expect(numberEnumType.enumValues[0].name).toEqual("One");
147148
expect(numberEnumType.enumValues[1].name).toEqual("Two");
@@ -155,7 +156,7 @@ describe("Enums", () => {
155156
) as IntrospectionEnumType;
156157

157158
expect(stringEnumType.name).toEqual("StringEnum");
158-
expect(stringEnumType.kind).toEqual("ENUM");
159+
expect(stringEnumType.kind).toEqual(TypeKind.ENUM);
159160
expect(stringEnumType.description).toEqual("custom string enum");
160161
expect(stringEnumType.enumValues).toHaveLength(3);
161162
expect(stringEnumType.enumValues[0].name).toEqual("One");

tests/functional/fields.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
IntrospectionNonNullTypeRef,
66
IntrospectionNamedTypeRef,
77
IntrospectionListTypeRef,
8+
TypeKind,
89
} from "graphql";
910

1011
import { MetadataStorage } from "../../src/metadata/metadata-storage";
@@ -159,27 +160,27 @@ describe("Fields - schema", () => {
159160
field => field.name === "implicitStringField",
160161
)!;
161162

162-
expect(implicitStringField.type.kind).toEqual("NON_NULL");
163+
expect(implicitStringField.type.kind).toEqual(TypeKind.NON_NULL);
163164
});
164165

165166
it("should generate implicit field type for scalar", async () => {
166167
const implicitStringFieldType = getInnerFieldType("implicitStringField");
167168

168-
expect(implicitStringFieldType.kind).toEqual("SCALAR");
169+
expect(implicitStringFieldType.kind).toEqual(TypeKind.SCALAR);
169170
expect(implicitStringFieldType.name).toEqual("String");
170171
});
171172

172173
it("should generate explicit field type for scalar", async () => {
173174
const explicitStringFieldType = getInnerFieldType("explicitStringField");
174175

175-
expect(explicitStringFieldType.kind).toEqual("SCALAR");
176+
expect(explicitStringFieldType.kind).toEqual(TypeKind.SCALAR);
176177
expect(explicitStringFieldType.name).toEqual("String");
177178
});
178179

179180
it("should generate implicit field type for object type", async () => {
180181
const implicitObjectFieldType = getInnerFieldType("implicitObjectField");
181182

182-
expect(implicitObjectFieldType.kind).toEqual("OBJECT");
183+
expect(implicitObjectFieldType.kind).toEqual(TypeKind.OBJECT);
183184
expect(implicitObjectFieldType.name).toEqual("SampleNestedObject");
184185
});
185186

@@ -191,7 +192,7 @@ describe("Fields - schema", () => {
191192
const implicitNullableStringFieldType =
192193
implicitNullableStringField.type as IntrospectionNamedTypeRef;
193194

194-
expect(implicitNullableStringFieldType.kind).toEqual("SCALAR");
195+
expect(implicitNullableStringFieldType.kind).toEqual(TypeKind.SCALAR);
195196
expect(implicitNullableStringFieldType.name).toEqual("String");
196197
});
197198

@@ -203,7 +204,7 @@ describe("Fields - schema", () => {
203204
const explicitNullableStringFieldType =
204205
explicitNullableStringField.type as IntrospectionNamedTypeRef;
205206

206-
expect(explicitNullableStringFieldType.kind).toEqual("SCALAR");
207+
expect(explicitNullableStringFieldType.kind).toEqual(TypeKind.SCALAR);
207208
expect(explicitNullableStringFieldType.name).toEqual("String");
208209
});
209210

@@ -216,10 +217,10 @@ describe("Fields - schema", () => {
216217
const arrayItemNonNullFieldType = arrayFieldType.ofType as IntrospectionNonNullTypeRef;
217218
const arrayItemFieldType = arrayItemNonNullFieldType.ofType as IntrospectionNamedTypeRef;
218219

219-
expect(nonNullFieldType.kind).toEqual("NON_NULL");
220-
expect(arrayFieldType.kind).toEqual("LIST");
221-
expect(arrayItemNonNullFieldType.kind).toEqual("NON_NULL");
222-
expect(arrayItemFieldType.kind).toEqual("SCALAR");
220+
expect(nonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
221+
expect(arrayFieldType.kind).toEqual(TypeKind.LIST);
222+
expect(arrayItemNonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
223+
expect(arrayItemFieldType.kind).toEqual(TypeKind.SCALAR);
223224
expect(arrayItemFieldType.name).toEqual("String");
224225
});
225226

@@ -232,10 +233,10 @@ describe("Fields - schema", () => {
232233
const arrayItemNonNullFieldType = arrayFieldType.ofType as IntrospectionNonNullTypeRef;
233234
const arrayItemFieldType = arrayItemNonNullFieldType.ofType as IntrospectionNamedTypeRef;
234235

235-
expect(nonNullFieldType.kind).toEqual("NON_NULL");
236-
expect(arrayFieldType.kind).toEqual("LIST");
237-
expect(arrayItemNonNullFieldType.kind).toEqual("NON_NULL");
238-
expect(arrayItemFieldType.kind).toEqual("SCALAR");
236+
expect(nonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
237+
expect(arrayFieldType.kind).toEqual(TypeKind.LIST);
238+
expect(arrayItemNonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
239+
expect(arrayItemFieldType.kind).toEqual(TypeKind.SCALAR);
239240
expect(arrayItemFieldType.name).toEqual("String");
240241
});
241242

@@ -245,9 +246,9 @@ describe("Fields - schema", () => {
245246
const arrayItemNonNullFieldType = arrayFieldType.ofType as IntrospectionNonNullTypeRef;
246247
const arrayItemFieldType = arrayItemNonNullFieldType.ofType as IntrospectionNamedTypeRef;
247248

248-
expect(arrayFieldType.kind).toEqual("LIST");
249-
expect(arrayItemNonNullFieldType.kind).toEqual("NON_NULL");
250-
expect(arrayItemFieldType.kind).toEqual("SCALAR");
249+
expect(arrayFieldType.kind).toEqual(TypeKind.LIST);
250+
expect(arrayItemNonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
251+
expect(arrayItemFieldType.kind).toEqual(TypeKind.SCALAR);
251252
expect(arrayItemFieldType.name).toEqual("String");
252253
});
253254

@@ -259,9 +260,9 @@ describe("Fields - schema", () => {
259260
const arrayItemNonNullFieldType = arrayFieldType.ofType as IntrospectionNonNullTypeRef;
260261
const arrayItemFieldType = arrayItemNonNullFieldType.ofType as IntrospectionNamedTypeRef;
261262

262-
expect(arrayFieldType.kind).toEqual("LIST");
263-
expect(arrayItemNonNullFieldType.kind).toEqual("NON_NULL");
264-
expect(arrayItemFieldType.kind).toEqual("SCALAR");
263+
expect(arrayFieldType.kind).toEqual(TypeKind.LIST);
264+
expect(arrayItemNonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
265+
expect(arrayItemFieldType.kind).toEqual(TypeKind.SCALAR);
265266
expect(arrayItemFieldType.name).toEqual("String");
266267
});
267268

@@ -274,9 +275,9 @@ describe("Fields - schema", () => {
274275
const arrayItemNonNullFieldType = arrayFieldType.ofType as IntrospectionNonNullTypeRef;
275276
const arrayItemFieldType = arrayItemNonNullFieldType.ofType as IntrospectionNamedTypeRef;
276277

277-
expect(arrayFieldType.kind).toEqual("LIST");
278-
expect(arrayItemNonNullFieldType.kind).toEqual("NON_NULL");
279-
expect(arrayItemFieldType.kind).toEqual("OBJECT");
278+
expect(arrayFieldType.kind).toEqual(TypeKind.LIST);
279+
expect(arrayItemNonNullFieldType.kind).toEqual(TypeKind.NON_NULL);
280+
expect(arrayItemFieldType.kind).toEqual(TypeKind.OBJECT);
280281
expect(arrayItemFieldType.name).toEqual("SampleNestedObject");
281282
});
282283
});

tests/functional/interfaces-and-inheritance.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IntrospectionInputObjectType,
99
GraphQLSchema,
1010
graphql,
11+
TypeKind,
1112
} from "graphql";
1213

1314
import { getSchemaInfo } from "../helpers/getSchemaInfo";
@@ -167,7 +168,7 @@ describe("Intefaces and inheritance", () => {
167168

168169
it("should generate interface type correctly", async () => {
169170
expect(sampleInterface1Type).toBeDefined();
170-
expect(sampleInterface1Type.kind).toEqual("INTERFACE");
171+
expect(sampleInterface1Type.kind).toEqual(TypeKind.INTERFACE);
171172
expect(sampleInterface1Type.fields).toHaveLength(2);
172173

173174
const idFieldType = getInnerFieldType(sampleInterface1Type, "id");
@@ -182,7 +183,7 @@ describe("Intefaces and inheritance", () => {
182183
type => type.name === "SampleInterfaceExtending1",
183184
) as IntrospectionInterfaceType;
184185
expect(sampleInterfaceExtending1).toBeDefined();
185-
expect(sampleInterfaceExtending1.kind).toEqual("INTERFACE");
186+
expect(sampleInterfaceExtending1.kind).toEqual(TypeKind.INTERFACE);
186187
expect(sampleInterfaceExtending1.fields).toHaveLength(3);
187188

188189
const idFieldType = getInnerFieldType(sampleInterfaceExtending1, "id");
@@ -214,7 +215,7 @@ describe("Intefaces and inheritance", () => {
214215
expect(idFieldType.name).toEqual("ID");
215216
expect(interfaceStringField.name).toEqual("String");
216217
expect(ownField2.name).toEqual("Float");
217-
expect(implementedInterfaceInfo.kind).toEqual("INTERFACE");
218+
expect(implementedInterfaceInfo.kind).toEqual(TypeKind.INTERFACE);
218219
});
219220

220221
it("should generate object type implicitly implementing interface correctly", async () => {
@@ -234,7 +235,7 @@ describe("Intefaces and inheritance", () => {
234235
expect(idFieldType.name).toEqual("ID");
235236
expect(interfaceStringField1.name).toEqual("String");
236237
expect(ownField1.name).toEqual("Float");
237-
expect(implementedInterfaceInfo.kind).toEqual("INTERFACE");
238+
expect(implementedInterfaceInfo.kind).toEqual(TypeKind.INTERFACE);
238239
});
239240

240241
it("should generate object type extending other object type correctly", async () => {
@@ -267,7 +268,7 @@ describe("Intefaces and inheritance", () => {
267268
)!;
268269

269270
expect(implementedInterfaceInfo).toBeDefined();
270-
expect(implementedInterfaceInfo.kind).toEqual("INTERFACE");
271+
expect(implementedInterfaceInfo.kind).toEqual(TypeKind.INTERFACE);
271272
});
272273

273274
// tslint:disable-next-line:max-line-length

0 commit comments

Comments
 (0)