Skip to content

Commit

Permalink
SingleFieldSubscriptionsRule-test: extract test schema from harness (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 9, 2021
1 parent 120758a commit d82c8e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
45 changes: 39 additions & 6 deletions src/validation/__tests__/SingleFieldSubscriptionsRule-test.ts
@@ -1,21 +1,48 @@
import { describe, it } from 'mocha';

import { buildSchema } from '../../utilities/buildASTSchema';

import { SingleFieldSubscriptionsRule } from '../rules/SingleFieldSubscriptionsRule';

import {
expectValidationErrors,
expectValidationErrorsWithSchema,
emptySchema,
} from './harness';
import { expectValidationErrorsWithSchema } from './harness';

function expectErrors(queryStr: string) {
return expectValidationErrors(SingleFieldSubscriptionsRule, queryStr);
return expectValidationErrorsWithSchema(
schema,
SingleFieldSubscriptionsRule,
queryStr,
);
}

function expectValid(queryStr: string) {
expectErrors(queryStr).to.deep.equal([]);
}

const schema = buildSchema(`
type Message {
body: String
sender: String
}
type SubscriptionRoot {
importantEmails: [String]
notImportantEmails: [String]
moreImportantEmails: [String]
spamEmails: [String]
deletedEmails: [String]
newMessage: Message
}
type QueryRoot {
dummy: String
}
schema {
query: QueryRoot
subscription: SubscriptionRoot
}
`);

describe('Validate: Subscriptions with single field', () => {
it('valid subscription', () => {
expectValid(`
Expand Down Expand Up @@ -260,6 +287,12 @@ describe('Validate: Subscriptions with single field', () => {
});

it('skips if not subscription type', () => {
const emptySchema = buildSchema(`
type Query {
dummy: String
}
`);

expectValidationErrorsWithSchema(
emptySchema,
SingleFieldSubscriptionsRule,
Expand Down
25 changes: 0 additions & 25 deletions src/validation/__tests__/harness.ts
Expand Up @@ -130,23 +130,8 @@ export const testSchema: GraphQLSchema = buildSchema(`
complicatedArgs: ComplicatedArgs
}
type Message {
body: String
sender: String
}
type SubscriptionRoot {
importantEmails: [String]
notImportantEmails: [String]
moreImportantEmails: [String]
spamEmails: [String]
deletedEmails: [String]
newMessage: Message
}
schema {
query: QueryRoot
subscription: SubscriptionRoot
}
directive @onQuery on QUERY
Expand All @@ -159,16 +144,6 @@ export const testSchema: GraphQLSchema = buildSchema(`
directive @onVariableDefinition on VARIABLE_DEFINITION
`);

export const emptySchema: GraphQLSchema = buildSchema(`
type QueryRoot {
empty: Boolean
}
schema {
query: QueryRoot
}
`);

export function expectValidationErrorsWithSchema(
schema: GraphQLSchema,
rule: ValidationRule,
Expand Down

0 comments on commit d82c8e2

Please sign in to comment.