|
@@ -18,12 +18,15 @@ describe "WebApiManager", ->
|
|
|
pass: "password"
|
|
pass: "password"
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
|
@user_id = "mock-user-id"
|
|
@user_id = "mock-user-id"
|
|
|
|
|
+ @project_id = "mock-project-id"
|
|
|
@user_info =
|
|
@user_info =
|
|
|
email: "leo@sharelatex.com"
|
|
email: "leo@sharelatex.com"
|
|
|
id: @user_id
|
|
id: @user_id
|
|
|
first_name: "Leo"
|
|
first_name: "Leo"
|
|
|
last_nane: "Lion"
|
|
last_nane: "Lion"
|
|
|
extra_param: "blah"
|
|
extra_param: "blah"
|
|
|
|
|
+ @project =
|
|
|
|
|
+ features: "mock-features"
|
|
|
|
|
|
|
|
describe "getUserInfo", ->
|
|
describe "getUserInfo", ->
|
|
|
describe "successfully", ->
|
|
describe "successfully", ->
|
|
@@ -33,7 +36,6 @@ describe "WebApiManager", ->
|
|
|
@WebApiManager.getUserInfo @user_id, @callback
|
|
@WebApiManager.getUserInfo @user_id, @callback
|
|
|
|
|
|
|
|
it 'should get the user from the web api', ->
|
|
it 'should get the user from the web api', ->
|
|
|
- url =
|
|
|
|
|
@request.get
|
|
@request.get
|
|
|
.calledWith({
|
|
.calledWith({
|
|
|
url: "#{@settings.apis.web.url}/user/#{@user_id}/personal_info"
|
|
url: "#{@settings.apis.web.url}/user/#{@user_id}/personal_info"
|
|
@@ -65,6 +67,46 @@ describe "WebApiManager", ->
|
|
|
@request.get = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")
|
|
@request.get = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")
|
|
|
@WebApiManager.getUserInfo @user_id, @callback
|
|
@WebApiManager.getUserInfo @user_id, @callback
|
|
|
|
|
|
|
|
|
|
+ it "should return the callback with an error", ->
|
|
|
|
|
+ @callback
|
|
|
|
|
+ .calledWith(new Error("web returned failure status code: 500"))
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ describe "getProjectDetails", ->
|
|
|
|
|
+ describe "successfully", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @body = JSON.stringify @project
|
|
|
|
|
+ @request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body)
|
|
|
|
|
+ @WebApiManager.getProjectDetails @project_id, @callback
|
|
|
|
|
+
|
|
|
|
|
+ it 'should get the project from the web api', ->
|
|
|
|
|
+ @request.get
|
|
|
|
|
+ .calledWith({
|
|
|
|
|
+ url: "#{@settings.apis.web.url}/project/#{@project_id}/details"
|
|
|
|
|
+ auth:
|
|
|
|
|
+ user: @settings.apis.web.user
|
|
|
|
|
+ pass: @settings.apis.web.pass
|
|
|
|
|
+ sendImmediately: true
|
|
|
|
|
+ })
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ it "should call the callback with the project", ->
|
|
|
|
|
+ @callback.calledWith(null, @project).should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ describe "when the web API returns an error", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @request.get = sinon.stub().callsArgWith(1, @error = new Error("something went wrong"), null, null)
|
|
|
|
|
+ @WebApiManager.getProjectDetails @project_id, @callback
|
|
|
|
|
+
|
|
|
|
|
+ it "should return an error to the callback", ->
|
|
|
|
|
+ @callback.calledWith(@error).should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ describe "when the web returns a failure error code", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @request.get = sinon.stub().callsArgWith(1, null, { statusCode: 500 }, "")
|
|
|
|
|
+ @WebApiManager.getProjectDetails @project_id, @callback
|
|
|
|
|
+
|
|
|
it "should return the callback with an error", ->
|
|
it "should return the callback with an error", ->
|
|
|
@callback
|
|
@callback
|
|
|
.calledWith(new Error("web returned failure status code: 500"))
|
|
.calledWith(new Error("web returned failure status code: 500"))
|