mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-01 13:42:21 -05:00
prettier: convert test/unit decaffeinated files to Prettier format
This commit is contained in:
parent
856b428272
commit
9f46abc0d1
2 changed files with 266 additions and 252 deletions
|
@ -9,116 +9,135 @@
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
* DS102: Remove unnecessary code created because of implicit returns
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon')
|
||||||
const chai = require('chai');
|
const chai = require('chai')
|
||||||
const should = chai.should();
|
const should = chai.should()
|
||||||
const {
|
const { expect } = chai
|
||||||
expect
|
const modulePath = '../../../app/js/ContactManager.js'
|
||||||
} = chai;
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const modulePath = "../../../app/js/ContactManager.js";
|
const { ObjectId } = require('mongojs')
|
||||||
const SandboxedModule = require('sandboxed-module');
|
const tk = require('timekeeper')
|
||||||
const {
|
|
||||||
ObjectId
|
|
||||||
} = require("mongojs");
|
|
||||||
const tk = require("timekeeper");
|
|
||||||
|
|
||||||
describe("ContactManager", function() {
|
describe('ContactManager', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
tk.freeze(Date.now());
|
tk.freeze(Date.now())
|
||||||
this.ContactManager = SandboxedModule.require(modulePath, { requires: {
|
this.ContactManager = SandboxedModule.require(modulePath, {
|
||||||
"./mongojs": {
|
requires: {
|
||||||
|
'./mongojs': {
|
||||||
db: (this.db = { contacts: {} }),
|
db: (this.db = { contacts: {} }),
|
||||||
ObjectId
|
ObjectId
|
||||||
},
|
},
|
||||||
'logger-sharelatex': { log: sinon.stub() },
|
'logger-sharelatex': { log: sinon.stub() },
|
||||||
'metrics-sharelatex': { timeAsyncMethod: sinon.stub() }
|
'metrics-sharelatex': { timeAsyncMethod: sinon.stub() }
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
this.user_id = ObjectId().toString();
|
this.user_id = ObjectId().toString()
|
||||||
this.contact_id = ObjectId().toString();
|
this.contact_id = ObjectId().toString()
|
||||||
return this.callback = sinon.stub();
|
return (this.callback = sinon.stub())
|
||||||
});
|
})
|
||||||
|
|
||||||
afterEach(function() { return tk.reset(); });
|
afterEach(function() {
|
||||||
|
return tk.reset()
|
||||||
|
})
|
||||||
|
|
||||||
describe("touchContact", function() {
|
describe('touchContact', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.db.contacts.update = sinon.stub().callsArg(3);
|
return (this.db.contacts.update = sinon.stub().callsArg(3))
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("with a valid user_id", function() {
|
describe('with a valid user_id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.ContactManager.touchContact(this.user_id, (this.contact_id = "mock_contact"), this.callback);
|
return this.ContactManager.touchContact(
|
||||||
});
|
this.user_id,
|
||||||
|
(this.contact_id = 'mock_contact'),
|
||||||
|
this.callback
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should increment the contact count and timestamp", function() {
|
it('should increment the contact count and timestamp', function() {
|
||||||
return this.db.contacts.update
|
return this.db.contacts.update
|
||||||
.calledWith({
|
.calledWith(
|
||||||
user_id: sinon.match(o => o.toString() === this.user_id.toString())
|
{
|
||||||
}, {
|
user_id: sinon.match(
|
||||||
|
o => o.toString() === this.user_id.toString()
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
$inc: {
|
$inc: {
|
||||||
"contacts.mock_contact.n": 1
|
'contacts.mock_contact.n': 1
|
||||||
},
|
},
|
||||||
$set: {
|
$set: {
|
||||||
"contacts.mock_contact.ts": new Date()
|
'contacts.mock_contact.ts': new Date()
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
upsert: true
|
upsert: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
.should.equal(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
return it("should call the callback", function() {
|
return it('should call the callback', function() {
|
||||||
return this.callback.called.should.equal(true);
|
return this.callback.called.should.equal(true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
return describe("with an invalid user id", function() {
|
return describe('with an invalid user id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.ContactManager.touchContact("not-valid-object-id", this.contact_id, this.callback);
|
return this.ContactManager.touchContact(
|
||||||
});
|
'not-valid-object-id',
|
||||||
|
this.contact_id,
|
||||||
|
this.callback
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
return it("should call the callback with an error", function() {
|
return it('should call the callback with an error', function() {
|
||||||
return this.callback.calledWith(new Error()).should.equal(true);
|
return this.callback.calledWith(new Error()).should.equal(true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
return describe("getContacts", function() {
|
return describe('getContacts', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.user = {
|
this.user = {
|
||||||
contacts: ["mock", "contacts"]
|
contacts: ['mock', 'contacts']
|
||||||
};
|
}
|
||||||
return this.db.contacts.findOne = sinon.stub().callsArgWith(1, null, this.user);
|
return (this.db.contacts.findOne = sinon
|
||||||
});
|
.stub()
|
||||||
|
.callsArgWith(1, null, this.user))
|
||||||
|
})
|
||||||
|
|
||||||
describe("with a valid user_id", function() {
|
describe('with a valid user_id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.ContactManager.getContacts(this.user_id, this.callback);
|
return this.ContactManager.getContacts(this.user_id, this.callback)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("should find the user's contacts", function() {
|
it("should find the user's contacts", function() {
|
||||||
return this.db.contacts.findOne
|
return this.db.contacts.findOne
|
||||||
.calledWith({
|
.calledWith({
|
||||||
user_id: sinon.match(o => o.toString() === this.user_id.toString())
|
user_id: sinon.match(o => o.toString() === this.user_id.toString())
|
||||||
})
|
})
|
||||||
.should.equal(true);
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
return it("should call the callback with the contacts", function() {
|
return it('should call the callback with the contacts', function() {
|
||||||
return this.callback.calledWith(null, this.user.contacts).should.equal(true);
|
return this.callback
|
||||||
});
|
.calledWith(null, this.user.contacts)
|
||||||
});
|
.should.equal(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
return describe("with an invalid user id", function() {
|
return describe('with an invalid user id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.ContactManager.getContacts("not-valid-object-id", this.callback);
|
return this.ContactManager.getContacts(
|
||||||
});
|
'not-valid-object-id',
|
||||||
|
this.callback
|
||||||
return it("should call the callback with an error", function() {
|
)
|
||||||
return this.callback.calledWith(new Error()).should.equal(true);
|
})
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return it('should call the callback with an error', function() {
|
||||||
|
return this.callback.calledWith(new Error()).should.equal(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -10,150 +10,145 @@
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
* DS102: Remove unnecessary code created because of implicit returns
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon')
|
||||||
const chai = require('chai');
|
const chai = require('chai')
|
||||||
const should = chai.should();
|
const should = chai.should()
|
||||||
const {
|
const { expect } = chai
|
||||||
expect
|
const modulePath = '../../../app/js/HttpController.js'
|
||||||
} = chai;
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const modulePath = "../../../app/js/HttpController.js";
|
|
||||||
const SandboxedModule = require('sandboxed-module');
|
|
||||||
|
|
||||||
describe("HttpController", function() {
|
describe('HttpController', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.HttpController = SandboxedModule.require(modulePath, { requires: {
|
this.HttpController = SandboxedModule.require(modulePath, {
|
||||||
"./ContactManager": (this.ContactManager = {}),
|
requires: {
|
||||||
"logger-sharelatex": (this.logger = { log: sinon.stub() })
|
'./ContactManager': (this.ContactManager = {}),
|
||||||
|
'logger-sharelatex': (this.logger = { log: sinon.stub() })
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
this.user_id = "mock-user-id";
|
this.user_id = 'mock-user-id'
|
||||||
this.contact_id = "mock-contact-id";
|
this.contact_id = 'mock-contact-id'
|
||||||
|
|
||||||
this.req = {};
|
this.req = {}
|
||||||
this.res = {};
|
this.res = {}
|
||||||
this.res.status = sinon.stub().returns(this.res);
|
this.res.status = sinon.stub().returns(this.res)
|
||||||
this.res.end = sinon.stub();
|
this.res.end = sinon.stub()
|
||||||
this.res.send = sinon.stub();
|
this.res.send = sinon.stub()
|
||||||
return this.next = sinon.stub();
|
return (this.next = sinon.stub())
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("addContact", function() {
|
describe('addContact', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.params =
|
this.req.params = { user_id: this.user_id }
|
||||||
{user_id: this.user_id};
|
return (this.ContactManager.touchContact = sinon.stub().callsArg(2))
|
||||||
return this.ContactManager.touchContact = sinon.stub().callsArg(2);
|
})
|
||||||
});
|
|
||||||
|
|
||||||
describe("with a valid user_id and contact_id", function() {
|
describe('with a valid user_id and contact_id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.body =
|
this.req.body = { contact_id: this.contact_id }
|
||||||
{contact_id: this.contact_id};
|
return this.HttpController.addContact(this.req, this.res, this.next)
|
||||||
return this.HttpController.addContact(this.req, this.res, this.next);
|
})
|
||||||
});
|
|
||||||
|
|
||||||
it("should update the contact in the user's contact list", function() {
|
it("should update the contact in the user's contact list", function() {
|
||||||
return this.ContactManager.touchContact
|
return this.ContactManager.touchContact
|
||||||
.calledWith(this.user_id, this.contact_id)
|
.calledWith(this.user_id, this.contact_id)
|
||||||
.should.equal(true);
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("should update the user in the contact's contact list", function() {
|
it("should update the user in the contact's contact list", function() {
|
||||||
return this.ContactManager.touchContact
|
return this.ContactManager.touchContact
|
||||||
.calledWith(this.contact_id, this.user_id)
|
.calledWith(this.contact_id, this.user_id)
|
||||||
.should.equal(true);
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
return it("should send back a 204 status", function() {
|
return it('should send back a 204 status', function() {
|
||||||
this.res.status.calledWith(204).should.equal(true);
|
this.res.status.calledWith(204).should.equal(true)
|
||||||
return this.res.end.called.should.equal(true);
|
return this.res.end.called.should.equal(true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
return describe("with an invalid contact id", function() {
|
return describe('with an invalid contact id', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.body =
|
this.req.body = { contact_id: '' }
|
||||||
{contact_id: ""};
|
return this.HttpController.addContact(this.req, this.res, this.next)
|
||||||
return this.HttpController.addContact(this.req, this.res, this.next);
|
})
|
||||||
});
|
|
||||||
|
|
||||||
return it("should return 400, Bad Request", function() {
|
return it('should return 400, Bad Request', function() {
|
||||||
this.res.status.calledWith(400).should.equal(true);
|
this.res.status.calledWith(400).should.equal(true)
|
||||||
return this.res.send.calledWith("contact_id should be a non-blank string").should.equal(true);
|
return this.res.send
|
||||||
});
|
.calledWith('contact_id should be a non-blank string')
|
||||||
});
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
return describe("getContacts", function() {
|
return describe('getContacts', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.params =
|
this.req.params = { user_id: this.user_id }
|
||||||
{user_id: this.user_id};
|
const now = Date.now()
|
||||||
const now = Date.now();
|
|
||||||
this.contacts = {
|
this.contacts = {
|
||||||
"user-id-1": { n: 2, ts: new Date(now) },
|
'user-id-1': { n: 2, ts: new Date(now) },
|
||||||
"user-id-2": { n: 4, ts: new Date(now) },
|
'user-id-2': { n: 4, ts: new Date(now) },
|
||||||
"user-id-3": { n: 2, ts: new Date(now - 1000) }
|
'user-id-3': { n: 2, ts: new Date(now - 1000) }
|
||||||
};
|
}
|
||||||
return this.ContactManager.getContacts = sinon.stub().callsArgWith(1, null, this.contacts);
|
return (this.ContactManager.getContacts = sinon
|
||||||
});
|
.stub()
|
||||||
|
.callsArgWith(1, null, this.contacts))
|
||||||
|
})
|
||||||
|
|
||||||
describe("normally", function() {
|
describe('normally', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
return this.HttpController.getContacts(this.req, this.res, this.next);
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("should look up the contacts in mongo", function() {
|
it('should look up the contacts in mongo', function() {
|
||||||
return this.ContactManager.getContacts
|
return this.ContactManager.getContacts
|
||||||
.calledWith(this.user_id)
|
.calledWith(this.user_id)
|
||||||
.should.equal(true);
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
|
|
||||||
return it("should return a sorted list of contacts by count and timestamp", function() {
|
return it('should return a sorted list of contacts by count and timestamp', function() {
|
||||||
return this.res.send
|
return this.res.send
|
||||||
.calledWith({
|
.calledWith({
|
||||||
contact_ids: [
|
contact_ids: ['user-id-2', 'user-id-1', 'user-id-3']
|
||||||
"user-id-2",
|
})
|
||||||
"user-id-1",
|
.should.equal(true)
|
||||||
"user-id-3"
|
})
|
||||||
]
|
|
||||||
})
|
})
|
||||||
.should.equal(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("with more contacts than the limit", function() {
|
describe('with more contacts than the limit', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.query =
|
this.req.query = { limit: 2 }
|
||||||
{limit: 2};
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
||||||
return this.HttpController.getContacts(this.req, this.res, this.next);
|
})
|
||||||
});
|
|
||||||
|
|
||||||
return it("should return the most commonly used contacts up to the limit", function() {
|
return it('should return the most commonly used contacts up to the limit', function() {
|
||||||
return this.res.send
|
return this.res.send
|
||||||
.calledWith({
|
.calledWith({
|
||||||
contact_ids: [
|
contact_ids: ['user-id-2', 'user-id-1']
|
||||||
"user-id-2",
|
})
|
||||||
"user-id-1"
|
.should.equal(true)
|
||||||
]
|
})
|
||||||
})
|
})
|
||||||
.should.equal(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("without a contact list", function() {
|
describe('without a contact list', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.ContactManager.getContacts = sinon.stub().callsArgWith(1, null, null);
|
this.ContactManager.getContacts = sinon
|
||||||
return this.HttpController.getContacts(this.req, this.res, this.next);
|
.stub()
|
||||||
});
|
.callsArgWith(1, null, null)
|
||||||
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
||||||
|
})
|
||||||
|
|
||||||
return it("should return an empty list", function() {
|
return it('should return an empty list', function() {
|
||||||
return this.res.send
|
return this.res.send
|
||||||
.calledWith({
|
.calledWith({
|
||||||
contact_ids: []
|
contact_ids: []
|
||||||
})
|
})
|
||||||
.should.equal(true);
|
.should.equal(true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
return describe("with a holding account", function() { return it("should not return holding accounts"); });
|
return describe('with a holding account', function() {
|
||||||
});
|
return it('should not return holding accounts')
|
||||||
});
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue