|
| 1 | +const nock = require('nock') |
| 2 | + |
| 3 | +const dbs = require('../../lib/dbs') |
| 4 | +const removeIfExists = require('../helpers/remove-if-exists') |
| 5 | + |
| 6 | +describe('payment-required', async () => { |
| 7 | + beforeAll(async () => { |
| 8 | + const { repositories, installations } = await dbs() |
| 9 | + |
| 10 | + await installations.put({ |
| 11 | + _id: '111', |
| 12 | + installation: 11, |
| 13 | + plan: 'free' |
| 14 | + }) |
| 15 | + |
| 16 | + await repositories.put({ |
| 17 | + _id: '1_payment-required', |
| 18 | + accountId: '111', |
| 19 | + fullName: 'jacoba/private', |
| 20 | + enabled: true, |
| 21 | + private: true |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + jest.resetModules() |
| 27 | + jest.clearAllMocks() |
| 28 | + }) |
| 29 | + |
| 30 | + afterAll(async () => { |
| 31 | + const { repositories, installations } = await dbs() |
| 32 | + await Promise.all([ |
| 33 | + removeIfExists(repositories, 'payment-required'), |
| 34 | + removeIfExists(installations, '111') |
| 35 | + ]) |
| 36 | + }) |
| 37 | + |
| 38 | + test('create payment-required issue', async () => { |
| 39 | + expect.assertions(9) |
| 40 | + const githubMock = nock('https://api.github.com') |
| 41 | + .post('/app/installations/11/access_tokens') |
| 42 | + .optionally() |
| 43 | + .reply(200, { |
| 44 | + token: 'secret' |
| 45 | + }) |
| 46 | + .get('/rate_limit') |
| 47 | + .optionally() |
| 48 | + .reply(200) |
| 49 | + .post('/repos/jacoba/private/issues', ({ title, body, labels }) => { |
| 50 | + expect(title).toEqual('Payment required') |
| 51 | + expect(body).toMatch(/🚨 You privatized your repo. 🚨/) |
| 52 | + expect(body).toMatch(/Please enter your payment information at/) |
| 53 | + expect(labels[0]).toEqual('greenkeeper') |
| 54 | + return true |
| 55 | + }) |
| 56 | + .reply(201, () => { |
| 57 | + return { |
| 58 | + number: 10 |
| 59 | + } |
| 60 | + }) |
| 61 | + |
| 62 | + const paymentRequired = require('../../jobs/payment-required') |
| 63 | + const newJob = await paymentRequired({ accountId: '111', repositoryId: '1_payment-required' }) |
| 64 | + expect(newJob).toBeFalsy() |
| 65 | + |
| 66 | + const { repositories } = await dbs() |
| 67 | + const issue = await repositories.get('1_payment-required:issue:10') |
| 68 | + expect(issue.initial).toBeFalsy() |
| 69 | + expect(issue.type).toEqual('issue') |
| 70 | + expect(issue.number).toBe(10) |
| 71 | + expect(issue.repositoryId).toBe('1_payment-required') |
| 72 | + githubMock.done() |
| 73 | + }) |
| 74 | +}) |
0 commit comments