mirror of
https://github.com/badges/shields.git
synced 2026-11-21 16:06:35 +03:00
* add not-planned and duplicate to issue state to [GithubIssueDetail] Fixes GitHub issues/PRs - Support the "not planned" state Fixes #11662 * fix: replace underscore with space in state reason response transformation * fix: tests after not_planed replaced by not planned * fix: update issue state color key from not_planned to not planned * improve testing, forever closed Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com> * remove redundent condition --------- Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
286 lines
7.1 KiB
JavaScript
286 lines
7.1 KiB
JavaScript
import { expect } from 'chai'
|
|
import { test, given } from 'sazerac'
|
|
import { age, formatDate } from '../date.js'
|
|
import { metric } from '../text-formatters.js'
|
|
import { InvalidResponse } from '../index.js'
|
|
import GithubIssueDetail from './github-issue-detail.service.js'
|
|
import { issueStateColor, commentsColor } from './github-helpers.js'
|
|
|
|
describe('GithubIssueDetail', function () {
|
|
test(GithubIssueDetail.render, () => {
|
|
given({
|
|
property: 'state',
|
|
value: { state: 'open' },
|
|
number: '12',
|
|
isPR: true,
|
|
}).expect({
|
|
label: 'pull request 12',
|
|
message: 'open',
|
|
color: issueStateColor('open'),
|
|
})
|
|
given({
|
|
property: 'state',
|
|
value: { state: 'closed' },
|
|
number: '15',
|
|
isPR: false,
|
|
}).expect({
|
|
label: 'issue 15',
|
|
message: 'closed',
|
|
color: issueStateColor('closed'),
|
|
})
|
|
given({
|
|
property: 'state',
|
|
value: { state: 'not planned' },
|
|
number: '93',
|
|
isPR: false,
|
|
}).expect({
|
|
label: 'issue 93',
|
|
message: 'not planned',
|
|
color: issueStateColor('not planned'),
|
|
})
|
|
given({
|
|
property: 'state',
|
|
value: { state: 'duplicate' },
|
|
number: '95',
|
|
isPR: false,
|
|
}).expect({
|
|
label: 'issue 95',
|
|
message: 'duplicate',
|
|
color: issueStateColor('duplicate'),
|
|
})
|
|
given({
|
|
property: 'title',
|
|
value: 'refactor [FooService]',
|
|
number: '232',
|
|
isPR: true,
|
|
}).expect({
|
|
label: 'pull request 232',
|
|
message: 'refactor [FooService]',
|
|
})
|
|
given({
|
|
property: 'title',
|
|
value: 'Packagist: invalid response data',
|
|
number: '345',
|
|
isPR: false,
|
|
}).expect({
|
|
label: 'issue 345',
|
|
message: 'Packagist: invalid response data',
|
|
})
|
|
given({
|
|
property: 'author',
|
|
value: 'calebcartwright',
|
|
}).expect({
|
|
label: 'author',
|
|
message: 'calebcartwright',
|
|
})
|
|
given({
|
|
property: 'label',
|
|
value: { names: ['feature'], colors: ['a2eeef'] },
|
|
}).expect({
|
|
color: 'a2eeef',
|
|
message: 'feature',
|
|
label: 'label',
|
|
})
|
|
given({
|
|
property: 'label',
|
|
value: { names: ['service-badge', 'bug'], colors: ['a2eeef', 'ee0701'] },
|
|
}).expect({
|
|
color: undefined,
|
|
message: 'service-badge | bug',
|
|
label: 'label',
|
|
})
|
|
given({ property: 'comments', value: 27 }).expect({
|
|
label: 'comments',
|
|
message: metric(27),
|
|
color: commentsColor('closed'),
|
|
})
|
|
given({
|
|
property: 'age',
|
|
value: '2019-04-01T20:09:31Z',
|
|
}).expect({
|
|
label: 'created',
|
|
message: formatDate('2019-04-01T20:09:31Z'),
|
|
color: age('2019-04-01T20:09:31Z'),
|
|
})
|
|
given({
|
|
property: 'last-update',
|
|
value: '2019-04-02T20:09:31Z',
|
|
}).expect({
|
|
label: 'updated',
|
|
message: formatDate('2019-04-02T20:09:31Z'),
|
|
color: age('2019-04-02T20:09:31Z'),
|
|
})
|
|
given({
|
|
property: 'milestone',
|
|
value: 'MS 1',
|
|
}).expect({
|
|
label: 'milestone',
|
|
message: 'MS 1',
|
|
color: 'informational',
|
|
})
|
|
})
|
|
|
|
test(GithubIssueDetail.prototype.transform, () => {
|
|
given({
|
|
property: 'state',
|
|
json: { state: 'closed' },
|
|
}).expect({
|
|
// Since it's a PR, the "merged" value is not crucial here.
|
|
value: { state: 'closed', merged: false },
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
json: { state: 'closed', state_reason: 'not_planned' },
|
|
}).expect({
|
|
value: { state: 'not planned', merged: false },
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
json: { state: 'closed', state_reason: 'duplicate' },
|
|
}).expect({
|
|
value: { state: 'duplicate', merged: false },
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
json: { state: 'closed', state_reason: 'other_reason' },
|
|
}).expect({
|
|
value: { state: 'closed', merged: false },
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
json: { state: 'closed', pull_request: { merged_at: null } },
|
|
}).expect({
|
|
value: { state: 'closed', merged: false },
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
json: {
|
|
state: 'closed',
|
|
pull_request: { merged_at: '2025-01-01T00:00:00Z' },
|
|
},
|
|
}).expect({
|
|
value: { state: 'closed', merged: true },
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
issueKind: 'pulls',
|
|
json: { state: 'closed', merged_at: null },
|
|
}).expect({
|
|
value: { state: 'closed', merged: false },
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'state',
|
|
issueKind: 'pulls',
|
|
json: { state: 'closed', merged_at: 'I am not null' },
|
|
}).expect({
|
|
value: { state: 'closed', merged: true },
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'title',
|
|
json: { pull_request: {}, title: 'refactor [Codecov]' },
|
|
}).expect({
|
|
value: 'refactor [Codecov]',
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'author',
|
|
json: { user: { login: 'dependabot' } },
|
|
}).expect({
|
|
value: 'dependabot',
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'label',
|
|
json: {
|
|
pull_request: {},
|
|
labels: [
|
|
{ name: 'service-badge', color: 'a2eeef' },
|
|
{ name: 'bug', color: 'ee0701' },
|
|
],
|
|
},
|
|
}).expect({
|
|
value: {
|
|
names: ['service-badge', 'bug'],
|
|
colors: ['a2eeef', 'ee0701'],
|
|
},
|
|
isPR: true,
|
|
})
|
|
given({
|
|
property: 'label',
|
|
json: { labels: [{ name: 'bug', color: 'ee0701' }] },
|
|
}).expect({
|
|
value: {
|
|
names: ['bug'],
|
|
colors: ['ee0701'],
|
|
},
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'comments',
|
|
json: { comments: 100 },
|
|
}).expect({
|
|
value: 100,
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'age',
|
|
json: { created_at: '2019-04-01T20:09:31Z' },
|
|
}).expect({
|
|
value: '2019-04-01T20:09:31Z',
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'last-update',
|
|
json: { updated_at: '2019-04-02T20:09:31Z' },
|
|
}).expect({
|
|
value: '2019-04-02T20:09:31Z',
|
|
isPR: false,
|
|
})
|
|
given({
|
|
property: 'milestone',
|
|
json: { milestone: { title: 'MS 1' } },
|
|
}).expect({
|
|
value: 'MS 1',
|
|
isPR: false,
|
|
})
|
|
})
|
|
|
|
context('transform()', function () {
|
|
it('throws InvalidResponse error when issue has no labels', function () {
|
|
try {
|
|
GithubIssueDetail.prototype.transform({
|
|
property: 'label',
|
|
json: { labels: [] },
|
|
})
|
|
expect.fail('Expected to throw')
|
|
} catch (e) {
|
|
expect(e).to.be.an.instanceof(InvalidResponse)
|
|
expect(e.prettyMessage).to.equal('no labels found')
|
|
}
|
|
})
|
|
})
|
|
|
|
context('transform()', function () {
|
|
it('throws InvalidResponse error when issue has no milestone', function () {
|
|
try {
|
|
GithubIssueDetail.prototype.transform({
|
|
property: 'milestone',
|
|
json: { milestone: null },
|
|
})
|
|
expect.fail('Expected to throw')
|
|
} catch (e) {
|
|
expect(e).to.be.an.instanceof(InvalidResponse)
|
|
expect(e.prettyMessage).to.equal('no milestone')
|
|
}
|
|
})
|
|
})
|
|
})
|