|
|
@@ -22,37 +22,60 @@ describe "HistoryController", ->
|
|
|
@next = sinon.stub()
|
|
|
@settings.apis =
|
|
|
trackchanges:
|
|
|
+ enabled: false
|
|
|
url: "http://trackchanges.example.com"
|
|
|
+ project_history:
|
|
|
+ url: "http://project_history.example.com"
|
|
|
@proxy =
|
|
|
events: {}
|
|
|
pipe: sinon.stub()
|
|
|
on: (event, handler) -> @events[event] = handler
|
|
|
@request.returns @proxy
|
|
|
- @HistoryController.proxyToHistoryApi @req, @res, @next
|
|
|
|
|
|
describe "successfully", ->
|
|
|
- it "should get the user id", ->
|
|
|
- @AuthenticationController.getLoggedInUserId
|
|
|
- .calledWith(@req)
|
|
|
- .should.equal true
|
|
|
-
|
|
|
- it "should call the track changes api", ->
|
|
|
- @request
|
|
|
- .calledWith({
|
|
|
- url: "#{@settings.apis.trackchanges.url}#{@req.url}"
|
|
|
- method: @req.method
|
|
|
- headers:
|
|
|
- "X-User-Id": @user_id
|
|
|
- })
|
|
|
- .should.equal true
|
|
|
-
|
|
|
- it "should pipe the response to the client", ->
|
|
|
- @proxy.pipe
|
|
|
- .calledWith(@res)
|
|
|
- .should.equal true
|
|
|
+ describe "with project history enabled", ->
|
|
|
+ beforeEach ->
|
|
|
+ @settings.apis.project_history.enabled = true
|
|
|
+ @HistoryController.proxyToHistoryApi @req, @res, @next
|
|
|
+
|
|
|
+ it "should get the user id", ->
|
|
|
+ @AuthenticationController.getLoggedInUserId
|
|
|
+ .calledWith(@req)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should call the project history api", ->
|
|
|
+ @request
|
|
|
+ .calledWith({
|
|
|
+ url: "#{@settings.apis.project_history.url}#{@req.url}"
|
|
|
+ method: @req.method
|
|
|
+ headers:
|
|
|
+ "X-User-Id": @user_id
|
|
|
+ })
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should pipe the response to the client", ->
|
|
|
+ @proxy.pipe
|
|
|
+ .calledWith(@res)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "with project history disabled", ->
|
|
|
+ beforeEach ->
|
|
|
+ @settings.apis.project_history.enabled = false
|
|
|
+ @HistoryController.proxyToHistoryApi @req, @res, @next
|
|
|
+
|
|
|
+ it "should call the track changes api", ->
|
|
|
+ @request
|
|
|
+ .calledWith({
|
|
|
+ url: "#{@settings.apis.trackchanges.url}#{@req.url}"
|
|
|
+ method: @req.method
|
|
|
+ headers:
|
|
|
+ "X-User-Id": @user_id
|
|
|
+ })
|
|
|
+ .should.equal true
|
|
|
|
|
|
describe "with an error", ->
|
|
|
beforeEach ->
|
|
|
+ @HistoryController.proxyToHistoryApi @req, @res, @next
|
|
|
@proxy.events["error"].call(@proxy, @error = new Error("oops"))
|
|
|
|
|
|
it "should pass the error up the call chain", ->
|