2018-03-08 12:24:54 -05:00
|
|
|
async = require "async"
|
|
|
|
expect = require("chai").expect
|
2018-03-09 11:36:10 -05:00
|
|
|
_ = require 'underscore'
|
2018-03-08 12:24:54 -05:00
|
|
|
|
|
|
|
ProjectGetter = require "../../../app/js/Features/Project/ProjectGetter.js"
|
|
|
|
|
|
|
|
User = require "./helpers/User"
|
|
|
|
MockProjectHistoryApi = require "./helpers/MockProjectHistoryApi"
|
|
|
|
MockDocstoreApi = require "./helpers/MockDocstoreApi"
|
2018-03-09 11:36:10 -05:00
|
|
|
MockFileStoreApi = require "./helpers/MockFileStoreApi"
|
2018-03-08 12:24:54 -05:00
|
|
|
|
|
|
|
describe "RestoringFiles", ->
|
|
|
|
before (done) ->
|
|
|
|
@owner = new User()
|
|
|
|
@owner.login (error) =>
|
|
|
|
throw error if error?
|
|
|
|
@owner.createProject "example-project", {template: "example"}, (error, @project_id) =>
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "restoring a text file", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
MockProjectHistoryApi.addOldFile(@project_id, 42, "foo.tex", "hello world, this is foo.tex!")
|
|
|
|
@owner.request {
|
|
|
|
method: "POST",
|
|
|
|
url: "/project/#{@project_id}/restore_file",
|
|
|
|
json:
|
|
|
|
pathname: "foo.tex"
|
|
|
|
version: 42
|
|
|
|
}, (error, response, body) ->
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
2018-03-09 11:36:10 -05:00
|
|
|
it "should have created a doc", (done) ->
|
2018-03-08 12:24:54 -05:00
|
|
|
@owner.getProject @project_id, (error, project) =>
|
|
|
|
throw error if error?
|
|
|
|
doc = _.find project.rootFolder[0].docs, (doc) ->
|
|
|
|
doc.name == 'foo.tex'
|
|
|
|
doc = MockDocstoreApi.docs[@project_id][doc._id]
|
|
|
|
expect(doc.lines).to.deep.equal [
|
|
|
|
"hello world, this is foo.tex!"
|
|
|
|
]
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "restoring a binary file", ->
|
2018-03-09 11:36:10 -05:00
|
|
|
beforeEach (done) ->
|
|
|
|
MockProjectHistoryApi.addOldFile(@project_id, 42, "image.png", "Mock image.png content")
|
|
|
|
@owner.request {
|
|
|
|
method: "POST",
|
|
|
|
url: "/project/#{@project_id}/restore_file",
|
|
|
|
json:
|
|
|
|
pathname: "image.png"
|
|
|
|
version: 42
|
|
|
|
}, (error, response, body) ->
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should have created a file", (done) ->
|
|
|
|
@owner.getProject @project_id, (error, project) =>
|
|
|
|
throw error if error?
|
|
|
|
file = _.find project.rootFolder[0].fileRefs, (file) ->
|
|
|
|
file.name == 'image.png'
|
|
|
|
file = MockFileStoreApi.files[@project_id][file._id]
|
|
|
|
expect(file.content).to.equal "Mock image.png content"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "restoring to a directory that exists", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
MockProjectHistoryApi.addOldFile(@project_id, 42, "foldername/foo2.tex", "hello world, this is foo-2.tex!")
|
|
|
|
@owner.request.post {
|
|
|
|
uri: "project/#{@project_id}/folder",
|
|
|
|
json:
|
|
|
|
name: 'foldername'
|
|
|
|
}, (error, response, body) =>
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
@owner.request {
|
|
|
|
method: "POST",
|
|
|
|
url: "/project/#{@project_id}/restore_file",
|
|
|
|
json:
|
|
|
|
pathname: "foldername/foo2.tex"
|
|
|
|
version: 42
|
|
|
|
}, (error, response, body) ->
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should have created the doc in the named folder", (done) ->
|
|
|
|
@owner.getProject @project_id, (error, project) =>
|
|
|
|
throw error if error?
|
|
|
|
folder = _.find project.rootFolder[0].folders, (folder) ->
|
|
|
|
folder.name == 'foldername'
|
|
|
|
doc = _.find folder.docs, (doc) ->
|
|
|
|
doc.name == 'foo2.tex'
|
|
|
|
doc = MockDocstoreApi.docs[@project_id][doc._id]
|
|
|
|
expect(doc.lines).to.deep.equal [
|
|
|
|
"hello world, this is foo-2.tex!"
|
|
|
|
]
|
|
|
|
done()
|
2018-03-08 12:24:54 -05:00
|
|
|
|
|
|
|
describe "restoring to a directory that no longer exists", ->
|
2018-03-09 11:36:10 -05:00
|
|
|
beforeEach (done) ->
|
|
|
|
MockProjectHistoryApi.addOldFile(@project_id, 42, "nothere/foo3.tex", "hello world, this is foo-3.tex!")
|
|
|
|
@owner.request {
|
|
|
|
method: "POST",
|
|
|
|
url: "/project/#{@project_id}/restore_file",
|
|
|
|
json:
|
|
|
|
pathname: "nothere/foo3.tex"
|
|
|
|
version: 42
|
|
|
|
}, (error, response, body) ->
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should have created the doc in the root folder", (done) ->
|
|
|
|
@owner.getProject @project_id, (error, project) =>
|
|
|
|
throw error if error?
|
|
|
|
doc = _.find project.rootFolder[0].docs, (doc) ->
|
|
|
|
doc.name == 'foo3.tex'
|
|
|
|
doc = MockDocstoreApi.docs[@project_id][doc._id]
|
|
|
|
expect(doc.lines).to.deep.equal [
|
|
|
|
"hello world, this is foo-3.tex!"
|
|
|
|
]
|
|
|
|
done()
|
2018-03-08 12:24:54 -05:00
|
|
|
|
|
|
|
describe "restoring to a filename that already exists", ->
|
2018-03-09 11:36:10 -05:00
|
|
|
it "should have created the file with a timestamp appended", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
MockProjectHistoryApi.addOldFile(@project_id, 42, "main.tex", "hello world, this is main.tex!")
|
|
|
|
@owner.request {
|
|
|
|
method: "POST",
|
|
|
|
url: "/project/#{@project_id}/restore_file",
|
|
|
|
json:
|
|
|
|
pathname: "main.tex"
|
|
|
|
version: 42
|
|
|
|
}, (error, response, body) ->
|
|
|
|
throw error if error?
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should have created the doc in the root folder", (done) ->
|
|
|
|
@owner.getProject @project_id, (error, project) =>
|
|
|
|
throw error if error?
|
|
|
|
doc = _.find project.rootFolder[0].docs, (doc) ->
|
|
|
|
doc.name.match(/main \(Restored on/)
|
|
|
|
expect(doc).to.exist
|
|
|
|
doc = MockDocstoreApi.docs[@project_id][doc._id]
|
|
|
|
expect(doc.lines).to.deep.equal [
|
|
|
|
"hello world, this is main.tex!"
|
|
|
|
]
|
|
|
|
done()
|
|
|
|
|