Skip to content

Commit

Permalink
feat: expose getAllItems to github-script action (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Mar 19, 2024
1 parent fbaf72a commit eb760c4
Show file tree
Hide file tree
Showing 21 changed files with 849 additions and 373 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ jobs:
throw new Error("Field value is not correct")
}
const items = await actions.getAllItems("${{ steps.copy-project.outputs.id }}")
if (items.length !== 2) {
throw new Error("Expected 2 items")
}
# - name: Archive Item
# uses: ./archive-item/
# id: archive-item
Expand Down
5 changes: 5 additions & 0 deletions __tests__/completed-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('completedByAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: 'This is the item body',
title: 'Item Title'
Expand Down Expand Up @@ -164,6 +165,7 @@ describe('completedByAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: `Completed by ${itemUrl}`,
title: 'Item Title'
Expand Down Expand Up @@ -199,6 +201,7 @@ describe('completedByAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: `Completed by ${itemUrl}`,
title: 'Item Title'
Expand Down Expand Up @@ -232,6 +235,7 @@ describe('completedByAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: `
Completed by ${itemUrl1}
Expand Down Expand Up @@ -272,6 +276,7 @@ describe('completedByAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: `Completed by ${itemUrl}`,
title: 'Item Title'
Expand Down
4 changes: 4 additions & 0 deletions __tests__/copy-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe('copyProjectAction', () => {
{
id: 'item-id',
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: 'This is the item body',
title: 'Item Title'
Expand Down Expand Up @@ -264,6 +265,7 @@ describe('copyProjectAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: contentId,
body: 'This is the item {{ foo }}',
title: 'Item {{ foo }}'
Expand Down Expand Up @@ -301,6 +303,7 @@ describe('copyProjectAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: 'content-id',
body: `<!-- fields
{
Expand Down Expand Up @@ -342,6 +345,7 @@ describe('copyProjectAction', () => {
{
id: itemId,
content: {
__typename: 'DraftIssue',
id: contentId,
body: 'This is the item {{ foo }}',
title: 'Item {{ foo }}'
Expand Down
149 changes: 143 additions & 6 deletions __tests__/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,116 @@ describe('lib', () => {
});
});

describe('getAllItems', () => {
it('handles project not found', async () => {
const mockOctokit = mockGetOctokit();
const error = createMockGraphqlResponseError([
{
type: 'NOT_FOUND',
message: '',
path: ['']
}
]);
jest.mocked(mockOctokit.graphql.paginate.iterator).mockReturnValue({
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.ProjectItemsResponse;
}> {
throw error;
}
})
});

await expect(lib.getAllItems(projectId)).rejects.toThrow(
lib.ProjectNotFoundError
);
});

it('throws other graphql errors', async () => {
const mockOctokit = mockGetOctokit();
const error = createMockGraphqlResponseError([
{
type: 'SOME_ERROR',
message: '',
path: ['']
}
]);
jest.mocked(mockOctokit.graphql.paginate.iterator).mockReturnValue({
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.ProjectItemsResponse;
}> {
throw error;
}
})
});

await expect(lib.getAllItems(projectId)).rejects.toBe(error);
});

it('returns all items', async () => {
const items: lib.ProjectItem[] = [
{
id: 'DI_one',
content: {
__typename: 'DraftIssue',
id: 'content-id-one',
body: 'Body One',
title: 'Title One'
}
},
{
id: 'PR_two',
content: {
__typename: 'PullRequest',
id: 'content-id-two',
body: 'Body Two',
title: 'Title Two',
url: 'foobar'
}
},
{
id: 'I_three',
content: {
__typename: 'Issue',
id: 'content-id-three',
body: 'Body three',
title: 'Title three',
url: 'foobar-two'
}
}
];
const mockOctokit = mockGetOctokit();
let iterateCount = 0;
jest.mocked(mockOctokit.graphql.paginate.iterator).mockReturnValue({
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.ProjectItemsResponse;
}> {
return {
value: {
projectV2: {
items: {
nodes: items,
pageInfo: {
endCursor: 'end-cursor',
hasNextPage: false
}
}
}
},
done: iterateCount++ === 1
};
}
})
});
await expect(lib.getAllItems(projectId)).resolves.toEqual(items);
});
});

describe('getDraftIssues', () => {
it('handles project not found', async () => {
const mockOctokit = mockGetOctokit();
Expand All @@ -93,7 +203,7 @@ describe('lib', () => {
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.DraftIssuesResponse;
value: lib.ProjectItemsResponse;
}> {
throw error;
}
Expand All @@ -118,7 +228,7 @@ describe('lib', () => {
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.DraftIssuesResponse;
value: lib.ProjectItemsResponse;
}> {
throw error;
}
Expand All @@ -128,11 +238,12 @@ describe('lib', () => {
await expect(lib.getDraftIssues(projectId)).rejects.toBe(error);
});

it('returns draft items', async () => {
const items: lib.DraftIssueItem[] = [
it('returns only draft items', async () => {
const draftItems: lib.DraftIssueItem[] = [
{
id: 'DI_one',
content: {
__typename: 'DraftIssue',
id: 'content-id-one',
body: 'Body One',
title: 'Title One'
Expand All @@ -141,19 +252,45 @@ describe('lib', () => {
{
id: 'DI_two',
content: {
__typename: 'DraftIssue',
id: 'content-id-two',
body: 'Body Two',
title: 'Title Two'
}
}
];

const items: lib.ProjectItem[] = [
{
id: 'PR_two',
content: {
__typename: 'PullRequest',
id: 'content-id-two',
body: 'Body Two',
title: 'Title Two',
url: 'foobar'
}
},
...draftItems,
{
id: 'I_three',
content: {
__typename: 'Issue',
id: 'content-id-three',
body: 'Body three',
title: 'Title three',
url: 'foobar-two'
}
}
];

const mockOctokit = mockGetOctokit();
let iterateCount = 0;
jest.mocked(mockOctokit.graphql.paginate.iterator).mockReturnValue({
[Symbol.asyncIterator]: () => ({
async next(): Promise<{
done: boolean;
value: lib.DraftIssuesResponse;
value: lib.ProjectItemsResponse;
}> {
return {
value: {
Expand All @@ -172,7 +309,7 @@ describe('lib', () => {
}
})
});
await expect(lib.getDraftIssues(projectId)).resolves.toEqual(items);
await expect(lib.getDraftIssues(projectId)).resolves.toEqual(draftItems);
});
});

Expand Down
39 changes: 39 additions & 0 deletions dist/add-item.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb760c4

Please sign in to comment.