|
|
@@ -19,31 +19,41 @@ describe('ProjectRootDocManager', function () {
|
|
|
ctx.docPaths[ctx.docId3] = '/nested/chapter1a.tex'
|
|
|
ctx.docPaths[ctx.docId4] = '/nested/chapter1b.tex'
|
|
|
ctx.sl_req_id = 'sl-req-id-123'
|
|
|
- ctx.callback = sinon.stub()
|
|
|
ctx.globbyFiles = ['a.tex', 'b.tex', 'main.tex']
|
|
|
ctx.globby = sinon.stub().resolves(ctx.globbyFiles)
|
|
|
|
|
|
ctx.fs = {
|
|
|
- readFile: sinon.stub().callsArgWith(2, new Error('file not found')),
|
|
|
- stat: sinon.stub().callsArgWith(1, null, { size: 100 }),
|
|
|
+ promises: {
|
|
|
+ readFile: sinon.stub().rejects(new Error('file not found')),
|
|
|
+ stat: sinon.stub().resolves({ size: 100 }),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ctx.ProjectEntityHandler = {
|
|
|
+ promises: {},
|
|
|
+ }
|
|
|
+ ctx.ProjectEntityUpdateHandler = {
|
|
|
+ promises: {},
|
|
|
+ }
|
|
|
+ ctx.ProjectGetter = {
|
|
|
+ promises: {},
|
|
|
}
|
|
|
|
|
|
vi.doMock(
|
|
|
'../../../../app/src/Features/Project/ProjectEntityHandler',
|
|
|
() => ({
|
|
|
- default: (ctx.ProjectEntityHandler = {}),
|
|
|
+ default: ctx.ProjectEntityHandler,
|
|
|
})
|
|
|
)
|
|
|
|
|
|
vi.doMock(
|
|
|
'../../../../app/src/Features/Project/ProjectEntityUpdateHandler',
|
|
|
() => ({
|
|
|
- default: (ctx.ProjectEntityUpdateHandler = {}),
|
|
|
+ default: ctx.ProjectEntityUpdateHandler,
|
|
|
})
|
|
|
)
|
|
|
|
|
|
vi.doMock('../../../../app/src/Features/Project/ProjectGetter', () => ({
|
|
|
- default: (ctx.ProjectGetter = {}),
|
|
|
+ default: ctx.ProjectGetter,
|
|
|
}))
|
|
|
|
|
|
vi.doMock('../../../../app/src/infrastructure/GracefulShutdown', () => ({
|
|
|
@@ -66,7 +76,9 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('setRootDocAutomatically', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves()
|
|
|
ctx.ProjectEntityUpdateHandler.isPathValidForRootDoc = sinon
|
|
|
.stub()
|
|
|
.returns(true)
|
|
|
@@ -100,22 +112,22 @@ describe('ProjectRootDocManager', function () {
|
|
|
lines: ['Hello world'],
|
|
|
},
|
|
|
}
|
|
|
- ctx.ProjectEntityHandler.getAllDocs = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocs = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docs)
|
|
|
+ .resolves(ctx.docs)
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocAutomatically(
|
|
|
ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should check the docs of the project', function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocs
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocs
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc to the doc containing a documentclass', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId2)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -133,16 +145,16 @@ describe('ProjectRootDocManager', function () {
|
|
|
lines: ['\\documentclass{article}', '\\input{chapter1}'],
|
|
|
},
|
|
|
}
|
|
|
- ctx.ProjectEntityHandler.getAllDocs = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocs = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docs)
|
|
|
+ .resolves(ctx.docs)
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocAutomatically(
|
|
|
ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc to the doc containing a documentclass', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId2)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -160,37 +172,37 @@ describe('ProjectRootDocManager', function () {
|
|
|
lines: ['%Example: \\documentclass{article}'],
|
|
|
},
|
|
|
}
|
|
|
- ctx.ProjectEntityHandler.getAllDocs = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocs = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docs)
|
|
|
+ .resolves(ctx.docs)
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocAutomatically(
|
|
|
ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should not set the root doc to the doc containing a documentclass', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(false)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc.called.should.equal(
|
|
|
+ false
|
|
|
+ )
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('findRootDocFileFromDirectory', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.fs.readFile
|
|
|
- .withArgs('/foo/a.tex')
|
|
|
- .callsArgWith(2, null, 'Hello World!')
|
|
|
- ctx.fs.readFile
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a.tex').resolves('Hello World!')
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/b.tex')
|
|
|
- .callsArgWith(2, null, "I'm a little teapot, get me out of here.")
|
|
|
- ctx.fs.readFile
|
|
|
+ .resolves("I'm a little teapot, get me out of here.")
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/main.tex')
|
|
|
- .callsArgWith(2, null, "Help, I'm trapped in a unit testing factory")
|
|
|
- ctx.fs.readFile
|
|
|
+ .resolves("Help, I'm trapped in a unit testing factory")
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/c.tex')
|
|
|
- .callsArgWith(2, null, 'Tomato, tomahto.')
|
|
|
- ctx.fs.readFile
|
|
|
+ .resolves('Tomato, tomahto.')
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/a/a.tex')
|
|
|
- .callsArgWith(2, null, 'Potato? Potahto. Potootee!')
|
|
|
+ .resolves('Potato? Potahto. Potootee!')
|
|
|
ctx.documentclassContent = '% test\n\\documentclass\n% test'
|
|
|
})
|
|
|
|
|
|
@@ -214,34 +226,34 @@ describe('ProjectRootDocManager', function () {
|
|
|
)
|
|
|
expect(path).to.equal('a.tex')
|
|
|
sinon.assert.callOrder(
|
|
|
- ctx.fs.readFile.withArgs('/foo/a.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/b.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/c.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/a/a.tex')
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/b.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/c.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a/a.tex')
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('processes smaller files first', async function (ctx) {
|
|
|
- ctx.fs.stat.withArgs('/foo/c.tex').callsArgWith(1, null, { size: 1 })
|
|
|
+ ctx.fs.promises.stat.withArgs('/foo/c.tex').resolves({ size: 1 })
|
|
|
const { path } =
|
|
|
await ctx.ProjectRootDocManager.promises.findRootDocFileFromDirectory(
|
|
|
'/foo'
|
|
|
)
|
|
|
expect(path).to.equal('c.tex')
|
|
|
sinon.assert.callOrder(
|
|
|
- ctx.fs.readFile.withArgs('/foo/c.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/a.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/b.tex'),
|
|
|
- ctx.fs.readFile.withArgs('/foo/a/a.tex')
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/c.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/b.tex'),
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a/a.tex')
|
|
|
)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when main.tex contains a documentclass', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.fs.readFile
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/main.tex')
|
|
|
- .callsArgWith(2, null, ctx.documentclassContent)
|
|
|
+ .resolves(ctx.documentclassContent)
|
|
|
})
|
|
|
|
|
|
it('returns main.tex', async function (ctx) {
|
|
|
@@ -254,20 +266,22 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('processes main.text first and stops processing when it finds the content', async function (ctx) {
|
|
|
- await ctx.ProjectRootDocManager.findRootDocFileFromDirectory('/foo')
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
- expect(ctx.fs.readFile).not.to.be.calledWith('/foo/a.tex')
|
|
|
+ await ctx.ProjectRootDocManager.promises.findRootDocFileFromDirectory(
|
|
|
+ '/foo'
|
|
|
+ )
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).not.to.be.calledWith('/foo/a.tex')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when main.tex does not contain a line starting with \\documentclass', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.fs.readFile.withArgs('/foo/a.tex').callsArgWith(2, null, 'foo')
|
|
|
- ctx.fs.readFile.withArgs('/foo/main.tex').callsArgWith(2, null, 'foo')
|
|
|
- ctx.fs.readFile.withArgs('/foo/z.tex').callsArgWith(2, null, 'foo')
|
|
|
- ctx.fs.readFile
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/a.tex').resolves('foo')
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/main.tex').resolves('foo')
|
|
|
+ ctx.fs.promises.readFile.withArgs('/foo/z.tex').resolves('foo')
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/nested/chapter1a.tex')
|
|
|
- .callsArgWith(2, null, 'foo')
|
|
|
+ .resolves('foo')
|
|
|
})
|
|
|
|
|
|
it('returns the first .tex file from the root folder', async function (ctx) {
|
|
|
@@ -308,9 +322,9 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('when a.tex contains a documentclass', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.fs.readFile
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/a.tex')
|
|
|
- .callsArgWith(2, null, ctx.documentclassContent)
|
|
|
+ .resolves(ctx.documentclassContent)
|
|
|
})
|
|
|
|
|
|
it('returns a.tex', async function (ctx) {
|
|
|
@@ -326,9 +340,9 @@ describe('ProjectRootDocManager', function () {
|
|
|
await ctx.ProjectRootDocManager.promises.findRootDocFileFromDirectory(
|
|
|
'/foo'
|
|
|
)
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/a.tex')
|
|
|
- expect(ctx.fs.readFile).not.to.be.calledWith('/foo/b.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/a.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).not.to.be.calledWith('/foo/b.tex')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -343,17 +357,17 @@ describe('ProjectRootDocManager', function () {
|
|
|
await ctx.ProjectRootDocManager.promises.findRootDocFileFromDirectory(
|
|
|
'/foo'
|
|
|
)
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/a.tex')
|
|
|
- expect(ctx.fs.readFile).to.be.calledWith('/foo/b.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/main.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/a.tex')
|
|
|
+ expect(ctx.fs.promises.readFile).to.be.calledWith('/foo/b.tex')
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when there is an error reading a file', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.fs.readFile
|
|
|
+ ctx.fs.promises.readFile
|
|
|
.withArgs('/foo/a.tex')
|
|
|
- .callsArgWith(2, new Error('something went wrong'))
|
|
|
+ .rejects(new Error('something went wrong'))
|
|
|
})
|
|
|
|
|
|
it('returns an error', async function (ctx) {
|
|
|
@@ -375,10 +389,12 @@ describe('ProjectRootDocManager', function () {
|
|
|
describe('setRootDocFromName', function () {
|
|
|
describe('when there is a suitable root doc', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docPaths)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ .resolves(ctx.docPaths)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves()
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocFromName(
|
|
|
ctx.project_id,
|
|
|
'/main.tex'
|
|
|
@@ -386,13 +402,13 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('should check the docs of the project', function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc to main.tex', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId2.toString())
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -400,10 +416,12 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('when there is a suitable root doc but the leading slash is missing', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves(ctx.docPaths)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docPaths)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ .resolves()
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocFromName(
|
|
|
ctx.project_id,
|
|
|
'main.tex'
|
|
|
@@ -411,13 +429,13 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('should check the docs of the project', function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc to main.tex', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId2.toString())
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -425,10 +443,12 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('when there is a suitable root doc with a basename match', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves(ctx.docPaths)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docPaths)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ .resolves()
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocFromName(
|
|
|
ctx.project_id,
|
|
|
'chapter1a.tex'
|
|
|
@@ -436,13 +456,13 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('should check the docs of the project', function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc using the basename', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId3.toString())
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -450,10 +470,12 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('when there is a suitable root doc but the filename is in quotes', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docPaths)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ .resolves(ctx.docPaths)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves()
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocFromName(
|
|
|
ctx.project_id,
|
|
|
"'main.tex'"
|
|
|
@@ -461,13 +483,13 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('should check the docs of the project', function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should set the root doc to main.tex', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc
|
|
|
.calledWith(ctx.project_id, ctx.docId2.toString())
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
@@ -475,10 +497,12 @@ describe('ProjectRootDocManager', function () {
|
|
|
|
|
|
describe('when there is no suitable root doc', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getAllDocPathsFromProjectById = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves(ctx.docPaths)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.docPaths)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
|
|
|
+ .resolves()
|
|
|
await ctx.ProjectRootDocManager.promises.setRootDocFromName(
|
|
|
ctx.project_id,
|
|
|
'other.tex'
|
|
|
@@ -486,7 +510,9 @@ describe('ProjectRootDocManager', function () {
|
|
|
})
|
|
|
|
|
|
it('should not set the root doc', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(false)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc.called.should.equal(
|
|
|
+ false
|
|
|
+ )
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -494,82 +520,65 @@ describe('ProjectRootDocManager', function () {
|
|
|
describe('ensureRootDocumentIsSet', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
ctx.project = {}
|
|
|
- ctx.ProjectGetter.getProject = sinon
|
|
|
- .stub()
|
|
|
- .callsArgWith(2, null, ctx.project)
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically = sinon
|
|
|
+ ctx.ProjectGetter.promises.getProject = sinon.stub().resolves(ctx.project)
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null)
|
|
|
+ .resolves()
|
|
|
})
|
|
|
|
|
|
describe('when the root doc is set', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
ctx.project.rootDoc_id = ctx.docId2
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsSet(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
+
|
|
|
+ await ctx.ProjectRootDocManager.promises.ensureRootDocumentIsSet(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should find the project fetching only the rootDoc_id field', function (ctx) {
|
|
|
- ctx.ProjectGetter.getProject
|
|
|
+ ctx.ProjectGetter.promises.getProject
|
|
|
.calledWith(ctx.project_id, { rootDoc_id: 1 })
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should not try to update the project rootDoc_id', function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically.called.should.equal(
|
|
|
false
|
|
|
)
|
|
|
})
|
|
|
-
|
|
|
- it('should call the callback', function (ctx) {
|
|
|
- ctx.callback.called.should.equal(true)
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('when the root doc is not set', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsSet(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
+ await ctx.ProjectRootDocManager.promises.ensureRootDocumentIsSet(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should find the project with only the rootDoc_id field', function (ctx) {
|
|
|
- ctx.ProjectGetter.getProject
|
|
|
+ ctx.ProjectGetter.promises.getProject
|
|
|
.calledWith(ctx.project_id, { rootDoc_id: 1 })
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should update the project rootDoc_id', function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
-
|
|
|
- it('should call the callback', function (ctx) {
|
|
|
- ctx.callback.called.should.equal(true)
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('when the project does not exist', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
- ctx.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsSet(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
- )
|
|
|
+ ctx.ProjectGetter.promises.getProject = sinon.stub().resolves(null)
|
|
|
})
|
|
|
|
|
|
- it('should call the callback with an error', function (ctx) {
|
|
|
- ctx.callback
|
|
|
- .calledWith(
|
|
|
- sinon.match
|
|
|
- .instanceOf(Error)
|
|
|
- .and(sinon.match.has('message', 'project not found'))
|
|
|
+ it('should reject', async function (ctx) {
|
|
|
+ await expect(
|
|
|
+ ctx.ProjectRootDocManager.promises.ensureRootDocumentIsSet(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
- .should.equal(true)
|
|
|
+ ).to.be.rejectedWith('project not found')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -577,129 +586,110 @@ describe('ProjectRootDocManager', function () {
|
|
|
describe('ensureRootDocumentIsValid', function () {
|
|
|
beforeEach(function (ctx) {
|
|
|
ctx.project = {}
|
|
|
- ctx.ProjectGetter.getProject = sinon
|
|
|
+ ctx.ProjectGetter.promises.getProject = sinon.stub().resolves(ctx.project)
|
|
|
+ ctx.ProjectGetter.promises.getProjectWithoutDocLines = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves(ctx.project)
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.setRootDoc = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, ctx.project)
|
|
|
- ctx.ProjectGetter.getProjectWithoutDocLines = sinon
|
|
|
+ .resolves()
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.unsetRootDoc = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, ctx.project)
|
|
|
- ctx.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().yields()
|
|
|
- ctx.ProjectEntityUpdateHandler.unsetRootDoc = sinon.stub().yields()
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically = sinon
|
|
|
+ .resolves()
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null)
|
|
|
+ .resolves(null)
|
|
|
})
|
|
|
|
|
|
describe('when the root doc is set', function () {
|
|
|
describe('when the root doc is valid', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
ctx.project.rootDoc_id = ctx.docId2
|
|
|
- ctx.ProjectEntityHandler.getDocPathFromProjectByDocId = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getDocPathFromProjectByDocId = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, ctx.docPaths[ctx.docId2])
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
+ .resolves(ctx.docPaths[ctx.docId2])
|
|
|
+ await ctx.ProjectRootDocManager.promises.ensureRootDocumentIsValid(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should find the project without doc lines', function (ctx) {
|
|
|
- ctx.ProjectGetter.getProjectWithoutDocLines
|
|
|
+ ctx.ProjectGetter.promises.getProjectWithoutDocLines
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should not try to update the project rootDoc_id', function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically.called.should.equal(
|
|
|
false
|
|
|
)
|
|
|
})
|
|
|
-
|
|
|
- it('should call the callback', function (ctx) {
|
|
|
- ctx.callback.called.should.equal(true)
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('when the root doc is not valid', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
ctx.project.rootDoc_id = new ObjectId()
|
|
|
- ctx.ProjectEntityHandler.getDocPathFromProjectByDocId = sinon
|
|
|
+ ctx.ProjectEntityHandler.promises.getDocPathFromProjectByDocId = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(2, null, null)
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
+ .resolves(null)
|
|
|
+ await ctx.ProjectRootDocManager.promises.ensureRootDocumentIsValid(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should find the project without doc lines', function (ctx) {
|
|
|
- ctx.ProjectGetter.getProjectWithoutDocLines
|
|
|
+ ctx.ProjectGetter.promises.getProjectWithoutDocLines
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should unset the root doc', function (ctx) {
|
|
|
- ctx.ProjectEntityUpdateHandler.unsetRootDoc
|
|
|
+ ctx.ProjectEntityUpdateHandler.promises.unsetRootDoc
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should try to find a new rootDoc', function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically.called.should.equal(
|
|
|
true
|
|
|
)
|
|
|
})
|
|
|
-
|
|
|
- it('should call the callback', function (ctx) {
|
|
|
- ctx.callback.called.should.equal(true)
|
|
|
- })
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('when the root doc is not set', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
+ await ctx.ProjectRootDocManager.promises.ensureRootDocumentIsValid(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('should find the project without doc lines', function (ctx) {
|
|
|
- ctx.ProjectGetter.getProjectWithoutDocLines
|
|
|
+ it('should find the project without doc lines', async function (ctx) {
|
|
|
+ ctx.ProjectGetter.promises.getProjectWithoutDocLines
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
it('should update the project rootDoc_id', function (ctx) {
|
|
|
- ctx.ProjectRootDocManager.setRootDocAutomatically
|
|
|
+ ctx.ProjectRootDocManager.promises.setRootDocAutomatically
|
|
|
.calledWith(ctx.project_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
-
|
|
|
- it('should call the callback', function (ctx) {
|
|
|
- ctx.callback.called.should.equal(true)
|
|
|
- })
|
|
|
})
|
|
|
|
|
|
describe('when the project does not exist', function () {
|
|
|
- beforeEach(function (ctx) {
|
|
|
- ctx.ProjectGetter.getProjectWithoutDocLines = sinon
|
|
|
+ beforeEach(async function (ctx) {
|
|
|
+ ctx.ProjectGetter.promises.getProjectWithoutDocLines = sinon
|
|
|
.stub()
|
|
|
- .callsArgWith(1, null, null)
|
|
|
- ctx.ProjectRootDocManager.ensureRootDocumentIsValid(
|
|
|
- ctx.project_id,
|
|
|
- ctx.callback
|
|
|
- )
|
|
|
+ .resolves(null)
|
|
|
})
|
|
|
|
|
|
- it('should call the callback with an error', function (ctx) {
|
|
|
- ctx.callback
|
|
|
- .calledWith(
|
|
|
- sinon.match
|
|
|
- .instanceOf(Error)
|
|
|
- .and(sinon.match.has('message', 'project not found'))
|
|
|
+ it('should reject', async function (ctx) {
|
|
|
+ await expect(
|
|
|
+ ctx.ProjectRootDocManager.promises.ensureRootDocumentIsValid(
|
|
|
+ ctx.project_id
|
|
|
)
|
|
|
- .should.equal(true)
|
|
|
+ ).to.be.rejectedWith('project not found')
|
|
|
})
|
|
|
})
|
|
|
})
|