|
| 1 | +import { describe, expect, test, vi } from 'vitest' |
| 2 | +import type { Octokit } from '@octokit/rest' |
| 3 | + |
| 4 | +import main, { parseLabels } from '../../../.github/actions/labeler/labeler' |
| 5 | + |
| 6 | +describe('parseLabels', () => { |
| 7 | + test('returns no labels for a missing or empty input', () => { |
| 8 | + expect(parseLabels(undefined)).toEqual([]) |
| 9 | + expect(parseLabels('')).toEqual([]) |
| 10 | + }) |
| 11 | + |
| 12 | + test('splits, trims, and drops blank labels', () => { |
| 13 | + expect(parseLabels('waiting for review')).toEqual(['waiting for review']) |
| 14 | + expect(parseLabels(' a, b ,')).toEqual(['a', 'b']) |
| 15 | + }) |
| 16 | +}) |
| 17 | + |
| 18 | +describe('labeler main', () => { |
| 19 | + test('does not add labels when the addLabels input is empty', async () => { |
| 20 | + const addLabels = vi.fn() |
| 21 | + const removeLabel = vi.fn() |
| 22 | + const octokit = { |
| 23 | + issues: { |
| 24 | + get: vi.fn().mockResolvedValue({ data: { labels: [{ name: 'waiting for review' }] } }), |
| 25 | + addLabels, |
| 26 | + removeLabel, |
| 27 | + }, |
| 28 | + } as unknown as Octokit |
| 29 | + const core = { |
| 30 | + info: vi.fn(), |
| 31 | + debug: vi.fn(), |
| 32 | + warning: vi.fn(), |
| 33 | + error: vi.fn(), |
| 34 | + setOutput: vi.fn(), |
| 35 | + setFailed: vi.fn(), |
| 36 | + } |
| 37 | + |
| 38 | + await main(core, octokit, { |
| 39 | + addLabels: parseLabels(''), |
| 40 | + removeLabels: parseLabels('waiting for review'), |
| 41 | + issue_number: 1, |
| 42 | + owner: 'github', |
| 43 | + repo: 'docs', |
| 44 | + }) |
| 45 | + |
| 46 | + expect(removeLabel).toHaveBeenCalledWith( |
| 47 | + expect.objectContaining({ name: 'waiting for review' }), |
| 48 | + ) |
| 49 | + expect(addLabels).not.toHaveBeenCalled() |
| 50 | + }) |
| 51 | +}) |
0 commit comments