@donmahallem/label-pr
Version:
Helpers for working with github issue labels
111 lines • 4.36 kB
JavaScript
/**
* Package @donmahallem/label-pr
* Source https://donmahallem.github.io/js-libs/
*/
import { calculateLabelDiff } from '@donmahallem/label-gh';
import { expect } from 'chai';
import * as esmock from 'esmock';
import 'mocha';
import Sinon from 'sinon';
/* eslint-disable @typescript-eslint/no-explicit-any */
describe('syncLabels', function () {
let sandbox;
before('setup sandbox', function () {
sandbox = Sinon.createSandbox();
});
afterEach('reset sandbox', function () {
sandbox.reset();
});
after('restore sandbox', function () {
sandbox.restore();
});
describe('syncLabels', function () {
let getPullRequestLabelsStub;
let syncLabelsStub;
let testMethod;
before('setup octokit stub instance', async function () {
getPullRequestLabelsStub = sandbox.stub().named('getPullRequestLabels');
syncLabelsStub = sandbox.stub().named('syncLabels');
testMethod = (await esmock.strict('./sync-pr-labels.js', {
'@donmahallem/label-gh': {
calculateLabelDiff: calculateLabelDiff,
getPullRequestLabels: getPullRequestLabelsStub,
syncLabels: syncLabelsStub,
},
})).syncPRLabels;
});
beforeEach('setup octokit stub instance', function () {
syncLabelsStub.resolves('set label');
});
it('should ignore non prefixed labels and set prefixed', function () {
getPullRequestLabelsStub.resolves([{ name: 'label1' }]);
return testMethod({}, {
owner: 'some_owner',
pull_number: 2,
repo: 'anyrepo',
}, ['test', 'label']).then((result) => {
expect(syncLabelsStub.callCount).to.equal(1, 'should be called');
expect(syncLabelsStub.args).to.deep.eq([
[
{},
{
issue_number: 2,
owner: 'some_owner',
repo: 'anyrepo',
},
['pkg:test', 'pkg:label', 'label1'],
true,
],
]);
expect(result).to.equal('set label');
});
});
it('should ignore non prefixed labels and set non default prefix', function () {
getPullRequestLabelsStub.resolves([{ name: 'label1' }, { name: 'asdf:any' }]);
return testMethod({}, {
owner: 'some_owner',
pull_number: 2,
repo: 'anyrepo',
}, ['test', 'label'], 'asdf').then((result) => {
expect(syncLabelsStub.callCount).to.equal(1, 'should be called');
expect(syncLabelsStub.args).to.deep.eq([
[
{},
{
issue_number: 2,
owner: 'some_owner',
repo: 'anyrepo',
},
['asdf:test', 'asdf:label', 'label1'],
true,
],
]);
expect(result).to.equal('set label');
});
});
it('should keep previous labels', function () {
getPullRequestLabelsStub.resolves([{ name: 'label1' }, { name: 'asdf:test' }]);
return testMethod({}, {
owner: 'some_owner',
pull_number: 2,
repo: 'anyrepo',
}, ['test', 'label'], 'asdf').then((result) => {
expect(syncLabelsStub.callCount).to.equal(1, 'should be called');
expect(syncLabelsStub.args).to.deep.eq([
[
{},
{
issue_number: 2,
owner: 'some_owner',
repo: 'anyrepo',
},
['asdf:label', 'asdf:test', 'label1'],
true,
],
]);
expect(result).to.equal('set label');
});
});
});
});
//# sourceMappingURL=sync-pr-labels.spec.js.map