Skip to content

Commit 3fd0274

Browse files
committed
test: add github-issue-157
1 parent 0e7df23 commit 3fd0274

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* @flow */
2+
/* eslint-disable no-await-in-loop */
3+
4+
import mongoose from 'mongoose';
5+
import MongodbMemoryServer from 'mongodb-memory-server';
6+
import { EnumTypeComposer, graphql } from 'graphql-compose';
7+
import { composeWithMongoose } from '../../index';
8+
9+
let mongoServer;
10+
beforeAll(async () => {
11+
mongoServer = new MongodbMemoryServer();
12+
const mongoUri = await mongoServer.getConnectionString();
13+
await mongoose.connect(
14+
mongoUri,
15+
{ useNewUrlParser: true }
16+
);
17+
// mongoose.set('debug', true);
18+
});
19+
20+
afterAll(() => {
21+
mongoose.disconnect();
22+
mongoServer.stop();
23+
});
24+
25+
// May require additional time for downloading MongoDB binaries
26+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
27+
28+
describe('issue #157 - Optional enum error', () => {
29+
const Visit = mongoose.model(
30+
'visit',
31+
new mongoose.Schema({
32+
url: { type: String, required: true },
33+
referredBy: { type: String, enum: ['WEBSITE', 'NEWSPAPER'] },
34+
})
35+
);
36+
37+
it('check ', async () => {
38+
const VisitTC = composeWithMongoose(Visit);
39+
40+
const referredBy: any = VisitTC.getFieldType('referredBy');
41+
expect(referredBy).toBeInstanceOf(graphql.GraphQLEnumType);
42+
const etc = EnumTypeComposer.create(referredBy);
43+
expect(etc.getFieldNames()).toEqual(['WEBSITE', 'NEWSPAPER']);
44+
45+
etc.addFields({
46+
EMPTY_STRING: { value: '' },
47+
NULL: { value: null },
48+
});
49+
expect(etc.getFieldNames()).toEqual(['WEBSITE', 'NEWSPAPER', 'EMPTY_STRING', 'NULL']);
50+
});
51+
});

0 commit comments

Comments
 (0)