/
buildrequest.controller.spec.coffee
89 lines (84 loc) · 3.58 KB
/
buildrequest.controller.spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
beforeEach module 'app'
describe 'buildrequest controller', ->
buildbotService = mqService = $scope = $httpBackend = $rootScope = null
$timeout = createController = $stateParams = null
goneto = null
# overrride "$state"
beforeEach module(($provide) ->
$provide.value "$state",
go: (args...) -> goneto = args
$provide.value "$stateParams",
buildrequest: 1
null # those module callbacks need to return null!
)
injected = ($injector) ->
$httpBackend = $injector.get('$httpBackend')
decorateHttpBackend($httpBackend)
$rootScope = $injector.get('$rootScope')
$scope = $rootScope.$new()
mqService = $injector.get('mqService')
$timeout = $injector.get('$timeout')
$stateParams = $injector.get('$stateParams')
$controller = $injector.get('$controller')
$q = $injector.get('$q')
# stub out the actual backend of mqservice
spyOn(mqService,"setBaseUrl").and.returnValue(null)
spyOn(mqService,"startConsuming").and.returnValue($q.when( -> ))
spyOn(mqService,"stopConsuming").and.returnValue(null)
buildbotService = $injector.get('buildbotService')
createController = ->
return $controller 'buildrequestController',
$scope: $scope
$httpBackend.expectDataGET('buildrequests/1')
$httpBackend.expectDataGET('builders/1')
$httpBackend.expectDataGET('buildsets/1')
beforeEach(inject(injected))
afterEach ->
$httpBackend.verifyNoOutstandingExpectation()
$httpBackend.verifyNoOutstandingRequest()
it 'should query for buildrequest', ->
controller = createController()
$httpBackend.flush()
$scope.buildrequest.claimed = true
$httpBackend.expectDataGET('builds?buildrequestid=1')
$httpBackend.flush()
expect($scope.builds[0].buildid).toBeDefined()
$timeout.flush()
$httpBackend.verifyNoOutstandingRequest()
it 'should query for builds again if first query returns 0', ->
controller = createController()
$httpBackend.flush()
$scope.buildrequest.claimed = true
$httpBackend.expectDataGET 'builds?buildrequestid=1',
nItems:0
$httpBackend.flush()
expect($scope.builds.length).toBe(0)
$httpBackend.expectDataGET 'builds?buildrequestid=1',
nItems:0
$timeout.flush()
$httpBackend.flush()
expect($scope.builds.length).toBe(0)
$httpBackend.expectDataGET 'builds?buildrequestid=1',
nItems:1
$timeout.flush()
$httpBackend.flush()
expect($scope.builds[0].buildid).toBeDefined()
$timeout.flush()
$httpBackend.verifyNoOutstandingRequest()
it 'should go to build page if build started', ->
$stateParams.redirect_to_build = 1
controller = createController()
$httpBackend.flush()
$scope.buildrequest.claimed = true
$httpBackend.expectDataGET 'builds?buildrequestid=1',
nItems:0
$httpBackend.flush()
expect($scope.builds.length).toBe(0)
$httpBackend.expectDataGET 'builds?buildrequestid=1',
nItems:1
$timeout.flush()
$httpBackend.flush()
expect($scope.builds[0].buildid).toBeDefined()
$timeout.flush()
$httpBackend.verifyNoOutstandingRequest()
expect(goneto).toEqual([ 'build', { builder : 3, build : 1 } ])