[misc] run format_fix and lint:fix

This commit is contained in:
Jakob Ackermann 2021-07-13 12:04:47 +01:00
parent 21f5c25dbe
commit 9074ddd8a5
10 changed files with 49 additions and 51 deletions

View file

@ -60,7 +60,7 @@ if (!module.parent) {
return logger.info(`contacts starting up, listening on ${host}:${port}`) return logger.info(`contacts starting up, listening on ${host}:${port}`)
}) })
}) })
.catch((err) => { .catch(err => {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.') logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1) process.exit(1)
}) })

View file

@ -33,11 +33,11 @@ module.exports = ContactManager = {
db.contacts.updateOne( db.contacts.updateOne(
{ {
user_id user_id,
}, },
update, update,
{ {
upsert: true upsert: true,
}, },
callback callback
) )
@ -56,7 +56,7 @@ module.exports = ContactManager = {
return db.contacts.findOne( return db.contacts.findOne(
{ {
user_id user_id,
}, },
function (error, user) { function (error, user) {
if (error != null) { if (error != null) {
@ -65,9 +65,9 @@ module.exports = ContactManager = {
return callback(null, user != null ? user.contacts : undefined) return callback(null, user != null ? user.contacts : undefined)
} }
) )
} },
} }
;['touchContact', 'getContacts'].map((method) => ;['touchContact', 'getContacts'].map(method =>
metrics.timeAsyncMethod( metrics.timeAsyncMethod(
ContactManager, ContactManager,
method, method,

View file

@ -64,16 +64,16 @@ module.exports = HttpController = {
contacts.push({ contacts.push({
user_id, user_id,
n: data.n, n: data.n,
ts: data.ts ts: data.ts,
}) })
} }
HttpController._sortContacts(contacts) HttpController._sortContacts(contacts)
contacts = contacts.slice(0, limit) contacts = contacts.slice(0, limit)
const contact_ids = contacts.map((contact) => contact.user_id) const contact_ids = contacts.map(contact => contact.user_id)
return res.status(200).send({ return res.status(200).send({
contact_ids contact_ids,
}) })
}) })
}, },
@ -96,5 +96,5 @@ module.exports = HttpController = {
} }
} }
}) })
} },
} }

View file

@ -24,5 +24,5 @@ async function setupDb() {
module.exports = { module.exports = {
db, db,
ObjectId, ObjectId,
waitForDb waitForDb,
} }

View file

@ -5,17 +5,17 @@ module.exports = {
internal: { internal: {
contacts: { contacts: {
port: 3036, port: 3036,
host: process.env.LISTEN_ADDRESS || 'localhost' host: process.env.LISTEN_ADDRESS || 'localhost',
} },
}, },
mongo: { mongo: {
options: { options: {
useUnifiedTopology: useUnifiedTopology:
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true' (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
}, },
url: url:
process.env.MONGO_CONNECTION_STRING || process.env.MONGO_CONNECTION_STRING ||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex` `mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
} },
} }

View file

@ -31,7 +31,7 @@ module.exports = {
this.initing = true this.initing = true
this.callbacks.push(callback) this.callbacks.push(callback)
waitForDb().then(() => { waitForDb().then(() => {
return app.listen(3036, 'localhost', (error) => { return app.listen(3036, 'localhost', error => {
if (error != null) { if (error != null) {
throw error throw error
} }
@ -45,5 +45,5 @@ module.exports = {
})() })()
}) })
}) })
} },
} }

View file

