Skip to content

Commit

Permalink
test(graphql): Make private repo testing more explicit (#19803)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jan 12, 2023
1 parent 4b2f376 commit cd5c569
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/util/github/graphql/datasource-fetcher.spec.ts
Expand Up @@ -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: {
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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' },
Expand All @@ -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')
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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' },
Expand Down

0 comments on commit cd5c569

Please sign in to comment.