{"size": 1146, "ext": "js", "max_stars_repo_path": "lib/automations/todos/test/pull-request-handler.js", "max_stars_repo_name": "gigitux/automations", "max_stars_repo_stars_event_min_datetime": "2020-05-21T07:27:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T12:04:07.000Z", "max_issues_repo_path": "lib/automations/todos/test/pull-request-handler.js", "max_issues_repo_name": "gigitux/automations", "max_issues_repo_issues_event_min_datetime": "2020-05-18T20:30:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:00:38.000Z", "max_forks_repo_path": "lib/automations/todos/test/pull-request-handler.js", "max_forks_repo_name": "gigitux/automations", "max_forks_repo_forks_event_min_datetime": "2021-01-29T11:33:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-30T13:38:43.000Z"}
{"max_stars_count": 8, "max_issues_count": 46, "max_forks_count": 2, "avg_line_length": 27.2857142857, "max_line_length": 68, "alphanum_fraction": 0.6492146597}
const {
	gimmeOctokit,
	gimmeContext,
	gimmeApp,
	loadDiff,
} = require( '@testHelpers' );

describe( 'pull-request-handler', () => {
	let octokit, context, app;
	beforeEach( () => {
		octokit = gimmeOctokit();
		context = gimmeContext( 'pull_request', 'opened' );
		app = gimmeApp( 'todos' );
	} );
	it( 'comments on a pull request', async () => {
		await app( context, octokit );
		expect( octokit.issues.listComments ).toHaveBeenCalledTimes( 1 );
		expect( octokit.issues.createComment ).toHaveBeenCalledTimes( 1 );
		expect(
			octokit.issues.createComment.mock.calls[ 0 ]
		).toMatchSnapshot();
	} );
	it( 'does not create duplicate comments', async () => {
		octokit.issues.listComments.mockReturnValueOnce(
			Promise.resolve( {
				data: [
					{
						body: '## I am an example title',
					},
				],
			} )
		);
		await app( context, octokit );
		expect( octokit.issues.createComment ).not.toHaveBeenCalled();
	} );
	it( 'creates many (5) comments', async () => {
		octokit.pulls.get.mockReturnValue( loadDiff( 'many' ) );
		await app( context, octokit );
		expect( octokit.issues.createComment ).toHaveBeenCalledTimes( 5 );
	} );
} );
