clear mocks in github-issues tests
Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
@@ -22,80 +22,123 @@ import { ConfigApi, ErrorApi } from '@backstage/core-plugin-api';
|
||||
import { ForwardedError } from '@backstage/errors';
|
||||
import { gitHubIssuesApi } from './gitHubIssuesApi';
|
||||
|
||||
function getFragment(
|
||||
filterBy = '',
|
||||
orderBy = 'field: UPDATED_AT, direction: DESC',
|
||||
) {
|
||||
return (
|
||||
'\n' +
|
||||
' \n' +
|
||||
' fragment issues on Repository {\n' +
|
||||
' issues(\n' +
|
||||
' states: OPEN\n' +
|
||||
' first: 10\n' +
|
||||
` filterBy: { ${filterBy} }\n` +
|
||||
` orderBy: { ${orderBy} }\n` +
|
||||
' ) {\n' +
|
||||
' totalCount\n' +
|
||||
' edges {\n' +
|
||||
' node {\n' +
|
||||
' assignees(first: 10) {\n' +
|
||||
' edges {\n' +
|
||||
' node {\n' +
|
||||
' avatarUrl\n' +
|
||||
' login\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' author {\n' +
|
||||
' login\n' +
|
||||
' }\n' +
|
||||
' repository {\n' +
|
||||
' nameWithOwner\n' +
|
||||
' }\n' +
|
||||
' title\n' +
|
||||
' url\n' +
|
||||
' participants {\n' +
|
||||
' totalCount\n' +
|
||||
' }\n' +
|
||||
' updatedAt\n' +
|
||||
' createdAt\n' +
|
||||
' comments(last: 1) {\n' +
|
||||
' totalCount\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' \n' +
|
||||
'\n' +
|
||||
' query {\n' +
|
||||
' \n' +
|
||||
' yoyo: repository(name: "yo-yo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' ,\n' +
|
||||
' yoyox: repository(name: "yoyo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' ,\n' +
|
||||
' yoyoxx: repository(name: "yo.yo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' \n' +
|
||||
' } \n' +
|
||||
' '
|
||||
);
|
||||
}
|
||||
|
||||
describe('gitHubIssuesApi', () => {
|
||||
describe('fetchIssuesByRepoFromGitHub', () => {
|
||||
it('should call GitHub API with correct query with fragment for each repo', async () => {
|
||||
const api = gitHubIssuesApi(
|
||||
let api: ReturnType<typeof gitHubIssuesApi>;
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
api = gitHubIssuesApi(
|
||||
{ getAccessToken: jest.fn() },
|
||||
{
|
||||
getOptionalConfigArray: jest.fn(),
|
||||
} as unknown as ConfigApi,
|
||||
{ post: jest.fn() } as unknown as ErrorApi,
|
||||
);
|
||||
});
|
||||
|
||||
it('should call GitHub API with correct query with fragment for each repo', async () => {
|
||||
await api.fetchIssuesByRepoFromGitHub(
|
||||
['mrwolny/yo-yo', 'mrwolny/yoyo', 'mrwolny/yo.yo'],
|
||||
10,
|
||||
);
|
||||
|
||||
expect(mockGraphQLQuery).toHaveBeenCalledTimes(1);
|
||||
expect(mockGraphQLQuery).toHaveBeenCalledWith(getFragment());
|
||||
});
|
||||
|
||||
it('should call Github API with the correct filterBy and orderBy clauses', async () => {
|
||||
await api.fetchIssuesByRepoFromGitHub(
|
||||
['mrwolny/yo-yo', 'mrwolny/yoyo', 'mrwolny/yo.yo'],
|
||||
10,
|
||||
{
|
||||
filterBy: {
|
||||
labels: ['bug'],
|
||||
states: ['OPEN'],
|
||||
assignee: 'someone',
|
||||
},
|
||||
orderBy: {
|
||||
field: 'COMMENTS',
|
||||
direction: 'ASC',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const expectedFilterBy = `labels: [ "bug"], states: OPEN, assignee: "someone"`;
|
||||
const expectedOrderBy = 'field: COMMENTS, direction: ASC';
|
||||
|
||||
expect(mockGraphQLQuery).toHaveBeenCalledTimes(1);
|
||||
expect(mockGraphQLQuery).toHaveBeenCalledWith(
|
||||
'\n' +
|
||||
' \n' +
|
||||
' fragment issues on Repository {\n' +
|
||||
' issues(\n' +
|
||||
' states: OPEN\n' +
|
||||
' first: 10\n' +
|
||||
' orderBy: { field: UPDATED_AT, direction: DESC }\n' +
|
||||
' ) {\n' +
|
||||
' totalCount\n' +
|
||||
' edges {\n' +
|
||||
' node {\n' +
|
||||
' assignees(first: 10) {\n' +
|
||||
' edges {\n' +
|
||||
' node {\n' +
|
||||
' avatarUrl\n' +
|
||||
' login\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' author {\n' +
|
||||
' login\n' +
|
||||
' }\n' +
|
||||
' repository {\n' +
|
||||
' nameWithOwner\n' +
|
||||
' }\n' +
|
||||
' title\n' +
|
||||
' url\n' +
|
||||
' participants {\n' +
|
||||
' totalCount\n' +
|
||||
' }\n' +
|
||||
' updatedAt\n' +
|
||||
' createdAt\n' +
|
||||
' comments(last: 1) {\n' +
|
||||
' totalCount\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' }\n' +
|
||||
' \n' +
|
||||
'\n' +
|
||||
' query {\n' +
|
||||
' \n' +
|
||||
' yoyo: repository(name: "yo-yo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' ,\n' +
|
||||
' yoyox: repository(name: "yoyo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' ,\n' +
|
||||
' yoyoxx: repository(name: "yo.yo", owner: "mrwolny") {\n' +
|
||||
' ...issues\n' +
|
||||
' }\n' +
|
||||
' \n' +
|
||||
' } \n' +
|
||||
' ',
|
||||
getFragment(expectedFilterBy, expectedOrderBy),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ export const gitHubIssuesApi = (
|
||||
field: 'UPDATED_AT',
|
||||
direction: 'DESC',
|
||||
},
|
||||
}: IssuesByRepoOptions,
|
||||
}: IssuesByRepoOptions = {},
|
||||
): Promise<IssuesByRepo> => {
|
||||
const graphql = await getOctokit();
|
||||
const safeNames: Array<string> = [];
|
||||
@@ -134,13 +134,6 @@ export const gitHubIssuesApi = (
|
||||
};
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`
|
||||
---------------------------------------------------
|
||||
${createIssueByRepoQuery(repositories, itemsPerRepo, { filterBy, orderBy })}
|
||||
---------------------------------------------------
|
||||
`);
|
||||
|
||||
let issuesByRepo: IssuesByRepo = {};
|
||||
try {
|
||||
issuesByRepo = await graphql(
|
||||
|
||||
Reference in New Issue
Block a user