Skip to content
Merged
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
35 changes: 34 additions & 1 deletion __tests__/plugins/lgtmBinding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { http } from 'msw'
import { setupServer } from 'msw/node'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'

import { bindLgtm, isLgtmBound, lgtmOnPullRequest, lgtmSettings, unbindLgtm } from '../../src/plugins/lgtmBinding'
import { bindLgtm, hasLgtmLabel, isLgtmBound, lgtmOnPullRequest, lgtmSettings, unbindLgtm } from '../../src/plugins/lgtmBinding'
import { mergeProwConfig } from '../../src/utils/config'
import { newOctokit } from '../../src/utils/octokit'
import labelFileContents from '../fixtures/labels/labelFileContentsResp.json'
Expand Down Expand Up @@ -41,6 +41,17 @@ describe('lgtmSettings', () => {
})
})

describe('hasLgtmLabel', () => {
it.each([
['lgtm among other labels', ['approved', 'lgtm', 'kind/bug'], true],
['LGTM in another case', ['LGTM'], true],
['only other labels', ['approved', 'kind/bug'], false],
['no labels', [], false],
])('%s', (_, labels, expected) => {
expect(hasLgtmLabel(labels)).toBe(expected)
})
})

describe('lgtmOnPullRequest', () => {
it('labeled lgtm by a human binds the label to the payload head', async () => {
const status = new utils.ObserveRequest()
Expand Down Expand Up @@ -121,6 +132,19 @@ describe('the binding primitives', () => {
expect(body).not.toHaveProperty('target_url')
})

it('unbindLgtm sets prow/lgtm to pending and truncates the description to 140 characters', async () => {
const status = new utils.ObserveRequest()
server.use(http.post(`${repo}/statuses/abc`, utils.mockResponse(201, {}, status)))

await expect(unbindLgtm(octokit, context, 'abc', 'y'.repeat(200))).resolves.toBeUndefined()

expect(await status.body()).toEqual({
state: 'pending',
context: 'prow/lgtm',
description: 'y'.repeat(140),
})
})

it('unbindLgtm warns instead of throwing', async () => {
server.use(http.post(`${repo}/statuses/abc`, utils.mockResponse(500, { message: 'boom' })))
const warning = vi.spyOn(core, 'warning').mockImplementation(() => {})
Expand All @@ -140,6 +164,15 @@ describe('the binding primitives', () => {
await expect(isLgtmBound(octokit, context, 'abc')).resolves.toBe(bound)
})

it('isLgtmBound reads the combined status with per_page=100', async () => {
const combined = new utils.ObserveRequest()
server.use(http.get(`${repo}/commits/abc/status`, utils.mockResponse(200, { state: 'x', statuses: [] }, combined)))

await isLgtmBound(octokit, context, 'abc')

expect(new URL(combined.ref!.url).searchParams.get('per_page')).toBe('100')
})

it('isLgtmBound wraps any other error without the permission hint', async () => {
server.use(http.get(`${repo}/commits/abc/status`, utils.mockResponse(500, { message: 'boom' })))

Expand Down
Loading