Skip to content

Commit

Permalink
test(integration): defined rulesets fixtures to a failing state
Browse files Browse the repository at this point in the history
for #732
  • Loading branch information
travi committed Aug 30, 2024
1 parent 8493023 commit 5b9a0e7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/integration/features/step_definitions/rulesets-steps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { dump } from 'js-yaml'
import { StatusCodes } from 'http-status-codes'

import { Given, Then } from '@cucumber/cucumber'
import assert from 'node:assert'
import { http, HttpResponse } from 'msw'

import { repository } from './common-steps.mjs'
import settings from '../../../../lib/settings.js'

Given('no rulesets are defined for the repository', async function () {
this.server.use(
http.get(`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets`, ({ request }) =>
HttpResponse.json([])
)
)
})

Given('a ruleset is defined in the config', async function () {
this.server.use(
http.get(
`https://api.github.com/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(
settings.FILE_NAME
)}`,
({ request }) => HttpResponse.arrayBuffer(Buffer.from(dump({ rulesets: [{}] })))
),
http.post(
`https://api.github.com/repos/${repository.owner.name}/${repository.name}/rulesets`,
async ({ request }) => {
this.createdRuleset = await request.json()

return new HttpResponse(null, { status: StatusCodes.CREATED })
}
)
)
})

Then('the ruleset is enabled for the repository', async function () {
assert.deepEqual(this.createdRuleset, {})
})

0 comments on commit 5b9a0e7

Please sign in to comment.