@ -33,7 +33,7 @@ describe('Getting Contacts', function () {
{ {
method: 'GET', method: 'GET',
url: `${HOST}/user/${this.user_id}/contacts`, url: `${HOST}/user/${this.user_id}/contacts`,
json: true json: true,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(200) response.statusCode.should.equal(200)
@ -57,8 +57,8 @@ describe('Getting Contacts', function () {
method: 'POST', method: 'POST',
url: `${HOST}/user/${user_id}/contacts`, url: `${HOST}/user/${user_id}/contacts`,
json: { json: {
contact_id contact_id,
} },
}, },
cb cb
) )
@ -66,11 +66,11 @@ describe('Getting Contacts', function () {
return async.series( return async.series(
[ [
// 2 is preferred since touched twice, then 3 since most recent, then 1 // 2 is preferred since touched twice, then 3 since most recent, then 1
(cb) => ContactsApp.ensureRunning(cb), cb => ContactsApp.ensureRunning(cb),
(cb) => touchContact(this.user_id, this.contact_id_1, cb), cb => touchContact(this.user_id, this.contact_id_1, cb),
(cb) => touchContact(this.user_id, this.contact_id_2, cb), cb => touchContact(this.user_id, this.contact_id_2, cb),
(cb) => touchContact(this.user_id, this.contact_id_2, cb), cb => touchContact(this.user_id, this.contact_id_2, cb),
(cb) => touchContact(this.user_id, this.contact_id_3, cb) cb => touchContact(this.user_id, this.contact_id_3, cb),
], ],
done done
) )
@ -81,14 +81,14 @@ describe('Getting Contacts', function () {
{ {
method: 'GET', method: 'GET',
url: `${HOST}/user/${this.user_id}/contacts`, url: `${HOST}/user/${this.user_id}/contacts`,
json: true json: true,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(200) response.statusCode.should.equal(200)
body.contact_ids.should.deep.equal([ body.contact_ids.should.deep.equal([
this.contact_id_2, this.contact_id_2,
this.contact_id_3, this.contact_id_3,
this.contact_id_1 this.contact_id_1,
]) ])
return done() return done()
} }
@ -100,13 +100,13 @@ describe('Getting Contacts', function () {
{ {
method: 'GET', method: 'GET',
url: `${HOST}/user/${this.user_id}/contacts?limit=2`, url: `${HOST}/user/${this.user_id}/contacts?limit=2`,
json: true json: true,
}, },
(error, response, body) => { (error, response, body) => {
response.statusCode.should.equal(200) response.statusCode.should.equal(200)
body.contact_ids.should.deep.equal([ body.contact_ids.should.deep.equal([
this.contact_id_2, this.contact_id_2,
this.contact_id_3 this.contact_id_3,
]) ])
return done() return done()
} }

View file

@ -3,7 +3,7 @@ const SandboxedModule = require('sandboxed-module')
SandboxedModule.configure({ SandboxedModule.configure({
requires: { requires: {
'logger-sharelatex': { log() {} }, 'logger-sharelatex': { log() {} },
'@overleaf/metrics': { timeAsyncMethod() {} } '@overleaf/metrics': { timeAsyncMethod() {} },
}, },
globals: { Buffer, console, process } globals: { Buffer, console, process },
}) })

View file

@ -25,9 +25,9 @@ describe('ContactManager', function () {
requires: { requires: {
'./mongodb': { './mongodb': {
db: (this.db = { contacts: {} }), db: (this.db = { contacts: {} }),
ObjectId ObjectId,
} },
} },
}) })
this.user_id = ObjectId().toString() this.user_id = ObjectId().toString()
this.contact_id = ObjectId().toString() this.contact_id = ObjectId().toString()
@ -57,19 +57,19 @@ describe('ContactManager', function () {
.calledWith( .calledWith(
{ {
user_id: sinon.match( user_id: sinon.match(
(o) => o.toString() === this.user_id.toString() 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)
@ -98,7 +98,7 @@ describe('ContactManager', function () {
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 return (this.db.contacts.findOne = sinon
.stub() .stub()
@ -113,9 +113,7 @@ describe('ContactManager', function () {
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( user_id: sinon.match(o => o.toString() === this.user_id.toString()),
(o) => o.toString() === this.user_id.toString()
)
}) })
.should.equal(true) .should.equal(true)
}) })

View file

@ -21,8 +21,8 @@ describe('HttpController', function () {
beforeEach(function () { beforeEach(function () {
this.HttpController = SandboxedModule.require(modulePath, { this.HttpController = SandboxedModule.require(modulePath, {
requires: { requires: {
'./ContactManager': (this.ContactManager = {}) './ContactManager': (this.ContactManager = {}),
} },
}) })
this.user_id = 'mock-user-id' this.user_id = 'mock-user-id'
this.contact_id = 'mock-contact-id' this.contact_id = 'mock-contact-id'
@ -87,7 +87,7 @@ describe('HttpController', function () {
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 return (this.ContactManager.getContacts = sinon
.stub() .stub()
@ -108,7 +108,7 @@ describe('HttpController', function () {
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: ['user-id-2', 'user-id-1', 'user-id-3'] contact_ids: ['user-id-2', 'user-id-1', 'user-id-3'],
}) })
.should.equal(true) .should.equal(true)
}) })
@ -123,7 +123,7 @@ describe('HttpController', function () {
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: ['user-id-2', 'user-id-1'] contact_ids: ['user-id-2', 'user-id-1'],
}) })
.should.equal(true) .should.equal(true)
}) })
@ -140,7 +140,7 @@ describe('HttpController', function () {
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)
}) })