diff --git a/tests/action.test.ts b/tests/action.test.ts index 537d9e1..9bebcd6 100644 --- a/tests/action.test.ts +++ b/tests/action.test.ts @@ -373,6 +373,76 @@ describe('Integration tests', () => { // Test summary await assertSummary(`

Testing Farm as a GitHub Action summary

ComposeArchInfrastructure StateTest resultLink to logs
Fedora-latestx86_64OKsuccess[http://artifacts.osci.redhat.com/testing-farm/1/pipeline.log](pipeline.log)
+`); + + expect(mocks.TFError).not.toHaveBeenCalled(); + }); + + test('Pull Request comment with results', async () => { + setDefaultInputs(); + + // Mock required Action inputs + // api_key - A testing farm server api key + vi.stubEnv('INPUT_API_KEY', 'abcdef-123456'); + // git_url - An url to the GIT repository + vi.stubEnv( + 'INPUT_GIT_URL', + 'https://github.com/sclorg/testing-farm-as-github-action' + ); + // tmt_plan_regex - A tmt plan regex which will be used for selecting plans. By default all plans are selected + vi.stubEnv('INPUT_TMT_PLAN_REGEX', 'fedora'); + // create_issue_comment - It creates a github issue Comment + vi.stubEnv('INPUT_CREATE_ISSUE_COMMENT', 'true'); + + // Mock Testing Farm API + vi.mocked(mocks.newRequest).mockImplementation( + async (_request: NewRequest, _strict: boolean) => { + return Promise.resolve({ + id: '1', + }); + } + ); + vi.mocked(mocks.requestDetails) + .mockResolvedValueOnce({ state: 'new', result: null }) + .mockResolvedValueOnce({ state: 'queued', result: null }) + .mockResolvedValueOnce({ state: 'pending', result: null }) + .mockResolvedValueOnce({ state: 'running', result: null }) + .mockResolvedValueOnce({ + state: 'complete', + result: { overall: 'passed', summary: '\\o/' }, + }); + + // Run action + const octokit = new Octokit({ auth: 'mock-token' }); + const pr = await PullRequest.initialize(1, octokit); + + await action(pr); + + // Check if we have waited for Testing Farm to finish + expect(mocks.requestDetails).toHaveBeenCalledTimes(5); + + // Test outputs + expect(process.env['OUTPUT_REQUEST_ID']).toMatchInlineSnapshot('"1"'); + expect(process.env['OUTPUT_REQUEST_URL']).toMatchInlineSnapshot( + '"https://api.dev.testing-farm.io/requests/1"' + ); + + // First call to request PR details, next two calls for setting the status, the last call is for issue comment + expect(mocks.request).toHaveBeenCalledTimes(4); + expect(mocks.request).toHaveBeenCalledWith( + 'POST /repos/{owner}/{repo}/issues/{issue_number}/comments', + { + body: `Testing Farm [request](https://api.dev.testing-farm.io/requests/1) for Fedora-latest/ regression testing has been created.Once finished, results should be available [here](https://artifacts.dev.testing-farm.io/1/). +[Full pipeline log](https://artifacts.dev.testing-farm.io/1/pipeline.log).`, + issue_number: 1, + owner: 'sclorg', + repo: 'testing-farm-as-github-action', + } + ); + + // Test summary + await assertSummary(`

Testing Farm as a GitHub Action summary

+
ComposeArchInfrastructure StateTest resultLink to logs
${process.env['INPUT_COMPOSE']}${process.env['INPUT_ARCH']}OKsuccess[https://artifacts.dev.testing-farm.io/1/pipeline.log](pipeline.log)
`); expect(mocks.TFError).not.toHaveBeenCalled();