Skip to content

Commit 4731148

Browse files
committed
Updated tests to reflect latest ruleset data type changes.
1 parent b893e4a commit 4731148

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ rulesets:
154154
Notes:
155155
- For branch protection rules, contexts defined at the org level are merged together with the sub-org and repo level contexts.
156156
- When `{{EXTERNALLY_DEFINED}}` is defined for a new branch protection rule or ruleset configuration, they will be deployed with no status checks.
157-
- When an existing branch protection rule or ruleset configuration is ammended with `{{EXTERNALLY_DEFINED}}`, the status checks in the existing rules in GitHub will remain as is.
157+
- When an existing branch protection rule or ruleset configuration is amended with `{{EXTERNALLY_DEFINED}}`, the status checks in the existing rules in GitHub will remain as is.
158158

159159
⚠️ **Warning:**
160160
When `{{EXTERNALLY_DEFINED}}` is removed from an existing branch protection rule or ruleset configuration, the status checks in the existing rules in GitHub will revert to the checks that are defined in safe-settings.

test/unit/lib/plugins/branches.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('Branches', () => {
165165
})
166166
})
167167

168-
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exists in GitHub', () => {
168+
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exist in GitHub', () => {
169169
it('it initialises the status checks with an empty list', () => {
170170
const plugin = configure(
171171
[{
@@ -194,7 +194,7 @@ describe('Branches', () => {
194194
})
195195
})
196196

197-
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exists in GitHub', () => {
197+
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exist in GitHub', () => {
198198
it('it retains the status checks from GitHub', () => {
199199
github.repos.getBranchProtection = jest.fn().mockResolvedValue({
200200
data: {

test/unit/lib/plugins/rulesets.test.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ const org_conditions = {
2222
}
2323
}
2424

25-
function generateRequestRuleset(id, name, conditions, checks) {
25+
function generateRequestRuleset(id, name, conditions, checks, org=false) {
2626
response = {
2727
id: id,
2828
name: name,
29-
source_type: 'Repository',
3029
target: 'branch',
3130
enforcement: 'active',
3231
conditions: conditions,
@@ -40,14 +39,18 @@ function generateRequestRuleset(id, name, conditions, checks) {
4039
}
4140
]
4241
}
42+
if (org) {
43+
response.source_type = 'Organization'
44+
} else {
45+
response.source_type = 'Repository'
46+
}
4347
return response
4448
}
4549

4650
function generateResponseRuleset(id, name, conditions, checks, org=false) {
4751
response = {
4852
id: id,
4953
name: name,
50-
source_type: 'Repository',
5154
target: 'branch',
5255
enforcement: 'active',
5356
conditions: conditions,
@@ -63,8 +66,10 @@ function generateResponseRuleset(id, name, conditions, checks, org=false) {
6366
headers: version,
6467
}
6568
if (org) {
69+
response.source_type = 'Organization'
6670
response.org = 'jitran'
6771
} else {
72+
response.source_type = 'Repository'
6873
response.owner = 'jitran'
6974
response.repo = 'test'
7075
}
@@ -100,8 +105,9 @@ describe('Rulesets', () => {
100105
method: 'GET',
101106
url: '/repos/jitran/test/rulesets',
102107
headers: version
103-
})
104-
}
108+
}
109+
)
110+
}
105111
})
106112

107113
describe('sync', () => {
@@ -141,7 +147,7 @@ describe('Rulesets', () => {
141147
})
142148
})
143149

144-
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exists in GitHub', () => {
150+
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exist in GitHub', () => {
145151
it('it initialises the status checks with an empty list', () => {
146152
// Mock the GitHub API response
147153
github.paginate = jest.fn().mockResolvedValue([])
@@ -175,7 +181,7 @@ describe('Rulesets', () => {
175181
})
176182
})
177183

178-
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exists in GitHub', () => {
184+
describe('when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exist in GitHub', () => {
179185
it('it retains the status checks from GitHub and everything else is reset to the safe-settings', () => {
180186
// Mock the GitHub API response
181187
github.paginate = jest.fn().mockResolvedValue([
@@ -294,7 +300,8 @@ describe('Rulesets', () => {
294300
[
295301
{ context: 'Status Check 1' },
296302
{ context: 'Status Check 2' }
297-
]
303+
],
304+
true
298305
)
299306
],
300307
'org'
@@ -318,7 +325,7 @@ describe('Rulesets', () => {
318325
})
319326
})
320327

321-
describe('[org] when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exists in GitHub', () => {
328+
describe('[org] when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and no status checks exist in GitHub', () => {
322329
it('it initialises the status checks with an empty list', () => {
323330
// Mock the GitHub API response
324331
github.paginate = jest.fn().mockResolvedValue([])
@@ -333,7 +340,8 @@ describe('Rulesets', () => {
333340
[
334341
{ context: 'Status Check 1' },
335342
{ context: '{{EXTERNALLY_DEFINED}}' }
336-
]
343+
],
344+
true
337345
)
338346
],
339347
'org'
@@ -354,7 +362,7 @@ describe('Rulesets', () => {
354362
})
355363
})
356364

357-
describe('[org] when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exists in GitHub', () => {
365+
describe('[org] when {{EXTERNALLY_DEFINED}} is present in "required_status_checks" and status checks exist in GitHub', () => {
358366
it('it retains the status checks from GitHub', () => {
359367
// Mock the GitHub API response
360368
github.paginate = jest.fn().mockResolvedValue([
@@ -365,7 +373,8 @@ describe('Rulesets', () => {
365373
[
366374
{ context: 'Custom Check 1' },
367375
{ context: 'Custom Check 2' }
368-
]
376+
],
377+
true
369378
)
370379
])
371380

@@ -379,7 +388,8 @@ describe('Rulesets', () => {
379388
[
380389
{ context: 'Status Check 1' },
381390
{ context: '{{EXTERNALLY_DEFINED}}' }
382-
]
391+
],
392+
true
383393
)
384394
],
385395
'org'

0 commit comments

Comments
 (0)