From fa8d0100dc90521084606f3b380cf83f6ff53f6c Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 3 May 2023 16:55:49 +0200 Subject: [PATCH] add test combining number and status --- __tests__/transform.test.ts | 111 ++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 17 deletions(-) diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index 93adf5c..87d5757 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -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().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().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 = [ @@ -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 () => { @@ -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 = [ @@ -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 @@ -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` ) }) @@ -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' } ] }, @@ -559,11 +635,11 @@ 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( @@ -571,6 +647,7 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn ) }) + function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): string { return buildChangelog(DefaultDiffInfo, prs, { owner: 'mikepenz', @@ -585,4 +662,4 @@ function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): stri commitMode: false, configuration: config }) -} \ No newline at end of file +}