mirror of
https://github.com/actions/labeler.git
synced 2025-12-11 03:58:05 +00:00
Add unit tests for toBranchMatchConfig
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import {getBranchName, checkBranch} from '../src/branch';
|
||||
import {
|
||||
getBranchName,
|
||||
checkBranch,
|
||||
toBranchMatchConfig,
|
||||
BranchMatchConfig
|
||||
} from '../src/branch';
|
||||
import * as github from '@actions/github';
|
||||
|
||||
jest.mock('@actions/core');
|
||||
@@ -85,3 +90,66 @@ describe('checkBranch', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBranchMatchConfig', () => {
|
||||
describe('when there are no branch keys in the config', () => {
|
||||
const config = {'changed-files': [{any: ['testing']}]};
|
||||
it('returns an empty object', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toMatchObject({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains a head-branch option', () => {
|
||||
const config = {'head-branch': ['testing']};
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toMatchObject<BranchMatchConfig>({
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the matching option is a string', () => {
|
||||
const stringConfig = {'head-branch': 'testing'};
|
||||
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(stringConfig);
|
||||
expect(result).toMatchObject<BranchMatchConfig>({
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains a base-branch option', () => {
|
||||
const config = {'base-branch': ['testing']};
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toMatchObject<BranchMatchConfig>({
|
||||
baseBranch: ['testing']
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the matching option is a string', () => {
|
||||
const stringConfig = {'base-branch': 'testing'};
|
||||
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(stringConfig);
|
||||
expect(result).toMatchObject<BranchMatchConfig>({
|
||||
baseBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains both a base-branch and head-branch option', () => {
|
||||
const config = {'base-branch': ['testing'], 'head-branch': ['testing']};
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toMatchObject<BranchMatchConfig>({
|
||||
baseBranch: ['testing'],
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user