|
| 1 | +const { initializeNock, loadInstance, teardownNock, repository, buildTriggerEvent } = require('../common') |
| 2 | +const path = require('path') |
| 3 | +const fs = require('fs') |
| 4 | +const settings = require('../../../lib/settings') |
| 5 | +const { OK, CREATED, NO_CONTENT } = require('http-status-codes') |
| 6 | +describe('branches plugin', function () { |
| 7 | + let probot, githubScope |
| 8 | + |
| 9 | + beforeEach(async () => { |
| 10 | + githubScope = initializeNock() |
| 11 | + probot = await loadInstance() |
| 12 | + }) |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + teardownNock(githubScope) |
| 16 | + }) |
| 17 | + |
| 18 | + it('configures labels', async () => { |
| 19 | + const pathToConfig = path.resolve(__dirname, '..', '..', 'fixtures', 'labels-config.yml') |
| 20 | + const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8')) |
| 21 | + const config = configFile.toString() |
| 22 | + githubScope |
| 23 | + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(settings.FILE_NAME)}`) |
| 24 | + .reply(OK, config) |
| 25 | + githubScope.get(`/repos/${repository.owner.name}/${repository.name}/labels?per_page=100`).reply(OK, [ |
| 26 | + { name: 'bug', color: 'ee0701' }, |
| 27 | + { name: 'duplicate', color: 'cccccc' }, |
| 28 | + { name: 'help wanted', color: '128A0C' } |
| 29 | + ]) |
| 30 | + githubScope |
| 31 | + .post(`/repos/${repository.owner.name}/${repository.name}/labels`, body => { |
| 32 | + expect(body).toMatchObject({ name: 'enhancement', color: '008672' }) |
| 33 | + return true |
| 34 | + }) |
| 35 | + .reply(CREATED) |
| 36 | + githubScope |
| 37 | + .patch(`/repos/${repository.owner.name}/${repository.name}/labels/help%20wanted`, body => { |
| 38 | + expect(body).toMatchObject({ color: 'd876e3' }) |
| 39 | + return true |
| 40 | + }) |
| 41 | + .reply(OK) |
| 42 | + githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/labels/duplicate`).reply(NO_CONTENT) |
| 43 | + |
| 44 | + await probot.receive(buildTriggerEvent()) |
| 45 | + }) |
| 46 | +}) |
0 commit comments