From cd5c569bab2a614a829271ebeb9fa751dbd7fa6a Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Thu, 12 Jan 2023 20:25:15 +0300
Subject: [PATCH] test(graphql): Make private repo testing more explicit
 (#19803)

---
 .../github/graphql/datasource-fetcher.spec.ts | 25 +++++++++++--------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/util/github/graphql/datasource-fetcher.spec.ts b/lib/util/github/graphql/datasource-fetcher.spec.ts
index ee375eff64..673a96c0ee 100644
--- a/lib/util/github/graphql/datasource-fetcher.spec.ts
+++ b/lib/util/github/graphql/datasource-fetcher.spec.ts
@@ -52,9 +52,9 @@ const adapter: GithubGraphqlDatasourceAdapter<
 };
 
 function resp(
+  isRepoPrivate: boolean | undefined,
   nodes: TestAdapterInput[],
-  cursor: string | undefined = undefined,
-  isRepoPrivate = false
+  cursor: string | undefined = undefined
 ): GithubGraphqlResponse<GithubGraphqlRepoResponse<TestAdapterInput>> {
   const data: GithubGraphqlRepoResponse<TestAdapterInput> = {
     repository: {
@@ -112,7 +112,7 @@ describe('util/github/graphql/datasource-fetcher', () => {
       httpMock
         .scope('https://api.github.com/')
         .post('/graphql')
-        .reply(200, resp([]));
+        .reply(200, resp(false, []));
 
       const res = await Datasource.query(
         { packageName: 'foo/bar' },
@@ -205,7 +205,7 @@ describe('util/github/graphql/datasource-fetcher', () => {
         .post('/graphql')
         .reply(
           200,
-          resp([
+          resp(false, [
             { version: v3, releaseTimestamp: t3, foo: '3' },
             { version: v2, releaseTimestamp: t2, foo: '2' },
             { version: v1, releaseTimestamp: t1, foo: '1' },
@@ -227,14 +227,18 @@ describe('util/github/graphql/datasource-fetcher', () => {
 
     it('handles paginated data', async () => {
       const page1 = resp(
+        false,
         [{ version: v3, releaseTimestamp: t3, foo: '3' }],
         'aaa'
       );
       const page2 = resp(
+        false,
         [{ version: v2, releaseTimestamp: t2, foo: '2' }],
         'bbb'
       );
-      const page3 = resp([{ version: v1, releaseTimestamp: t1, foo: '1' }]);
+      const page3 = resp(false, [
+        { version: v1, releaseTimestamp: t1, foo: '1' },
+      ]);
       httpMock
         .scope('https://api.github.com/')
         .post('/graphql')
@@ -285,7 +289,7 @@ describe('util/github/graphql/datasource-fetcher', () => {
       ): GithubGraphqlResponse<GithubGraphqlRepoResponse<TestAdapterInput>>[] {
         const partitions = partitionBy(items, perPage);
         const pages = partitions.map((nodes, idx) =>
-          resp(nodes, `page-${idx + 2}`)
+          resp(false, nodes, `page-${idx + 2}`)
         );
         delete pages[pages.length - 1].data?.repository.payload.pageInfo;
         return pages;
@@ -375,16 +379,17 @@ describe('util/github/graphql/datasource-fetcher', () => {
       ];
 
       test.each`
-        isPrivate | isCacheable
-        ${true}   | ${false}
-        ${false}  | ${true}
+        isPrivate    | isCacheable
+        ${undefined} | ${false}
+        ${true}      | ${false}
+        ${false}     | ${true}
       `(
         'private=$isPrivate => isCacheable=$isCacheable',
         async ({ isPrivate, isCacheable }) => {
           httpMock
             .scope('https://api.github.com/')
             .post('/graphql')
-            .reply(200, resp(data, undefined, isPrivate));
+            .reply(200, resp(isPrivate, data, undefined));
 
           const instance = new GithubGraphqlDatasourceFetcher(
             { packageName: 'foo/bar' },
-- 
GitLab