Skip to content

Commit

Permalink
test: add acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin authored Dec 17, 2024
1 parent 47036e9 commit 735d9c5
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions test/acceptance/build/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { createGithubWebhookSignatureHeader, expect, nock, sinon, StatusCodes }
import { knex } from '../../../db/knex-database-connection.js';

describe('Acceptance | Build | Github', function () {
afterEach(async function () {
beforeEach(async function () {
await knex('review-apps').truncate();
await knex('pull_requests').truncate();
});

describe('POST /github/webhook', function () {
Expand Down Expand Up @@ -640,9 +641,46 @@ describe('Acceptance | Build | Github', function () {

describe('when label is `ready-to-merge`', function () {
it('should save pull request and call action', async function () {
const callGitHubAction = nock('https://github.com')
.post(`/v1/apps/${appName}/scm_repo_link/manual_review_app`, { pull_request_id: 2 })
.reply(returnCode, body);
const body = {
action: 'labeled',
number: 123,
repository: {
full_name: '1024pix/pix',
},
pull_request: {
state: 'open',
labels: [],
head: {
ref: 'my-branch',
repo: {
name: 'pix',
fork: false,
},
},
},
label: {
name: ':rocket: Ready to Merge',
},
sender: {
login: 'foo',
},
};
const workflowRepoName = config.github.automerge.repositoryName;
const workflowId = config.github.automerge.workflowId;
const workflowRef = config.github.automerge.workflowRef;

sinon.stub(config.github.automerge, 'allowedRepositories').value(['1024pix/pix']);

const checkUserBelongsToPixNock = nock('https://api.github.com')
.get(`/orgs/1024pix/members/${body.sender.login}`)
.reply(204);

const callGitHubAction = nock('https://api.github.com/')
.post(`/repos/${workflowRepoName}/actions/workflows/${workflowId}/dispatches`, {
ref: workflowRef,
inputs: { pullRequest: `1024pix/pix/${body.number}` },
})
.reply(200, {});

const response = await server.inject({
method: 'POST',
Expand All @@ -654,6 +692,7 @@ describe('Acceptance | Build | Github', function () {
payload: body,
});

expect(checkUserBelongsToPixNock.isDone()).to.be.true;
expect(callGitHubAction.isDone()).to.be.true;
expect(response.statusCode).equal(200);
});
Expand Down

0 comments on commit 735d9c5

Please sign in to comment.