Skip to content

Commit

Permalink
Invert test that rejected non-github.com URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
iansan5653 authored Mar 31, 2023
1 parent 5d4ef34 commit 74235d0
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions __tests__/add-to-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,13 @@ describe('addToProject', () => {
expect(gqlMock).not.toHaveBeenCalled()
})

test(`throws an error when url isn't under the github.com domain`, async () => {
mockGetInput({
'project-url': 'https://notgithub.com/orgs/github/projects/1',
'github-token': 'gh_token',
})

test(`works with URLs that are not under the github.com domain`, async () => {
github.context.payload = {
issue: {
number: 1,
labels: [],
labels: [{name: 'bug'}],
// eslint-disable-next-line camelcase
html_url: 'https://github.com/actions/add-to-project/issues/74',
html_url: 'https://notgithub.com/actions/add-to-project/issues/74',
},
repository: {
name: 'add-to-project',
Expand All @@ -599,13 +594,32 @@ describe('addToProject', () => {
},
}

const infoSpy = jest.spyOn(core, 'info')
const gqlMock = mockGraphQL()
await expect(addToProject()).rejects.toThrow(
'https://notgithub.com/orgs/github/projects/1. Project URL should match the format https://github.com/<orgs-or-users>/<ownerName>/projects/<projectNumber>',
mockGraphQL(
{
test: /getProject/,
return: {
organization: {
projectV2: {
id: 'project-id',
},
},
},
},
{
test: /addProjectV2ItemById/,
return: {
addProjectV2ItemById: {
item: {
id: 'project-item-id',
},
},
},
},
)
expect(infoSpy).not.toHaveBeenCalled()
expect(gqlMock).not.toHaveBeenCalled()

await addToProject()

expect(outputs.itemId).toEqual('project-item-id')
})

test('constructs the correct graphQL query given an organization owner', async () => {
Expand Down

0 comments on commit 74235d0

Please sign in to comment.