| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | // Imports
 | 
					
						
							|  |  |  | import * as express from 'express'; | 
					
						
							|  |  |  | import * as http from 'http'; | 
					
						
							|  |  |  | import * as supertest from 'supertest'; | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | import {GithubPullRequests} from '../../lib/common/github-pull-requests'; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | import {BuildCreator} from '../../lib/upload-server/build-creator'; | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  | import {ChangedPrVisibilityEvent, CreatedBuildEvent} from '../../lib/upload-server/build-events'; | 
					
						
							|  |  |  | import {BUILD_VERIFICATION_STATUS, BuildVerifier} from '../../lib/upload-server/build-verifier'; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | import {uploadServerFactory as usf} from '../../lib/upload-server/upload-server-factory'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Tests
 | 
					
						
							|  |  |  | describe('uploadServerFactory', () => { | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |   const defaultConfig = { | 
					
						
							|  |  |  |     buildsDir: 'builds/dir', | 
					
						
							| 
									
										
										
										
											2017-03-02 00:04:03 +02:00
										 |  |  |     domainName: 'domain.name', | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     githubOrganization: 'organization', | 
					
						
							|  |  |  |     githubTeamSlugs: ['team1', 'team2'], | 
					
						
							|  |  |  |     githubToken: '12345', | 
					
						
							|  |  |  |     repoSlug: 'repo/slug', | 
					
						
							|  |  |  |     secret: 'secret', | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |     trustedPrLabel: 'trusted: pr-label', | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Helpers
 | 
					
						
							|  |  |  |   const createUploadServer = (partialConfig: Partial<typeof defaultConfig> = {}) => | 
					
						
							| 
									
										
										
										
											2017-06-17 21:03:10 +03:00
										 |  |  |     usf.create({...defaultConfig, ...partialConfig} as typeof defaultConfig); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('create()', () => { | 
					
						
							|  |  |  |     let usfCreateMiddlewareSpy: jasmine.Spy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       usfCreateMiddlewareSpy = spyOn(usf as any, 'createMiddleware').and.callThrough(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 00:04:03 +02:00
										 |  |  |     it('should throw if \'buildsDir\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({buildsDir: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'buildsDir\'!'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should throw if \'domainName\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({domainName: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'domainName\'!'); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should throw if \'githubToken\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({githubToken: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'githubToken\'!'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should throw if \'githubOrganization\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({githubOrganization: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'organization\'!'); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should throw if \'githubTeamSlugs\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({githubTeamSlugs: []})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'allowedTeamSlugs\'!'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should throw if \'repoSlug\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({repoSlug: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'repoSlug\'!'); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should throw if \'secret\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({secret: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'secret\'!'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |     it('should throw if \'trustedPrLabel\' is missing or empty', () => { | 
					
						
							|  |  |  |       expect(() => createUploadServer({trustedPrLabel: ''})). | 
					
						
							|  |  |  |         toThrowError('Missing or empty required parameter \'trustedPrLabel\'!'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should return an http.Server', () => { | 
					
						
							|  |  |  |       const httpCreateServerSpy = spyOn(http, 'createServer').and.callThrough(); | 
					
						
							|  |  |  |       const server = createUploadServer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(server).toBe(httpCreateServerSpy.calls.mostRecent().returnValue); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     it('should create and use an appropriate BuildCreator', () => { | 
					
						
							|  |  |  |       const usfCreateBuildCreatorSpy = spyOn(usf as any, 'createBuildCreator').and.callThrough(); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       createUploadServer(); | 
					
						
							|  |  |  |       const buildCreator: BuildCreator = usfCreateBuildCreatorSpy.calls.mostRecent().returnValue; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       expect(usfCreateMiddlewareSpy).toHaveBeenCalledWith(jasmine.any(BuildVerifier), buildCreator); | 
					
						
							| 
									
										
										
										
											2017-03-02 00:04:03 +02:00
										 |  |  |       expect(usfCreateBuildCreatorSpy).toHaveBeenCalledWith('builds/dir', '12345', 'repo/slug', 'domain.name'); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should create and use an appropriate middleware', () => { | 
					
						
							|  |  |  |       const httpCreateServerSpy = spyOn(http, 'createServer').and.callThrough(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       createUploadServer(); | 
					
						
							|  |  |  |       const middleware: express.Express = usfCreateMiddlewareSpy.calls.mostRecent().returnValue; | 
					
						
							|  |  |  |       const buildVerifier = jasmine.any(BuildVerifier); | 
					
						
							|  |  |  |       const buildCreator = jasmine.any(BuildCreator); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(httpCreateServerSpy).toHaveBeenCalledWith(middleware); | 
					
						
							|  |  |  |       expect(usfCreateMiddlewareSpy).toHaveBeenCalledWith(buildVerifier, buildCreator); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should log the server address info on \'listening\'', () => { | 
					
						
							|  |  |  |       const consoleInfoSpy = spyOn(console, 'info'); | 
					
						
							| 
									
										
										
										
											2017-09-23 15:24:04 +03:00
										 |  |  |       const server = createUploadServer(); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       server.address = () => ({address: 'foo', family: '', port: 1337}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(consoleInfoSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       server.emit('listening'); | 
					
						
							|  |  |  |       expect(consoleInfoSpy).toHaveBeenCalledWith('Up and running (and listening on foo:1337)...'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Protected methods
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |   describe('createBuildCreator()', () => { | 
					
						
							|  |  |  |     let buildCreator: BuildCreator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       buildCreator = (usf as any).createBuildCreator( | 
					
						
							|  |  |  |         defaultConfig.buildsDir, | 
					
						
							|  |  |  |         defaultConfig.githubToken, | 
					
						
							|  |  |  |         defaultConfig.repoSlug, | 
					
						
							| 
									
										
										
										
											2017-03-02 00:04:03 +02:00
										 |  |  |         defaultConfig.domainName, | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should pass the \'buildsDir\' to the BuildCreator', () => { | 
					
						
							|  |  |  |       expect((buildCreator as any).buildsDir).toBe('builds/dir'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |     describe('on \'build.created\'', () => { | 
					
						
							|  |  |  |       let prsAddCommentSpy: jasmine.Spy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEach(() => prsAddCommentSpy = spyOn(GithubPullRequests.prototype, 'addComment')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       it('should post a comment on GitHub for public previews', () => { | 
					
						
							|  |  |  |         const commentBody = 'You can preview 1234567890 at https://pr42-1234567890.domain.name/.'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         buildCreator.emit(CreatedBuildEvent.type, {pr: 42, sha: '1234567890', isPublic: true}); | 
					
						
							|  |  |  |         expect(prsAddCommentSpy).toHaveBeenCalledWith(42, commentBody); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not post a comment on GitHub for non-public previews', () => { | 
					
						
							|  |  |  |         buildCreator.emit(CreatedBuildEvent.type, {pr: 42, sha: '1234567890', isPublic: false}); | 
					
						
							|  |  |  |         expect(prsAddCommentSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('on \'pr.changedVisibility\'', () => { | 
					
						
							|  |  |  |       let prsAddCommentSpy: jasmine.Spy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEach(() => prsAddCommentSpy = spyOn(GithubPullRequests.prototype, 'addComment')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should post a comment on GitHub (for all SHAs) for PRs made public', () => { | 
					
						
							|  |  |  |         const commentBody = 'You can preview 12345 at https://pr42-12345.domain.name/.\n' + | 
					
						
							|  |  |  |                             'You can preview 67890 at https://pr42-67890.domain.name/.'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         buildCreator.emit(ChangedPrVisibilityEvent.type, {pr: 42, shas: ['12345', '67890'], isPublic: true}); | 
					
						
							|  |  |  |         expect(prsAddCommentSpy).toHaveBeenCalledWith(42, commentBody); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not post a comment on GitHub if no SHAs were affected', () => { | 
					
						
							|  |  |  |         buildCreator.emit(ChangedPrVisibilityEvent.type, {pr: 42, shas: [], isPublic: true}); | 
					
						
							|  |  |  |         expect(prsAddCommentSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not post a comment on GitHub for PRs made non-public', () => { | 
					
						
							|  |  |  |         buildCreator.emit(ChangedPrVisibilityEvent.type, {pr: 42, shas: ['12345', '67890'], isPublic: false}); | 
					
						
							|  |  |  |         expect(prsAddCommentSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should pass the correct \'githubToken\' and \'repoSlug\' to GithubPullRequests', () => { | 
					
						
							|  |  |  |       const prsAddCommentSpy = spyOn(GithubPullRequests.prototype, 'addComment'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       buildCreator.emit(CreatedBuildEvent.type, {pr: 42, sha: '1234567890', isPublic: true}); | 
					
						
							|  |  |  |       buildCreator.emit(ChangedPrVisibilityEvent.type, {pr: 42, shas: ['12345', '67890'], isPublic: true}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const allCalls = prsAddCommentSpy.calls.all(); | 
					
						
							|  |  |  |       const prs = allCalls[0].object; | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       expect(prsAddCommentSpy).toHaveBeenCalledTimes(2); | 
					
						
							|  |  |  |       expect(prs).toBe(allCalls[1].object); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       expect(prs).toEqual(jasmine.any(GithubPullRequests)); | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       expect(prs.repoSlug).toBe('repo/slug'); | 
					
						
							|  |  |  |       expect(prs.requestHeaders.Authorization).toContain('12345'); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |   describe('createMiddleware()', () => { | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |     let buildVerifier: BuildVerifier; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     let buildCreator: BuildCreator; | 
					
						
							|  |  |  |     let agent: supertest.SuperTest<supertest.Test>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Helpers
 | 
					
						
							|  |  |  |     const promisifyRequest = (req: supertest.Request) => | 
					
						
							|  |  |  |       new Promise((resolve, reject) => req.end(err => err ? reject(err) : resolve())); | 
					
						
							|  |  |  |     const verifyRequests = (reqs: supertest.Request[], done: jasmine.DoneFn) => | 
					
						
							|  |  |  |       Promise.all(reqs.map(promisifyRequest)).then(done, done.fail); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       buildVerifier = new BuildVerifier( | 
					
						
							|  |  |  |         defaultConfig.secret, | 
					
						
							|  |  |  |         defaultConfig.githubToken, | 
					
						
							|  |  |  |         defaultConfig.repoSlug, | 
					
						
							|  |  |  |         defaultConfig.githubOrganization, | 
					
						
							|  |  |  |         defaultConfig.githubTeamSlugs, | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |         defaultConfig.trustedPrLabel, | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       ); | 
					
						
							|  |  |  |       buildCreator = new BuildCreator(defaultConfig.buildsDir); | 
					
						
							|  |  |  |       agent = supertest.agent((usf as any).createMiddleware(buildVerifier, buildCreator)); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       spyOn(console, 'error'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('GET /create-build/<pr>/<sha>', () => { | 
					
						
							|  |  |  |       const pr = '9'; | 
					
						
							|  |  |  |       const sha = '9'.repeat(40); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       let buildVerifierVerifySpy: jasmine.Spy; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       let buildCreatorCreateSpy: jasmine.Spy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |         const verStatus = BUILD_VERIFICATION_STATUS.verifiedAndTrusted; | 
					
						
							|  |  |  |         buildVerifierVerifySpy = spyOn(buildVerifier, 'verify').and.returnValue(Promise.resolve(verStatus)); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |         buildCreatorCreateSpy = spyOn(buildCreator, 'create').and.returnValue(Promise.resolve()); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |       it('should respond with 404 for non-GET requests', done => { | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         verifyRequests([ | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |           agent.put(`/create-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.post(`/create-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.patch(`/create-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.delete(`/create-build/${pr}/${sha}`).expect(404), | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       it('should respond with 401 for requests without an \'AUTHORIZATION\' header', done => { | 
					
						
							|  |  |  |         const url = `/create-build/${pr}/${sha}`; | 
					
						
							|  |  |  |         const responseBody = `Missing or empty 'AUTHORIZATION' header in request: GET ${url}`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           agent.get(url).expect(401, responseBody), | 
					
						
							|  |  |  |           agent.get(url).set('AUTHORIZATION', '').expect(401, responseBody), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       it('should respond with 400 for requests without an \'X-FILE\' header', done => { | 
					
						
							|  |  |  |         const url = `/create-build/${pr}/${sha}`; | 
					
						
							|  |  |  |         const responseBody = `Missing or empty 'X-FILE' header in request: GET ${url}`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |         const request1 = agent.get(url).set('AUTHORIZATION', 'foo'); | 
					
						
							|  |  |  |         const request2 = agent.get(url).set('AUTHORIZATION', 'foo').set('X-FILE', ''); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         verifyRequests([ | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |           request1.expect(400, responseBody), | 
					
						
							|  |  |  |           request2.expect(400, responseBody), | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 404 for unknown paths', done => { | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           agent.get(`/foo/create-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/foo-create-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/fooncreate-build/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/create-build/foo/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/create-build-foo/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/create-buildnfoo/${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/create-build/pr${pr}/${sha}`).expect(404), | 
					
						
							|  |  |  |           agent.get(`/create-build/${pr}/${sha}42`).expect(404), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       it('should call \'BuildVerifier#verify()\' with the correct arguments', done => { | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         const req = agent. | 
					
						
							|  |  |  |           get(`/create-build/${pr}/${sha}`). | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |           set('AUTHORIZATION', 'foo'). | 
					
						
							|  |  |  |           set('X-FILE', 'bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         promisifyRequest(req). | 
					
						
							|  |  |  |           then(() => expect(buildVerifierVerifySpy).toHaveBeenCalledWith(9, 'foo')). | 
					
						
							|  |  |  |           then(done, done.fail); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should propagate errors from BuildVerifier', done => { | 
					
						
							|  |  |  |         buildVerifierVerifySpy.and.callFake(() => Promise.reject('Test')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const req = agent. | 
					
						
							|  |  |  |           get(`/create-build/${pr}/${sha}`). | 
					
						
							|  |  |  |           set('AUTHORIZATION', 'foo'). | 
					
						
							|  |  |  |           set('X-FILE', 'bar'). | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |           expect(500, 'Test'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |         promisifyRequest(req). | 
					
						
							|  |  |  |           then(() => { | 
					
						
							|  |  |  |             expect(buildVerifierVerifySpy).toHaveBeenCalledWith(9, 'foo'); | 
					
						
							|  |  |  |             expect(buildCreatorCreateSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |           }). | 
					
						
							|  |  |  |           then(done, done.fail); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       it('should call \'BuildCreator#create()\' with the correct arguments', done => { | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |         buildVerifierVerifySpy.and.returnValues( | 
					
						
							|  |  |  |             Promise.resolve(BUILD_VERIFICATION_STATUS.verifiedAndTrusted), | 
					
						
							|  |  |  |             Promise.resolve(BUILD_VERIFICATION_STATUS.verifiedNotTrusted)); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |         const req1 = agent.get(`/create-build/${pr}/${sha}`).set('AUTHORIZATION', 'foo').set('X-FILE', 'bar'); | 
					
						
							|  |  |  |         const req2 = agent.get(`/create-build/${pr}/${sha}`).set('AUTHORIZATION', 'foo').set('X-FILE', 'bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Promise.all([ | 
					
						
							|  |  |  |           promisifyRequest(req1).then(() => expect(buildCreatorCreateSpy).toHaveBeenCalledWith(pr, sha, 'bar', true)), | 
					
						
							|  |  |  |           promisifyRequest(req2).then(() => expect(buildCreatorCreateSpy).toHaveBeenCalledWith(pr, sha, 'bar', false)), | 
					
						
							|  |  |  |         ]).then(done, done.fail); | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should propagate errors from BuildCreator', done => { | 
					
						
							|  |  |  |         buildCreatorCreateSpy.and.callFake(() => Promise.reject('Test')); | 
					
						
							|  |  |  |         const req = agent. | 
					
						
							|  |  |  |           get(`/create-build/${pr}/${sha}`). | 
					
						
							|  |  |  |           set('AUTHORIZATION', 'foo'). | 
					
						
							|  |  |  |           set('X-FILE', 'bar'). | 
					
						
							|  |  |  |           expect(500, 'Test'); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([req], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       it('should respond with 201 on successful upload (for public builds)', done => { | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |         const req = agent. | 
					
						
							|  |  |  |           get(`/create-build/${pr}/${sha}`). | 
					
						
							|  |  |  |           set('AUTHORIZATION', 'foo'). | 
					
						
							|  |  |  |           set('X-FILE', 'bar'). | 
					
						
							|  |  |  |           expect(201, http.STATUS_CODES[201]); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |         verifyRequests([req], done); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 01:15:07 +03:00
										 |  |  |       it('should respond with 202 on successful upload (for hidden builds)', done => { | 
					
						
							|  |  |  |         buildVerifierVerifySpy.and.returnValue(Promise.resolve(BUILD_VERIFICATION_STATUS.verifiedNotTrusted)); | 
					
						
							|  |  |  |         const req = agent. | 
					
						
							|  |  |  |           get(`/create-build/${pr}/${sha}`). | 
					
						
							|  |  |  |           set('AUTHORIZATION', 'foo'). | 
					
						
							|  |  |  |           set('X-FILE', 'bar'). | 
					
						
							|  |  |  |           expect(202, http.STATUS_CODES[202]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([req], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |       it('should reject PRs with leading zeros', done => { | 
					
						
							|  |  |  |         verifyRequests([agent.get(`/create-build/0${pr}/${sha}`).expect(404)], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 09:41:04 +02:00
										 |  |  |       it('should accept SHAs with leading zeros (but not trim the zeros)', done => { | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         const sha40 = '0'.repeat(40); | 
					
						
							| 
									
										
										
										
											2017-03-12 09:41:04 +02:00
										 |  |  |         const sha41 = `0${sha40}`; | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 09:41:04 +02:00
										 |  |  |         const request40 = agent.get(`/create-build/${pr}/${sha40}`).set('AUTHORIZATION', 'foo').set('X-FILE', 'bar'); | 
					
						
							|  |  |  |         const request41 = agent.get(`/create-build/${pr}/${sha41}`).set('AUTHORIZATION', 'baz').set('X-FILE', 'qux'); | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Promise.all([ | 
					
						
							| 
									
										
										
										
											2017-02-28 21:10:46 +02:00
										 |  |  |           promisifyRequest(request40.expect(201)), | 
					
						
							| 
									
										
										
										
											2017-03-12 09:41:04 +02:00
										 |  |  |           promisifyRequest(request41.expect(404)), | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         ]).then(done, done.fail); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('GET /health-check', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 200', done => { | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           agent.get('/health-check').expect(200), | 
					
						
							|  |  |  |           agent.get('/health-check/').expect(200), | 
					
						
							|  |  |  |          ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |       it('should respond with 404 for non-GET requests', done => { | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         verifyRequests([ | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |           agent.put('/health-check').expect(404), | 
					
						
							|  |  |  |           agent.post('/health-check').expect(404), | 
					
						
							|  |  |  |           agent.patch('/health-check').expect(404), | 
					
						
							|  |  |  |           agent.delete('/health-check').expect(404), | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 404 if the path does not match exactly', done => { | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           agent.get('/health-check/foo').expect(404), | 
					
						
							|  |  |  |           agent.get('/health-check-foo').expect(404), | 
					
						
							|  |  |  |           agent.get('/health-checknfoo').expect(404), | 
					
						
							|  |  |  |           agent.get('/foo/health-check').expect(404), | 
					
						
							|  |  |  |           agent.get('/foo-health-check').expect(404), | 
					
						
							|  |  |  |           agent.get('/foonhealth-check').expect(404), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 19:43:02 +03:00
										 |  |  |     describe('POST /pr-updated', () => { | 
					
						
							|  |  |  |       const pr = '9'; | 
					
						
							|  |  |  |       const url = '/pr-updated'; | 
					
						
							|  |  |  |       let bvGetPrIsTrustedSpy: jasmine.Spy; | 
					
						
							|  |  |  |       let bcUpdatePrVisibilitySpy: jasmine.Spy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Helpers
 | 
					
						
							|  |  |  |       const createRequest = (num: number, action?: string) => | 
					
						
							|  |  |  |         agent.post(url).send({number: num, action}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEach(() => { | 
					
						
							|  |  |  |         bvGetPrIsTrustedSpy = spyOn(buildVerifier, 'getPrIsTrusted'); | 
					
						
							|  |  |  |         bcUpdatePrVisibilitySpy = spyOn(buildCreator, 'updatePrVisibility'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 404 for non-POST requests', done => { | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           agent.get(url).expect(404), | 
					
						
							|  |  |  |           agent.put(url).expect(404), | 
					
						
							|  |  |  |           agent.patch(url).expect(404), | 
					
						
							|  |  |  |           agent.delete(url).expect(404), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 400 for requests without a payload', done => { | 
					
						
							|  |  |  |         const responseBody = `Missing or empty 'number' field in request: POST ${url} {}`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const request1 = agent.post(url); | 
					
						
							|  |  |  |         const request2 = agent.post(url).send(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           request1.expect(400, responseBody), | 
					
						
							|  |  |  |           request2.expect(400, responseBody), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should respond with 400 for requests without a \'number\' field', done => { | 
					
						
							|  |  |  |         const responseBodyPrefix = `Missing or empty 'number' field in request: POST ${url}`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const request1 = agent.post(url).send({}); | 
					
						
							|  |  |  |         const request2 = agent.post(url).send({number: null}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							|  |  |  |           request1.expect(400, `${responseBodyPrefix} {}`), | 
					
						
							|  |  |  |           request2.expect(400, `${responseBodyPrefix} {"number":null}`), | 
					
						
							|  |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should call \'BuildVerifier#gtPrIsTrusted()\' with the correct arguments', done => { | 
					
						
							|  |  |  |         const req = createRequest(+pr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         promisifyRequest(req). | 
					
						
							|  |  |  |           then(() => expect(bvGetPrIsTrustedSpy).toHaveBeenCalledWith(9)). | 
					
						
							|  |  |  |           then(done, done.fail); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should propagate errors from BuildVerifier', done => { | 
					
						
							|  |  |  |         bvGetPrIsTrustedSpy.and.callFake(() => Promise.reject('Test')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const req = createRequest(+pr).expect(500, 'Test'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         promisifyRequest(req). | 
					
						
							|  |  |  |           then(() => { | 
					
						
							|  |  |  |             expect(bvGetPrIsTrustedSpy).toHaveBeenCalledWith(9); | 
					
						
							|  |  |  |             expect(bcUpdatePrVisibilitySpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |           }). | 
					
						
							|  |  |  |           then(done, done.fail); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should call \'BuildCreator#updatePrVisibility()\' with the correct arguments', done => { | 
					
						
							|  |  |  |         bvGetPrIsTrustedSpy.and.callFake((pr2: number) => Promise.resolve(pr2 === 42)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const req1 = createRequest(24); | 
					
						
							|  |  |  |         const req2 = createRequest(42); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Promise.all([ | 
					
						
							|  |  |  |           promisifyRequest(req1).then(() => expect(bcUpdatePrVisibilitySpy).toHaveBeenCalledWith('24', false)), | 
					
						
							|  |  |  |           promisifyRequest(req2).then(() => expect(bcUpdatePrVisibilitySpy).toHaveBeenCalledWith('42', true)), | 
					
						
							|  |  |  |         ]).then(done, done.fail); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should propagate errors from BuildCreator', done => { | 
					
						
							|  |  |  |         bcUpdatePrVisibilitySpy.and.callFake(() => Promise.reject('Test')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const req = createRequest(+pr).expect(500, 'Test'); | 
					
						
							|  |  |  |         verifyRequests([req], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('on success', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should respond with 200 (action: undefined)', done => { | 
					
						
							|  |  |  |           bvGetPrIsTrustedSpy.and.returnValues(Promise.resolve(true), Promise.resolve(false)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const reqs = [4, 2].map(num => createRequest(num).expect(200, http.STATUS_CODES[200])); | 
					
						
							|  |  |  |           verifyRequests(reqs, done); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should respond with 200 (action: labeled)', done => { | 
					
						
							|  |  |  |           bvGetPrIsTrustedSpy.and.returnValues(Promise.resolve(true), Promise.resolve(false)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const reqs = [4, 2].map(num => createRequest(num, 'labeled').expect(200, http.STATUS_CODES[200])); | 
					
						
							|  |  |  |           verifyRequests(reqs, done); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should respond with 200 (action: unlabeled)', done => { | 
					
						
							|  |  |  |           bvGetPrIsTrustedSpy.and.returnValues(Promise.resolve(true), Promise.resolve(false)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const reqs = [4, 2].map(num => createRequest(num, 'unlabeled').expect(200, http.STATUS_CODES[200])); | 
					
						
							|  |  |  |           verifyRequests(reqs, done); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should respond with 200 (and do nothing) if \'action\' implies no visibility change', done => { | 
					
						
							|  |  |  |           const promises = ['foo', 'notlabeled']. | 
					
						
							|  |  |  |             map(action => createRequest(+pr, action).expect(200, http.STATUS_CODES[200])). | 
					
						
							|  |  |  |             map(promisifyRequest); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Promise.all(promises). | 
					
						
							|  |  |  |             then(() => { | 
					
						
							|  |  |  |               expect(bvGetPrIsTrustedSpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |               expect(bcUpdatePrVisibilitySpy).not.toHaveBeenCalled(); | 
					
						
							|  |  |  |             }). | 
					
						
							|  |  |  |             then(done, done.fail); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |     describe('ALL *', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |       it('should respond with 404', done => { | 
					
						
							|  |  |  |         const responseFor = (method: string) => `Unknown resource in request: ${method.toUpperCase()} /some/url`; | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         verifyRequests([ | 
					
						
							| 
									
										
										
										
											2017-06-27 20:14:41 +03:00
										 |  |  |           agent.get('/some/url').expect(404, responseFor('get')), | 
					
						
							|  |  |  |           agent.put('/some/url').expect(404, responseFor('put')), | 
					
						
							|  |  |  |           agent.post('/some/url').expect(404, responseFor('post')), | 
					
						
							|  |  |  |           agent.patch('/some/url').expect(404, responseFor('patch')), | 
					
						
							|  |  |  |           agent.delete('/some/url').expect(404, responseFor('delete')), | 
					
						
							| 
									
										
										
										
											2017-02-06 20:40:28 +02:00
										 |  |  |         ], done); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |