From a3f2b820739d9c3c5a523cc52cfcf445936811b4 Mon Sep 17 00:00:00 2001 From: William Chargin Date: Tue, 12 Jun 2018 14:09:58 -0700 Subject: [PATCH] Add snapshot test for GitHub GraphQL query (#382) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This has two primary benefits: - Humans can look at this snapshot file to see what’s being queried, or to manually issue a query. - When we change the programmatically generated query, we can easily see what the results are in the GraphQL output. This makes it easy to verify that a change is correct. Test Plan: None. wchargin-branch: snapshot-query --- .../github/__snapshots__/graphql.test.js.snap | 125 ++++++++++++++++++ src/v3/plugins/github/graphql.test.js | 8 +- 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/v3/plugins/github/__snapshots__/graphql.test.js.snap b/src/v3/plugins/github/__snapshots__/graphql.test.js.snap index f0d61f9..c805639 100644 --- a/src/v3/plugins/github/__snapshots__/graphql.test.js.snap +++ b/src/v3/plugins/github/__snapshots__/graphql.test.js.snap @@ -200,3 +200,128 @@ Object { }, } `; + +exports[`graphql creates a query 1`] = ` +"query FetchData($repoOwner: String! $repoName: String!) { + repository(owner: $repoOwner name: $repoName) { + url + name + owner { + ...whoami + } + id + issues(first: 50) { + ...issues + } + pullRequests(first: 50) { + ...prs + } + } +} +fragment whoami on Actor { + __typename + login + url + ... on User { + id + } + ... on Organization { + id + } + ... on Bot { + id + } +} +fragment issues on IssueConnection { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + url + title + body + number + author { + ...whoami + } + comments(first: 20) { + ...comments + } + } +} +fragment prs on PullRequestConnection { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + url + title + body + number + mergeCommit { + oid + } + additions + deletions + author { + ...whoami + } + comments(first: 20) { + ...comments + } + reviews(first: 10) { + ...reviews + } + } +} +fragment comments on IssueCommentConnection { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + url + author { + ...whoami + } + body + } +} +fragment reviews on PullRequestReviewConnection { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + url + body + author { + ...whoami + } + state + comments(first: 10) { + ...reviewComments + } + } +} +fragment reviewComments on PullRequestReviewCommentConnection { + pageInfo { + hasNextPage + endCursor + } + nodes { + id + url + body + author { + ...whoami + } + } +}" +`; diff --git a/src/v3/plugins/github/graphql.test.js b/src/v3/plugins/github/graphql.test.js index c2f8915..de02ccf 100644 --- a/src/v3/plugins/github/graphql.test.js +++ b/src/v3/plugins/github/graphql.test.js @@ -1,7 +1,7 @@ // @flow import type {Continuation} from "./graphql"; -import {build} from "../../graphql/queries"; +import {build, stringify, multilineLayout} from "../../graphql/queries"; import { PAGE_LIMIT, createQuery, @@ -950,4 +950,10 @@ describe("graphql", () => { expect(result).toMatchSnapshot(); }); }); + + it("creates a query", () => { + expect( + stringify.body(createQuery(), multilineLayout(" ")) + ).toMatchSnapshot(); + }); });