Skip to content

Commit

Permalink
Adds more tests, follow-up from #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Oct 21, 2018
1 parent 5de4146 commit 488f8e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Helps enforce type safety and adherence to the following TypeScript/Relay conven
- `QueryRenderer` components must include type parameters (includes fix).
- `QueryRenderer` components must use `graphql` tagged template strings for their `query` prop.
- calls to `commitMutation` must use `graphql` tagged template strings for their `mutation` option.
- calls to `commitMutation` must include type parameters (includes fix).
- calls to `commitMutation` must use full object literal syntax for their `mutation` option.

```json
Expand Down
46 changes: 46 additions & 0 deletions rules/relayOperationGenericsRule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,50 @@ describe("commitMutation", () => {

expect(result.length).toBe(1)
})

it("requires type parameters", () => {
const result = applyRuleToSourceText(`
commitMutation(this.props.relay.environment, {
mutation: graphql\`
mutation ConfirmBidCreateCreditCardMutation($input: CreditCardInput!) {
createCreditCard(input: $input) {
id_or_whatever
}
}
\`,
})
`)

expect(result.length).toBe(1)
})

it("has a fix for commitMutation type parameter requirement", () => {
const sourceText = dedent`
commitMutation(this.props.relay.environment, {
mutation: graphql\`
mutation ConfirmBidCreateCreditCardMutation($input: CreditCardInput!) {
createCreditCard(input: $input) {
id_or_whatever
}
}
\`,
})
`

const result = applyRuleToSourceText(sourceText)

expect(result[0].hasFix()).toBeTruthy()
expect(applyRuleFixes(sourceText, result)).toEqual(dedent`
import { ConfirmBidCreateCreditCardMutation } from "__generated__/ConfirmBidCreateCreditCardMutation.graphql"
commitMutation<ConfirmBidCreateCreditCardMutation>(this.props.relay.environment, {
mutation: graphql\`
mutation ConfirmBidCreateCreditCardMutation($input: CreditCardInput!) {
createCreditCard(input: $input) {
id_or_whatever
}
}
\`,
})
`)
})
})

0 comments on commit 488f8e8

Please sign in to comment.