|
1 | 1 | var codebuild = require('../../lib/services/codebuild') |
| 2 | +var git = require('../../lib/git.js') |
| 3 | + |
| 4 | +// Set all module functions to jest.fn |
| 5 | +jest.mock('../../lib/git.js') |
2 | 6 |
|
3 | 7 | describe('AWS CodeBuild Provider', function() { |
4 | 8 | it('can detect codebuild', function() { |
@@ -29,17 +33,39 @@ describe('AWS CodeBuild Provider', function() { |
29 | 33 |
|
30 | 34 | it('throws if branch name cannot be detected', function() { |
31 | 35 | delete process.env.CODEBUILD_WEBHOOK_HEAD_REF |
| 36 | + git.branch.mockImplementation(function() { |
| 37 | + throw new Error() |
| 38 | + }) |
32 | 39 | expect(function() { |
33 | 40 | codebuild.configuration() |
34 | 41 | }).toThrow() |
35 | 42 | }) |
36 | 43 |
|
37 | | - it('throws if pr number cannot be detected', function() { |
| 44 | + it('Test build triggered via AWS SDK', function() { |
| 45 | + delete process.env.CODEBUILD_WEBHOOK_HEAD_REF |
| 46 | + git.branch.mockReturnValue('master') |
| 47 | + expect(codebuild.configuration()).toEqual({ |
| 48 | + service: 'codebuild', |
| 49 | + build: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', |
| 50 | + job: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', |
| 51 | + commit: '39ec2418eca4c539d765574a1c68f3bd77e8c549', |
| 52 | + branch: 'master', |
| 53 | + pr: undefined, |
| 54 | + slug: 'my-org/my-project', |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + it('Test build triggered via Github Webhook', function() { |
38 | 59 | process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master' |
39 | | - delete process.env.CODEBUILD_SOURCE_VERSION |
40 | | - expect(function() { |
41 | | - codebuild.configuration() |
42 | | - }).toThrow() |
| 60 | + expect(codebuild.configuration()).toEqual({ |
| 61 | + service: 'codebuild', |
| 62 | + build: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', |
| 63 | + job: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', |
| 64 | + commit: '39ec2418eca4c539d765574a1c68f3bd77e8c549', |
| 65 | + branch: 'master', |
| 66 | + pr: '1', |
| 67 | + slug: 'my-org/my-project', |
| 68 | + }) |
43 | 69 | }) |
44 | 70 |
|
45 | 71 | it('throws if slug cannot be detected', function() { |
|
0 commit comments