Skip to content

Commit

Permalink
test: integration test for issue comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Nov 29, 2023
1 parent a38ed7b commit f85d6a8
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,76 @@ describe('Integration tests', () => {
// Test summary
await assertSummary(`<h1>Testing Farm as a GitHub Action summary</h1>
<table><tr><th>Compose</th><th>Arch</th><th>Infrastructure State</th><th>Test result</th><th>Link to logs</th></tr><tr><td>Fedora-latest</td><td>x86_64</td><td>OK</td><td>success</td><td>[http://artifacts.osci.redhat.com/testing-farm/1/pipeline.log](pipeline.log)</td></tr></table>
`);

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(`<h1>Testing Farm as a GitHub Action summary</h1>
<table><tr><th>Compose</th><th>Arch</th><th>Infrastructure State</th><th>Test result</th><th>Link to logs</th></tr><tr><td>${process.env['INPUT_COMPOSE']}</td><td>${process.env['INPUT_ARCH']}</td><td>OK</td><td>success</td><td>[https://artifacts.dev.testing-farm.io/1/pipeline.log](pipeline.log)</td></tr></table>
`);

expect(mocks.TFError).not.toHaveBeenCalled();
Expand Down

0 comments on commit f85d6a8

Please sign in to comment.