|
| 1 | +/** |
| 2 | + * Copyright (c) 2015, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +import { describe, it } from 'mocha'; |
| 11 | +import { expectPassesRule, expectFailsRule } from './harness'; |
| 12 | +import { |
| 13 | + SingleFieldSubscriptions, |
| 14 | + singleFieldOnlyMessage, |
| 15 | +} from '../rules/SingleFieldSubscriptions'; |
| 16 | + |
| 17 | + |
| 18 | +describe('Validate: Subscriptions with single field', () => { |
| 19 | + |
| 20 | + it('valid subscription', () => { |
| 21 | + expectPassesRule(SingleFieldSubscriptions, ` |
| 22 | + subscription ImportantEmails { |
| 23 | + importantEmails |
| 24 | + } |
| 25 | + `); |
| 26 | + }); |
| 27 | + |
| 28 | + it('fails with more than one root field', () => { |
| 29 | + expectFailsRule(SingleFieldSubscriptions, ` |
| 30 | + subscription ImportantEmails { |
| 31 | + importantEmails |
| 32 | + notImportantEmails |
| 33 | + } |
| 34 | + `, [ { |
| 35 | + message: singleFieldOnlyMessage('ImportantEmails'), |
| 36 | + locations: [ { line: 4, column: 9 } ], |
| 37 | + path: undefined, |
| 38 | + } ]); |
| 39 | + }); |
| 40 | + |
| 41 | + it('fails with more than one root field including introspection', () => { |
| 42 | + expectFailsRule(SingleFieldSubscriptions, ` |
| 43 | + subscription ImportantEmails { |
| 44 | + importantEmails |
| 45 | + __typename |
| 46 | + } |
| 47 | + `, [ { |
| 48 | + message: singleFieldOnlyMessage('ImportantEmails'), |
| 49 | + locations: [ { line: 4, column: 9 } ], |
| 50 | + path: undefined, |
| 51 | + } ]); |
| 52 | + }); |
| 53 | + |
| 54 | + it('fails with many more than one root field', () => { |
| 55 | + expectFailsRule(SingleFieldSubscriptions, ` |
| 56 | + subscription ImportantEmails { |
| 57 | + importantEmails |
| 58 | + notImportantEmails |
| 59 | + spamEmails |
| 60 | + } |
| 61 | + `, [ { |
| 62 | + message: singleFieldOnlyMessage('ImportantEmails'), |
| 63 | + locations: [ { line: 4, column: 9 }, { line: 5, column: 9 } ], |
| 64 | + path: undefined, |
| 65 | + } ]); |
| 66 | + }); |
| 67 | + |
| 68 | + it('fails with more than one root field in anonymous subscriptions', () => { |
| 69 | + expectFailsRule(SingleFieldSubscriptions, ` |
| 70 | + subscription { |
| 71 | + importantEmails |
| 72 | + notImportantEmails |
| 73 | + } |
| 74 | + `, [ { |
| 75 | + message: singleFieldOnlyMessage(null), |
| 76 | + locations: [ { line: 4, column: 9 } ], |
| 77 | + path: undefined, |
| 78 | + } ]); |
| 79 | + }); |
| 80 | + |
| 81 | +}); |
0 commit comments