mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
return pathname from PersistenceManager
This commit is contained in:
parent
02d3d1bd17
commit
05b93a629a
2 changed files with 10 additions and 8 deletions
|
@ -13,7 +13,7 @@ request = (require("requestretry")).defaults({
|
||||||
MAX_HTTP_REQUEST_LENGTH = 5000 # 5 seconds
|
MAX_HTTP_REQUEST_LENGTH = 5000 # 5 seconds
|
||||||
|
|
||||||
module.exports = PersistenceManager =
|
module.exports = PersistenceManager =
|
||||||
getDoc: (project_id, doc_id, _callback = (error, lines, version, ranges) ->) ->
|
getDoc: (project_id, doc_id, _callback = (error, lines, version, ranges, pathname) ->) ->
|
||||||
timer = new Metrics.Timer("persistenceManager.getDoc")
|
timer = new Metrics.Timer("persistenceManager.getDoc")
|
||||||
callback = (args...) ->
|
callback = (args...) ->
|
||||||
timer.done()
|
timer.done()
|
||||||
|
@ -42,7 +42,7 @@ module.exports = PersistenceManager =
|
||||||
return callback(new Error("web API response had no doc lines"))
|
return callback(new Error("web API response had no doc lines"))
|
||||||
if !body.version? or not body.version instanceof Number
|
if !body.version? or not body.version instanceof Number
|
||||||
return callback(new Error("web API response had no valid doc version"))
|
return callback(new Error("web API response had no valid doc version"))
|
||||||
return callback null, body.lines, body.version, body.ranges
|
return callback null, body.lines, body.version, body.ranges, body.pathname
|
||||||
else if res.statusCode == 404
|
else if res.statusCode == 404
|
||||||
return callback(new Errors.NotFoundError("doc not not found: #{url}"))
|
return callback(new Errors.NotFoundError("doc not not found: #{url}"))
|
||||||
else
|
else
|
||||||
|
|
|
@ -22,6 +22,7 @@ describe "PersistenceManager", ->
|
||||||
@version = 42
|
@version = 42
|
||||||
@callback = sinon.stub()
|
@callback = sinon.stub()
|
||||||
@ranges = { comments: "mock", entries: "mock" }
|
@ranges = { comments: "mock", entries: "mock" }
|
||||||
|
@pathname = '/a/b/c.tex'
|
||||||
@Settings.apis =
|
@Settings.apis =
|
||||||
web:
|
web:
|
||||||
url: @url = "www.example.com"
|
url: @url = "www.example.com"
|
||||||
|
@ -29,13 +30,14 @@ describe "PersistenceManager", ->
|
||||||
pass: @pass = "password"
|
pass: @pass = "password"
|
||||||
|
|
||||||
describe "getDoc", ->
|
describe "getDoc", ->
|
||||||
|
|
||||||
describe "with a successful response from the web api", ->
|
describe "with a successful response from the web api", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify({
|
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify({
|
||||||
lines: @lines,
|
lines: @lines,
|
||||||
version: @version,
|
version: @version,
|
||||||
ranges: @ranges
|
ranges: @ranges
|
||||||
|
pathname: @pathname,
|
||||||
}))
|
}))
|
||||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||||
|
|
||||||
|
@ -56,7 +58,7 @@ describe "PersistenceManager", ->
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback with the doc lines, version and ranges", ->
|
it "should call the callback with the doc lines, version and ranges", ->
|
||||||
@callback.calledWith(null, @lines, @version, @ranges).should.equal true
|
@callback.calledWith(null, @lines, @version, @ranges, @pathname).should.equal true
|
||||||
|
|
||||||
it "should time the execution", ->
|
it "should time the execution", ->
|
||||||
@Metrics.Timer::done.called.should.equal true
|
@Metrics.Timer::done.called.should.equal true
|
||||||
|
@ -76,7 +78,7 @@ describe "PersistenceManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@request.callsArgWith(1, null, {statusCode: 404}, "")
|
@request.callsArgWith(1, null, {statusCode: 404}, "")
|
||||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||||
|
|
||||||
it "should return a NotFoundError", ->
|
it "should return a NotFoundError", ->
|
||||||
@callback.calledWith(new Errors.NotFoundError("not found")).should.equal true
|
@callback.calledWith(new Errors.NotFoundError("not found")).should.equal true
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ describe "PersistenceManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@request.callsArgWith(1, null, {statusCode: 500}, "")
|
@request.callsArgWith(1, null, {statusCode: 500}, "")
|
||||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||||
|
|
||||||
it "should return an error", ->
|
it "should return an error", ->
|
||||||
@callback.calledWith(new Error("web api error")).should.equal true
|
@callback.calledWith(new Error("web api error")).should.equal true
|
||||||
|
|
||||||
|
@ -155,7 +157,7 @@ describe "PersistenceManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@request.callsArgWith(1, null, {statusCode: 404}, "")
|
@request.callsArgWith(1, null, {statusCode: 404}, "")
|
||||||
@PersistenceManager.setDoc(@project_id, @doc_id, @lines, @version, @ranges, @callback)
|
@PersistenceManager.setDoc(@project_id, @doc_id, @lines, @version, @ranges, @callback)
|
||||||
|
|
||||||
it "should return a NotFoundError", ->
|
it "should return a NotFoundError", ->
|
||||||
@callback.calledWith(new Errors.NotFoundError("not found")).should.equal true
|
@callback.calledWith(new Errors.NotFoundError("not found")).should.equal true
|
||||||
|
|
||||||
|
@ -166,7 +168,7 @@ describe "PersistenceManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@request.callsArgWith(1, null, {statusCode: 500}, "")
|
@request.callsArgWith(1, null, {statusCode: 500}, "")
|
||||||
@PersistenceManager.setDoc(@project_id, @doc_id, @lines, @version, @ranges, @callback)
|
@PersistenceManager.setDoc(@project_id, @doc_id, @lines, @version, @ranges, @callback)
|
||||||
|
|
||||||
it "should return an error", ->
|
it "should return an error", ->
|
||||||
@callback.calledWith(new Error("web api error")).should.equal true
|
@callback.calledWith(new Error("web api error")).should.equal true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue