add acceptance tests

This commit is contained in:
Hayden Faulds 2017-11-27 17:09:51 +00:00
parent 61a1336ec6
commit 3466db0aae
11 changed files with 276 additions and 5 deletions

View file

@ -111,7 +111,7 @@ module.exports = settings =
trackchanges:
url : "http://localhost:3015"
project_history:
enabled: false
enabled: process.env.PROJECT_HISTORY_ENABLED == 'true' or false
url : "http://localhost:3054"
docstore:
url : "http://#{process.env['DOCSTORE_HOST'] or 'localhost'}:3016"

View file

@ -0,0 +1,200 @@
async = require("async")
expect = require("chai").expect
Path = require "path"
fs = require "fs"
_ = require "underscore"
ProjectGetter = require "../../../app/js/Features/Project/ProjectGetter.js"
MockDocUpdaterApi = require './helpers/MockDocUpdaterApi'
MockFileStoreApi = require './helpers/MockFileStoreApi'
MockProjectHistoryApi = require './helpers/MockProjectHistoryApi'
request = require "./helpers/request"
User = require "./helpers/User"
describe "ProjectStructureChanges", ->
before (done) ->
@owner = new User()
@owner.login done
describe "creating a project from the example template", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
@owner.createProject "project", {template: "example"}, (error, project_id) =>
throw error if error?
@example_project_id = project_id
done()
it "should version creating a doc", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(2)
_.each updates, (update) =>
expect(update.userId).to.equal(@owner._id)
expect(update.docLines).to.be.a('string')
expect(_.where(updates, pathname: "/main.tex").length).to.equal 1
expect(_.where(updates, pathname: "/references.bib").length).to.equal 1
it "should version creating a file", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/universe.jpg")
expect(update.url).to.be.a('string');
describe "duplicating a project", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
@owner.request.post {
uri: "/Project/#{@example_project_id}/clone",
json:
projectName: 'new.tex'
}, (error, res, body) =>
throw error if error?
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to add doc #{res.statusCode}")
@dup_project_id = body.project_id
done()
it "should version the dosc created", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@dup_project_id).docUpdates
expect(updates.length).to.equal(2)
_.each updates, (update) =>
expect(update.userId).to.equal(@owner._id)
expect(update.docLines).to.be.a('string')
expect(_.where(updates, pathname: "/main.tex").length).to.equal(1)
expect(_.where(updates, pathname: "/references.bib").length).to.equal(1)
it "should version the files created", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@dup_project_id).fileUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/universe.jpg")
expect(update.url).to.be.a('string');
describe "adding a doc", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
ProjectGetter.getProject @example_project_id, (error, projects) =>
throw error if error?
@owner.request.post {
uri: "project/#{@example_project_id}/doc",
json:
name: 'new.tex'
parent_folder_id: projects[0].rootFolder[0]._id
}, (error, res, body) =>
throw error if error?
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to add doc #{res.statusCode}")
done()
it "should version the doc added", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/new.tex")
expect(update.docLines).to.be.a('string');
describe "uploading a project", ->
before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates()
zip_file = fs.createReadStream(Path.resolve(__dirname + '/../files/test_project.zip'))
req = @owner.request.post {
uri: "project/new/upload",
formData:
qqfile: zip_file
}, (error, res, body) =>
throw error if error?
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload project #{res.statusCode}")
@uploaded_project_id = JSON.parse(body).project_id
done()
it "should version the dosc created", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@uploaded_project_id).docUpdates
expect(updates.length).to.equal(1)
update = updates[0]
expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/main.tex")
expect(update.docLines).to.equal("Test")
it "should version the files created", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(@uploaded_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');
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()
it "should version a newly uploaded file", (done) ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/1pixel.png'))
req = @owner.request.post {
uri: "project/#{@example_project_id}/upload",
qs:
folder_id: @root_folder_id
formData:
qqfile:
value: image_file
options:
filename: '1pixel.png',
contentType: 'image/png'
}, (error, res, body) =>
throw error if error?
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_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');
@original_file_url = update.url
done()
it "should version a replacement file", (done) ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/2pixel.png'))
req = @owner.request.post {
uri: "project/#{@example_project_id}/upload",
qs:
folder_id: @root_folder_id
formData:
qqfile:
value: image_file
options:
filename: '1pixel.png',
contentType: 'image/png'
}, (error, res, body) =>
throw error if error?
if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_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()
describe "tpds", ->
it "should version add a doc"
it "should version add a new file"
it "should version replacing a file"

View file

@ -1,11 +1,40 @@
express = require("express")
app = express()
bodyParser = require "body-parser"
jsonParser = bodyParser.json()
module.exports = MockDocUpdaterApi =
project_structures_updates: {}
clearProjectStructureUpdates: () ->
@project_structures_updates = {}
getProjectStructureUpdates: (project_id) ->
@project_structures_updates[project_id]
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates) ->
@project_structures_updates[project_id] ||= {
docUpdates: []
fileUpdates: []
}
for update in docUpdates
update.userId = userId
@project_structures_updates[project_id].docUpdates.push(update)
for update in fileUpdates
update.userId = userId
@project_structures_updates[project_id].fileUpdates.push(update)
run: () ->
app.post "/project/:project_id/flush", (req, res, next) =>
res.sendStatus 200
app.post "/project/:project_id", jsonParser, (req, res, next) =>
project_id = req.params.project_id
{userId, docUpdates, fileUpdates} = req.body
@addProjectStructureUpdates(project_id, userId, docUpdates, fileUpdates)
res.sendStatus 200
app.listen 3003, (error) ->
throw error if error?
.on "error", (error) ->

View file

@ -13,6 +13,7 @@ module.exports = MockDocStoreApi =
@docs[project_id][doc_id] = {lines, version, ranges}
@docs[project_id][doc_id].rev ?= 0
@docs[project_id][doc_id].rev += 1
@docs[project_id][doc_id]._id = doc_id
res.json {
modified: true
rev: @docs[project_id][doc_id].rev

View file

@ -0,0 +1,20 @@
express = require("express")
app = express()
module.exports = MockFileStoreApi =
files: {}
run: () ->
app.post "/project/:project_id/file/:file_id", (req, res, next) =>
req.on 'data', ->
req.on 'end', ->
res.send 200
app.listen 3009, (error) ->
throw error if error?
.on "error", (error) ->
console.error "error starting MockFileStoreApi:", error.message
process.exit(1)
MockFileStoreApi.run()

View file

@ -0,0 +1,18 @@
express = require("express")
app = express()
module.exports = MockProjectHistoryApi =
docs: {}
run: () ->
app.post "/project", (req, res, next) =>
res.json project: id: 1
app.listen 3054, (error) ->
throw error if error?
.on "error", (error) ->
console.error "error starting MockProjectHistoryApi:", error.message
process.exit(1)
MockProjectHistoryApi.run()

View file

@ -99,11 +99,14 @@ class User
getProject: (project_id, callback = (error, project)->) ->
db.projects.findOne {_id: ObjectId(project_id.toString())}, callback
createProject: (name, callback = (error, project_id) ->) ->
createProject: (name, options, callback = (error, oroject_id) ->) ->
if typeof options == "function"
callback = options
options = {}
@request.post {
url: "/project/new",
json:
projectName: name
json: Object.assign({projectName: name}, options)
}, (error, response, body) ->
return callback(error) if error?
if !body?.project_id?

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

View file

@ -3,7 +3,7 @@
# If you're running on OS X, you probably need to rebuild
# some dependencies in the docker container, before it will start.
#
# npm rebuild --update-binary
#npm rebuild --update-binary
echo ">> Starting server..."