Skip to content

Commit

Permalink
add test combining number and status
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 committed May 3, 2023
1 parent aa0c892 commit fa8d010
Showing 1 changed file with 94 additions and 17 deletions.
111 changes: 94 additions & 17 deletions __tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,46 @@ pullRequestsWithLabels.push(
}
)

const openPullRequestsWithLabels: PullRequestInfo[] = []
openPullRequestsWithLabels.push(
{
number: 6,
title: 'Still pending open pull request (Current)',
htmlURL: '',
baseBranch: '',
createdAt: moment(),
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('feature'),
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
},
{
number: 7,
title: 'Still pending open pull request',
htmlURL: '',
baseBranch: '',
createdAt: moment(),
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('feature'),
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
}
)

it('Match multiple labels exhaustive for category', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
Expand Down Expand Up @@ -417,9 +457,7 @@ it('Release Diff', async () => {
configuration: customConfig
})

expect(resultChangelog).toStrictEqual(
`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1\n`
)
expect(resultChangelog).toStrictEqual(`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1\n`)
})

it('Use exclude labels to not include a PR within a category.', async () => {
Expand Down Expand Up @@ -492,7 +530,6 @@ it('Extract custom placeholder from PR body and replace in global template', asy
)
})


it('Use Rules to include a PR within a Category.', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
Expand All @@ -502,12 +539,12 @@ it('Use Rules to include a PR within a Category.', async () => {
exclude_labels: ['Fix'],
rules: [
{
pattern: "\[ABC-1234\]",
on_property: "title"
pattern: '[ABC-1234]',
on_property: 'title'
},
{
pattern: "merged",
on_property: "status"
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
Expand All @@ -528,14 +565,53 @@ it('Use Rules to get all open PRs in a Category.', async () => {
title: '## Open PRs only',
rules: [
{
pattern: "open",
on_property: "status"
pattern: 'open',
on_property: 'status'
}
]
}
]
expect(buildChangelogTest(customConfig, prs)).toStrictEqual(`## Open PRs only\n\n- Still pending open pull request\n - PR: #6\n\n`)
})


it('Use Rules to get current open PR and merged categorised.', async () => {
let prs = Array.from(pullRequestsWithLabels)
prs.concat(Array.from(openPullRequestsWithLabels))

const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '## 🚀 Features',
labels: ['Feature'],
rules: [
{
pattern: '6',
on_property: 'number'
},
{
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
},{
title: '## 🐛 Issues',
labels: ['Issue'],
rules: [
{
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
}
]

console.log(buildChangelogTest(customConfig, prs))

expect(buildChangelogTest(customConfig, prs)).toStrictEqual(
`## Open PRs only\n\n- Still pending open pull request\n - PR: #6\n\n`
`## 🚀 Features\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n- Still pending open pull request\n - PR: #6\n\n## 🐛 Issues\n\n- [ABC-4321] - this is a PR 2 title message\n - PR: #2\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n`
)
})

Expand All @@ -549,8 +625,8 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn
title: '## Open PRs only',
rules: [
{
pattern: "open",
on_property: "status"
pattern: 'open',
on_property: 'status'
}
]
},
Expand All @@ -559,18 +635,19 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn
labels: ['Feature', 'Issue'],
rules: [
{
pattern: "merged",
on_property: "status"
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true,
exhaustive: true
}
]
expect(buildChangelogTest(customConfig, prs)).toStrictEqual(
`## Open PRs only\n\n- Still pending open pull request\n - PR: #6\n\n## 🚀 Features and 🐛 Issues\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n`
)
})


function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): string {
return buildChangelog(DefaultDiffInfo, prs, {
owner: 'mikepenz',
Expand All @@ -585,4 +662,4 @@ function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): stri
commitMode: false,
configuration: config
})
}
}

0 comments on commit fa8d010

Please sign in to comment.