Skip to content

Commit

Permalink
Add test coverage for schema validation options.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Feb 9, 2018
1 parent bb9c68c commit 3beb355
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/type/__tests__/schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,66 @@ describe('Type System: Schema', () => {
expect(Schema.getTypeMap()).to.include.key('WrappedDirInput');
});
});

describe('Validity', () => {
describe('when not assumed valid', () => {
it('configures the schema to still needing validation', () => {
expect(
new GraphQLSchema({
assumeValid: false,
}).__validationErrors,
).to.equal(undefined);
});

it('configures the schema for allowed legacy names', () => {
expect(
new GraphQLSchema({
allowedLegacyNames: ['__badName'],
}).__allowedLegacyNames,
).to.deep.equal(['__badName']);
});

it('checks the configuration for mistakes', () => {
expect(() => new GraphQLSchema(() => null)).to.throw();
expect(() => new GraphQLSchema({ types: {} })).to.throw();
expect(() => new GraphQLSchema({ directives: {} })).to.throw();
expect(() => new GraphQLSchema({ allowedLegacyNames: {} })).to.throw();
});
});

describe('when assumed valid', () => {
it('configures the schema to have no errors', () => {
expect(
new GraphQLSchema({
assumeValid: true,
}).__validationErrors,
).to.deep.equal([]);
});

it('still configures the schema for allowed legacy names', () => {
expect(
new GraphQLSchema({
assumeValid: true,
allowedLegacyNames: ['__badName'],
}).__allowedLegacyNames,
).to.deep.equal(['__badName']);
});

it('does not check the configuration for mistakes', () => {
expect(() => {
const config = () => null;
config.assumeValid = true;
return new GraphQLSchema(config);
}).to.not.throw();
expect(() => {
return new GraphQLSchema({
assumeValid: true,
types: {},
directives: { reduce: () => [] },
allowedLegacyNames: {},
});
}).to.not.throw();
});
});
});
});

0 comments on commit 3beb355

Please sign in to comment.