UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

93 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const generated_1 = require("../../../../graphql/generated"); const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken"); const graphqlClient_1 = require("./graphqlClient"); const getViewerQuery = (0, generated_1.graphql)(` query GetViewer { viewer { login } } `); const getRepoQuery = (0, generated_1.graphql)(` query GetRepo($repoOwner: String!, $repoName: String!) { repository(owner: $repoOwner, name: $repoName) { name } } `); describe('graphqlClient', () => { let result; describe('when the access token is invalid', () => { beforeAll(async () => { const client = (0, graphqlClient_1.getGraphQLClient)({ accessToken: 'foobar', githubApiBaseUrlV4: 'https://api.github.com/graphql', }); result = await client.query(getViewerQuery, {}); }); it('includes status code', async () => { expect(result.statusCode).toBe(401); }); it('does not include graphql errors', async () => { expect(result.error?.graphQLErrors).toEqual([]); }); it('includes error message', async () => { expect(result.error?.message).toBe('[Network] Unauthorized'); }); }); describe('when the access token is valid', () => { const accessToken = (0, getDevAccessToken_1.getDevAccessToken)(); beforeAll(async () => { const client = (0, graphqlClient_1.getGraphQLClient)({ accessToken: accessToken, githubApiBaseUrlV4: 'https://api.github.com/graphql', }); result = await client.query(getViewerQuery, {}); }); it('includes status code', async () => { expect(result.statusCode).toBe(200); }); it('includes x-oauth-scopes headers', async () => { expect(result.responseHeaders?.get('x-oauth-scopes')).toContain('repo'); }); }); describe('when repo is not found', () => { const accessToken = (0, getDevAccessToken_1.getDevAccessToken)(); beforeAll(async () => { const client = (0, graphqlClient_1.getGraphQLClient)({ accessToken: accessToken, githubApiBaseUrlV4: 'https://api.github.com/graphql', }); result = await client.query(getRepoQuery, { repoName: 'backportNonExisting', repoOwner: 'sorenlouv', }); }); it('includes status code', async () => { expect(result.statusCode).toBe(200); }); it('includes error path', async () => { expect(result.error?.graphQLErrors[0].path).toEqual(['repository']); }); it('includes error type', async () => { expect((result.error?.graphQLErrors[0]).originalError ?.type).toBe('NOT_FOUND'); }); it('includes graphql errors', async () => { expect(result.error?.graphQLErrors).toMatchInlineSnapshot(` [ [GraphQLError: Could not resolve to a Repository with the name 'sorenlouv/backportNonExisting'.], ] `); }); it('includes error message', async () => { expect(result.error?.message).toBe("[GraphQL] Could not resolve to a Repository with the name 'sorenlouv/backportNonExisting'."); }); it('includes x-oauth-scopes headers', async () => { expect(result.responseHeaders?.get('x-oauth-scopes')).toContain('repo'); }); }); }); //# sourceMappingURL=graphqlClient.private.test.js.map