add tpds project structure acceptance tests

This commit is contained in:
Hayden Faulds 2017-11-29 11:07:49 +00:00
parent 9736513f59
commit 77eac423c7
3 changed files with 121 additions and 15 deletions

View file

@ -1,7 +1,10 @@
async = require("async")
async = require "async"
expect = require("chai").expect
mkdirp = require "mkdirp"
ObjectId = require("mongojs").ObjectId
Path = require "path"
fs = require "fs"
Settings = require "settings-sharelatex"
_ = require "underscore"
ProjectGetter = require "../../../app/js/Features/Project/ProjectGetter.js"
@ -20,7 +23,7 @@ describe "ProjectStructureChanges", ->
describe "creating a project from the example template", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
@owner.createProject "project", {template: "example"}, (error, project_id) =>
@owner.createProject "example-project", {template: "example"}, (error, project_id) =>
throw error if error?
@example_project_id = project_id
done()
@ -133,12 +136,14 @@ describe "ProjectStructureChanges", ->
describe "uploading a file", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
ProjectGetter.getProject @example_project_id, (error, projects) =>
throw error if error?
@root_folder_id = projects[0].rootFolder[0]._id.toString()
done()
beforeEach () ->
MockDocUpdaterApi.clearProjectStructureUpdates()
it "should version a newly uploaded file", (done) ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/1pixel.png'))
@ -195,6 +200,108 @@ describe "ProjectStructureChanges", ->
done()
describe "tpds", ->
it "should version add a doc"
it "should version add a new file"
it "should version replacing a file"
before (done) ->
@tpds_project_name = "tpds-project-#{new ObjectId().toString()}"
@owner.createProject @tpds_project_name, (error, project_id) =>
throw error if error?
@tpds_project_id = project_id
mkdirp Settings.path.dumpFolder, done
beforeEach () ->
MockDocUpdaterApi.clearProjectStructureUpdates()
it "should version adding a doc", (done) ->
tex_file = fs.createReadStream(Path.resolve(__dirname + '/../files/test.tex'))
req = @owner.request.post {
uri: "/user/#{@owner._id}/update/#{@tpds_project_name}/test.tex",
auth:
user: _.keys(Settings.httpAuthUsers)[0]
pass: _.values(Settings.httpAuthUsers)[0]
sendImmediately: true
}
tex_file.on "error", (err) ->
throw err
req.on "error", (err) ->
throw err
req.on "response", (res) =>
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(@tpds_project_id).docUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/test.tex")
expect(update.docLines).to.equal("Test")
done()
tex_file.pipe(req)
it "should version adding a new file", (done) ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/1pixel.png'))
req = @owner.request.post {
uri: "/user/#{@owner._id}/update/#{@tpds_project_name}/1pixel.png",
auth:
user: _.keys(Settings.httpAuthUsers)[0]
pass: _.values(Settings.httpAuthUsers)[0]
sendImmediately: true
}
image_file.on "error", (err) ->
throw err
req.on "error", (err) ->
throw err
req.on "response", (res) =>
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(@tpds_project_id).fileUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/1pixel.png")
expect(update.url).to.be.a('string');
done()
image_file.pipe(req)
it "should version replacing a file", (done) ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/2pixel.png'))
req = @owner.request.post {
uri: "/user/#{@owner._id}/update/#{@tpds_project_name}/1pixel.png",
auth:
user: _.keys(Settings.httpAuthUsers)[0]
pass: _.values(Settings.httpAuthUsers)[0]
sendImmediately: true
}
image_file.on "error", (err) ->
throw err
req.on "error", (err) ->
throw err
req.on "response", (res) =>
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(@tpds_project_id).fileUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/1pixel.png")
expect(update.url).to.be.a('string');
done()
image_file.pipe(req)

View file

@ -4,26 +4,24 @@ bodyParser = require "body-parser"
jsonParser = bodyParser.json()
module.exports = MockDocUpdaterApi =
project_structures_updates: {}
updates: {}
clearProjectStructureUpdates: () ->
@project_structures_updates = {}
@updates = {}
getProjectStructureUpdates: (project_id) ->
@project_structures_updates[project_id]
@updates[project_id] || { docUpdates: [], fileUpdates: [] }
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates) ->
@project_structures_updates[project_id] ||= {
docUpdates: []
fileUpdates: []
}
@updates[project_id] ||= { docUpdates: [], fileUpdates: [] }
for update in docUpdates
update.userId = userId
@project_structures_updates[project_id].docUpdates.push(update)
@updates[project_id].docUpdates.push(update)
for update in fileUpdates
update.userId = userId
@project_structures_updates[project_id].fileUpdates.push(update)
@updates[project_id].fileUpdates.push(update)
run: () ->
app.post "/project/:project_id/flush", (req, res, next) =>

View file

@ -0,0 +1 @@
Test