Skip to content

Commit

Permalink
test(rulesets): enable deletion of an existing ruleset
Browse files Browse the repository at this point in the history
for #732
  • Loading branch information
travi committed Sep 15, 2024
1 parent 8e7cbbc commit 8e877d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default class Rulesets extends Diffable {
}

update (existing, attrs) {
this.github.repos.updateRepoRuleset({ ...this.repo, ruleset_id: existing.ruleset_id, ...attrs })
return this.github.repos.updateRepoRuleset({ ...this.repo, ruleset_id: existing.ruleset_id, ...attrs })
}

remove (existing) {
return this.github.repos.deleteRepoRuleset({ ...this.repo, ruleset_id: existing.ruleset_id })
}

async add (attrs) {
Expand Down
1 change: 0 additions & 1 deletion test/integration/features/rulesets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Feature: Repository Rulesets
When a settings sync is triggered
Then the ruleset is updated

@wip
Scenario: Delete a ruleset
Given a ruleset exists for the repository
And the ruleset is removed from the config
Expand Down
10 changes: 9 additions & 1 deletion test/unit/lib/plugins/rulesets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('rulesets', () => {
github = {
repos: {
createRepoRuleset: jest.fn(),
deleteRepoRuleset: jest.fn(),
getRepoRulesets: jest.fn(),
updateRepoRuleset: jest.fn()
}
Expand All @@ -26,12 +27,18 @@ describe('rulesets', () => {
it('should sync rulesets', async () => {
const updatedValue = any.word()
const existingRulesetId = any.integer()
const removedRulesetId = any.integer()
const existingRuleset = { name: any.word(), foo: updatedValue }
const newRuleset = { name: any.word() }
const plugin = configure(github, owner, repo, [newRuleset, existingRuleset])
when(github.repos.getRepoRulesets)
.calledWith({ owner, repo })
.mockResolvedValue({ data: [{ ruleset_id: existingRulesetId, ...existingRuleset, foo: any.word() }] })
.mockResolvedValue({
data: [
{ ruleset_id: existingRulesetId, ...existingRuleset, foo: any.word() },
{ ruleset_id: removedRulesetId, name: any.word() }
]
})

await plugin.sync()

Expand All @@ -43,5 +50,6 @@ describe('rulesets', () => {
...existingRuleset,
foo: updatedValue
})
expect(github.repos.deleteRepoRuleset).toHaveBeenCalledWith({ owner, repo, ruleset_id: removedRulesetId })
})
})

0 comments on commit 8e877d1

Please sign in to comment.