functions/AnyInterestingPRs.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"

. "$here\ParsePrTitle.ps1"
. "$here\IsPackageInteresting.ps1"
. "$here\GetSemVerIncrement.ps1"

Describe 'AnyInterestingPRs Tests' -Tag Unit {

    Context 'No PRs' {
        It 'should run without error when no PRs are specified (empty array)' {
            $res = AnyInterestingPRs -Titles @() -MaxSemVerIncrement 'minor' -PackageWildcardExpressions @()
        }

        It 'should run without error when no PRs are specified (null array)' {
            $res = AnyInterestingPRs -Titles $null -MaxSemVerIncrement 'minor' -PackageWildcardExpressions @()
        }
    }
    Context 'Single PR' {
        It 'should return false when no patterns are specified' {
            $res = AnyInterestingPRs -Titles @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @()
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return false when matching patterns are specified with a SemVer increment more than MaxSemVerIncrement' {
            $res = AnyInterestingPRs -Titles @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 1.0.0 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @('Corvus.*')
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return false when matching patterns are specified but no PR matches the pattern' {
            $res = AnyInterestingPRs -Titles @('Bump Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @('Corvus.*')
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return true when matching patterns are specified with a SemVer increment less than MaxSemVerIncrement (<maxSemVerIncrement>)' -TestCases @(
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'major'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground'); maxSemVerIncrement = 'minor'; packageWildcardExpressions = @('Corvus.*'); }
        ) {
            param (
                [string[]] $titles,
                [string] $maxSemVerIncrement,
                [string[]] $packageWildcardExpressions
            )

            $res = AnyInterestingPRs `
                    -Titles $titles `
                    -MaxSemVerIncrement $maxSemVerIncrement `
                    -PackageWildcardExpressions $packageWildcardExpressions
            $res | Should -BeOfType [boolean]
            $res | Should -Be $true
        }

        It 'should return true when matching patterns are specified with a SemVer increment equal to MaxSemVerIncrement (<maxSemVerIncrement>)' -TestCases @(
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 1.0.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'major'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'minor'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground'); maxSemVerIncrement = 'patch'; packageWildcardExpressions = @('Corvus.*'); }
        ) {
            param (
                [string[]] $titles,
                [string] $maxSemVerIncrement,
                [string[]] $packageWildcardExpressions
            )

            $res = AnyInterestingPRs `
                    -Titles $titles `
                    -MaxSemVerIncrement $maxSemVerIncrement `
                    -PackageWildcardExpressions $packageWildcardExpressions
            $res | Should -BeOfType [boolean]
            $res | Should -Be $true
        }
    }

    Context 'Multiple PRs' {
        It 'should return false when no patterns are specified' {
            $res = AnyInterestingPRs -Titles @(
                'Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground',
                'Bump Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @()
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return false when matching patterns are specified with a SemVer increment more than MaxSemVerIncrement' {
            $res = AnyInterestingPRs -Titles  @(
                'Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 1.0.0 in /Solutions/dependency-playground',
                'Bump Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @('Corvus.*')
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return false when matching patterns are specified but no PR matches the pattern' {
            $res = AnyInterestingPRs -Titles @(
                'Bump Foo.Bar from 0.9.0 to 0.9.1 in /Solutions/dependency-playground',
                'Bump Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground') `
                                                    -MaxSemVerIncrement 'minor' `
                                                    -PackageWildcardExpressions @('Corvus.*')
            $res | Should -BeOfType [boolean]
            $res | Should -Be $false
        }

        It 'should return true when matching patterns are specified with a SemVer increment less than MaxSemVerIncrement (<maxSemVerIncrement>)' -TestCases @(
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground', 'Bump Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'major'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground', 'Bump Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'minor'; packageWildcardExpressions = @('Corvus.*'); }
        ) {
            param (
                [string[]] $titles,
                [string] $maxSemVerIncrement,
                [string[]] $packageWildcardExpressions
            )

            $res = AnyInterestingPRs `
                    -Titles $titles `
                    -MaxSemVerIncrement $maxSemVerIncrement `
                    -PackageWildcardExpressions $packageWildcardExpressions
            $res | Should -BeOfType [boolean]
            $res | Should -Be $true
        }

        It 'should return true when matching patterns are specified with a SemVer increment equal to MaxSemVerIncrement (<maxSemVerIncrement>)' -TestCases @(
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 1.0.0 in /Solutions/dependency-playground', 'Bump Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'major'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground', 'Bump Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'minor'; packageWildcardExpressions = @('Corvus.*'); }
            @{ titles = @('Bump Corvus.Extensions.Newtonsoft.Json from 0.9.0 to 0.9.1 in /Solutions/dependency-playground', 'Bump Newtonsoft.Json from 0.9.0 to 0.10.0 in /Solutions/dependency-playground'); maxSemVerIncrement = 'patch'; packageWildcardExpressions = @('Corvus.*'); }
        ) {
            param (
                [string[]] $titles,
                [string] $maxSemVerIncrement,
                [string[]] $packageWildcardExpressions
            )

            $res = AnyInterestingPRs `
                    -Titles $titles `
                    -MaxSemVerIncrement $maxSemVerIncrement `
                    -PackageWildcardExpressions $packageWildcardExpressions
            $res | Should -BeOfType [boolean]
            $res | Should -Be $true
        }
    }


}