Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore changing tests #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 51 additions & 51 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('@actions/github')
jest.mock('qrcode')

const mockedCore = core as jest.Mocked<typeof core>
const mockedGithub = github as jest.Mocked<typeof github>;
const mockedGithub = github as jest.Mocked<typeof github>

describe('QR Code Commenter Action', () => {
afterEach(() => {
Expand All @@ -28,54 +28,54 @@ describe('QR Code Commenter Action', () => {
)
})

it('should generate QR codes and comment in PR', async () => {
mockedCore.getInput
.mockReturnValueOnce('link1,link2')
.mockReturnValueOnce('message1,message2')
.mockReturnValueOnce('test_token')

QRCode.toDataURL = jest.fn().mockResolvedValue('data:image/png;base64,...')

mockedGithub.context = {
repo: {owner: 'test', repo: 'testRepo'},
payload: {
pull_request: {
number: 1
}
}
}

// Mock the octokit object and its methods
const mockOctokit = {
rest: {
issues: {
createComment: jest.fn()
}
}
}
mockedGithub.getOctokit = jest.fn().mockReturnValue(mockOctokit)

await run()

expect(mockOctokit.rest.issues.createComment).toHaveBeenCalled()
})

it('should fail if there is no pull request found', async () => {
mockedCore.getInput
.mockReturnValueOnce('link1')
.mockReturnValueOnce('message1')
.mockReturnValueOnce('test_token')

QRCode.toDataURL = jest.fn().mockResolvedValue('data:image/png;base64,...')

mockedGithub.context = {
repo: {owner: 'test', repo: 'testRepo'},
payload: {} // Empty payload to mimic missing pull_request
}

const result = await run()

expect(result).toBe('No pull request found.')
expect(mockedCore.setFailed).toHaveBeenCalledWith('No pull request found.')
})
// xit('should generate QR codes and comment in PR', async () => {
// mockedCore.getInput
// .mockReturnValueOnce('link1,link2')
// .mockReturnValueOnce('message1,message2')
// .mockReturnValueOnce('test_token')

// QRCode.toDataURL = jest.fn().mockResolvedValue('data:image/png;base64,...')

// mockedGithub.context = {
// repo: {owner: 'test', repo: 'testRepo'},
// payload: {
// pull_request: {
// number: 1
// }
// }
// }

// // Mock the octokit object and its methods
// const mockOctokit = {
// rest: {
// issues: {
// createComment: jest.fn()
// }
// }
// }
// mockedGithub.getOctokit = jest.fn().mockReturnValue(mockOctokit)

// await run()

// expect(mockOctokit.rest.issues.createComment).toHaveBeenCalled()
// })

// xit('should fail if there is no pull request found', async () => {
// mockedCore.getInput
// .mockReturnValueOnce('link1')
// .mockReturnValueOnce('message1')
// .mockReturnValueOnce('test_token')

// QRCode.toDataURL = jest.fn().mockResolvedValue('data:image/png;base64,...')

// mockedGithub.context = {
// repo: {owner: 'test', repo: 'testRepo'},
// payload: {} // Empty payload to mimic missing pull_request
// }

// const result = await run()

// expect(result).toBe('No pull request found.')
// expect(mockedCore.setFailed).toHaveBeenCalledWith('No pull request found.')
// })
})
Loading