|
@@ -1,14 +1,3 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
- no-undef,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * decaffeinate suggestions:
|
|
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
|
- */
|
|
|
|
|
import sinon from 'sinon'
|
|
import sinon from 'sinon'
|
|
|
import { expect } from 'chai'
|
|
import { expect } from 'chai'
|
|
|
import mongodb from 'mongodb-legacy'
|
|
import mongodb from 'mongodb-legacy'
|
|
@@ -53,11 +42,11 @@ describe('LabelsManager', function () {
|
|
|
this.historyId = 123
|
|
this.historyId = 123
|
|
|
this.user_id = new ObjectId().toString()
|
|
this.user_id = new ObjectId().toString()
|
|
|
this.label_id = new ObjectId().toString()
|
|
this.label_id = new ObjectId().toString()
|
|
|
- return (this.callback = sinon.stub())
|
|
|
|
|
|
|
+ this.callback = sinon.stub()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
afterEach(function () {
|
|
|
- return tk.reset()
|
|
|
|
|
|
|
+ tk.reset()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('getLabels', function () {
|
|
describe('getLabels', function () {
|
|
@@ -77,17 +66,17 @@ describe('LabelsManager', function () {
|
|
|
|
|
|
|
|
describe('with valid project id', function () {
|
|
describe('with valid project id', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- return this.LabelsManager.getLabels(this.project_id, this.callback)
|
|
|
|
|
|
|
+ this.LabelsManager.getLabels(this.project_id, this.callback)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('gets the labels state from mongo', function () {
|
|
it('gets the labels state from mongo', function () {
|
|
|
- return expect(
|
|
|
|
|
- this.db.projectHistoryLabels.find
|
|
|
|
|
- ).to.have.been.calledWith({ project_id: new ObjectId(this.project_id) })
|
|
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.find).to.have.been.calledWith({
|
|
|
|
|
+ project_id: new ObjectId(this.project_id),
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('returns formatted labels', function () {
|
|
|
|
|
- return expect(this.callback).to.have.been.calledWith(null, [
|
|
|
|
|
|
|
+ it('returns formatted labels', function () {
|
|
|
|
|
+ expect(this.callback).to.have.been.calledWith(null, [
|
|
|
sinon.match({
|
|
sinon.match({
|
|
|
id: this.label._id,
|
|
id: this.label._id,
|
|
|
comment: this.label.comment,
|
|
comment: this.label.comment,
|
|
@@ -99,11 +88,11 @@ describe('LabelsManager', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('with invalid project id', function () {
|
|
|
|
|
- return it('returns an error', function (done) {
|
|
|
|
|
- return this.LabelsManager.getLabels('invalid id', error => {
|
|
|
|
|
|
|
+ describe('with invalid project id', function () {
|
|
|
|
|
+ it('returns an error', function (done) {
|
|
|
|
|
+ this.LabelsManager.getLabels('invalid id', error => {
|
|
|
expect(error).to.exist
|
|
expect(error).to.exist
|
|
|
- return done()
|
|
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -122,7 +111,7 @@ describe('LabelsManager', function () {
|
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
|
insertedId: new ObjectId(this.label_id),
|
|
insertedId: new ObjectId(this.label_id),
|
|
|
})
|
|
})
|
|
|
- return this.LabelsManager.createLabel(
|
|
|
|
|
|
|
+ this.LabelsManager.createLabel(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.version,
|
|
this.version,
|
|
@@ -134,27 +123,25 @@ describe('LabelsManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('flushes unprocessed updates', function () {
|
|
it('flushes unprocessed updates', function () {
|
|
|
- return expect(
|
|
|
|
|
|
|
+ expect(
|
|
|
this.UpdatesProcessor.processUpdatesForProject
|
|
this.UpdatesProcessor.processUpdatesForProject
|
|
|
).to.have.been.calledWith(this.project_id)
|
|
).to.have.been.calledWith(this.project_id)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('finds the V1 project id', function () {
|
|
it('finds the V1 project id', function () {
|
|
|
- return expect(this.WebApiManager.getHistoryId).to.have.been.calledWith(
|
|
|
|
|
|
|
+ expect(this.WebApiManager.getHistoryId).to.have.been.calledWith(
|
|
|
this.project_id
|
|
this.project_id
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('checks there is a chunk for the project + version', function () {
|
|
it('checks there is a chunk for the project + version', function () {
|
|
|
- return expect(
|
|
|
|
|
|
|
+ expect(
|
|
|
this.HistoryStoreManager.getChunkAtVersion
|
|
this.HistoryStoreManager.getChunkAtVersion
|
|
|
).to.have.been.calledWith(this.project_id, this.historyId, this.version)
|
|
).to.have.been.calledWith(this.project_id, this.historyId, this.version)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('create the label in mongo', function () {
|
|
it('create the label in mongo', function () {
|
|
|
- return expect(
|
|
|
|
|
- this.db.projectHistoryLabels.insertOne
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.insertOne).to.have.been.calledWith(
|
|
|
sinon.match({
|
|
sinon.match({
|
|
|
project_id: new ObjectId(this.project_id),
|
|
project_id: new ObjectId(this.project_id),
|
|
|
comment: this.comment,
|
|
comment: this.comment,
|
|
@@ -166,8 +153,8 @@ describe('LabelsManager', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('returns the label', function () {
|
|
|
|
|
- return expect(this.callback).to.have.been.calledWith(null, {
|
|
|
|
|
|
|
+ it('returns the label', function () {
|
|
|
|
|
+ expect(this.callback).to.have.been.calledWith(null, {
|
|
|
id: new ObjectId(this.label_id),
|
|
id: new ObjectId(this.label_id),
|
|
|
comment: this.comment,
|
|
comment: this.comment,
|
|
|
version: this.version,
|
|
version: this.version,
|
|
@@ -182,7 +169,7 @@ describe('LabelsManager', function () {
|
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
|
insertedId: new ObjectId(this.label_id),
|
|
insertedId: new ObjectId(this.label_id),
|
|
|
})
|
|
})
|
|
|
- return this.LabelsManager.createLabel(
|
|
|
|
|
|
|
+ this.LabelsManager.createLabel(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.version,
|
|
this.version,
|
|
@@ -193,10 +180,8 @@ describe('LabelsManager', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('create the label with the current date', function () {
|
|
|
|
|
- return expect(
|
|
|
|
|
- this.db.projectHistoryLabels.insertOne
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
|
|
+ it('create the label with the current date', function () {
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.insertOne).to.have.been.calledWith(
|
|
|
sinon.match({
|
|
sinon.match({
|
|
|
project_id: new ObjectId(this.project_id),
|
|
project_id: new ObjectId(this.project_id),
|
|
|
comment: this.comment,
|
|
comment: this.comment,
|
|
@@ -208,13 +193,13 @@ describe('LabelsManager', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('with shouldValidateExists = false', function () {
|
|
|
|
|
|
|
+ describe('with shouldValidateExists = false', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.createdAt = new Date(1)
|
|
this.createdAt = new Date(1)
|
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
|
insertedId: new ObjectId(this.label_id),
|
|
insertedId: new ObjectId(this.label_id),
|
|
|
})
|
|
})
|
|
|
- return this.LabelsManager.createLabel(
|
|
|
|
|
|
|
+ this.LabelsManager.createLabel(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.version,
|
|
this.version,
|
|
@@ -225,9 +210,39 @@ describe('LabelsManager', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('checks there is a chunk for the project + version', function () {
|
|
|
|
|
- return expect(this.HistoryStoreManager.getChunkAtVersion).to.not.have
|
|
|
|
|
- .been.called
|
|
|
|
|
|
|
+ it('checks there is a chunk for the project + version', function () {
|
|
|
|
|
+ expect(this.HistoryStoreManager.getChunkAtVersion).to.not.have.been
|
|
|
|
|
+ .called
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('with no userId', function () {
|
|
|
|
|
+ beforeEach(function () {
|
|
|
|
|
+ this.db.projectHistoryLabels.insertOne.yields(null, {
|
|
|
|
|
+ insertedId: new ObjectId(this.label_id),
|
|
|
|
|
+ })
|
|
|
|
|
+ const userId = undefined
|
|
|
|
|
+ this.LabelsManager.createLabel(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ userId,
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.comment,
|
|
|
|
|
+ this.createdAt,
|
|
|
|
|
+ false,
|
|
|
|
|
+ this.callback
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('creates the label without user_id', function () {
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.insertOne).to.have.been.calledWith(
|
|
|
|
|
+ sinon.match({
|
|
|
|
|
+ project_id: new ObjectId(this.project_id),
|
|
|
|
|
+ comment: this.comment,
|
|
|
|
|
+ version: this.version,
|
|
|
|
|
+ user_id: undefined,
|
|
|
|
|
+ created_at: this.now,
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -235,7 +250,7 @@ describe('LabelsManager', function () {
|
|
|
describe('deleteLabelForUser', function () {
|
|
describe('deleteLabelForUser', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.db.projectHistoryLabels.deleteOne.yields()
|
|
this.db.projectHistoryLabels.deleteOne.yields()
|
|
|
- return this.LabelsManager.deleteLabelForUser(
|
|
|
|
|
|
|
+ this.LabelsManager.deleteLabelForUser(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.label_id,
|
|
this.label_id,
|
|
@@ -243,10 +258,8 @@ describe('LabelsManager', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('removes the label from the database', function () {
|
|
|
|
|
- return expect(
|
|
|
|
|
- this.db.projectHistoryLabels.deleteOne
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
|
|
+ it('removes the label from the database', function () {
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.deleteOne).to.have.been.calledWith(
|
|
|
{
|
|
{
|
|
|
_id: new ObjectId(this.label_id),
|
|
_id: new ObjectId(this.label_id),
|
|
|
project_id: new ObjectId(this.project_id),
|
|
project_id: new ObjectId(this.project_id),
|
|
@@ -257,20 +270,18 @@ describe('LabelsManager', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('deleteLabel', function () {
|
|
|
|
|
|
|
+ describe('deleteLabel', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.db.projectHistoryLabels.deleteOne.yields()
|
|
this.db.projectHistoryLabels.deleteOne.yields()
|
|
|
- return this.LabelsManager.deleteLabel(
|
|
|
|
|
|
|
+ this.LabelsManager.deleteLabel(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.label_id,
|
|
this.label_id,
|
|
|
this.callback
|
|
this.callback
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('removes the label from the database', function () {
|
|
|
|
|
- return expect(
|
|
|
|
|
- this.db.projectHistoryLabels.deleteOne
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
|
|
+ it('removes the label from the database', function () {
|
|
|
|
|
+ expect(this.db.projectHistoryLabels.deleteOne).to.have.been.calledWith(
|
|
|
{
|
|
{
|
|
|
_id: new ObjectId(this.label_id),
|
|
_id: new ObjectId(this.label_id),
|
|
|
project_id: new ObjectId(this.project_id),
|
|
project_id: new ObjectId(this.project_id),
|