From 9074ddd8a591543adf07f7fa5cb6a998a74f16da Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 13 Jul 2021 12:04:47 +0100 Subject: [PATCH] [misc] run format_fix and lint:fix --- services/contacts/app.js | 2 +- services/contacts/app/js/ContactManager.js | 10 ++++---- services/contacts/app/js/HttpController.js | 8 +++---- services/contacts/app/js/mongodb.js | 2 +- services/contacts/config/settings.defaults.js | 10 ++++---- .../test/acceptance/js/ContactsApp.js | 4 ++-- .../acceptance/js/GettingContactsTests.js | 24 +++++++++---------- services/contacts/test/setup.js | 4 ++-- .../test/unit/js/ContactsManagerTests.js | 24 +++++++++---------- .../test/unit/js/HttpControllerTests.js | 12 +++++----- 10 files changed, 49 insertions(+), 51 deletions(-) diff --git a/services/contacts/app.js b/services/contacts/app.js index 1070a148a8..9027234adb 100644 --- a/services/contacts/app.js +++ b/services/contacts/app.js @@ -60,7 +60,7 @@ if (!module.parent) { return logger.info(`contacts starting up, listening on ${host}:${port}`) }) }) - .catch((err) => { + .catch(err => { logger.fatal({ err }, 'Cannot connect to mongo. Exiting.') process.exit(1) }) diff --git a/services/contacts/app/js/ContactManager.js b/services/contacts/app/js/ContactManager.js index 95c51730e3..5025befa21 100644 --- a/services/contacts/app/js/ContactManager.js +++ b/services/contacts/app/js/ContactManager.js @@ -33,11 +33,11 @@ module.exports = ContactManager = { db.contacts.updateOne( { - user_id + user_id, }, update, { - upsert: true + upsert: true, }, callback ) @@ -56,7 +56,7 @@ module.exports = ContactManager = { return db.contacts.findOne( { - user_id + user_id, }, function (error, user) { if (error != null) { @@ -65,9 +65,9 @@ module.exports = ContactManager = { return callback(null, user != null ? user.contacts : undefined) } ) - } + }, } -;['touchContact', 'getContacts'].map((method) => +;['touchContact', 'getContacts'].map(method => metrics.timeAsyncMethod( ContactManager, method, diff --git a/services/contacts/app/js/HttpController.js b/services/contacts/app/js/HttpController.js index 691f542047..2a499649e7 100644 --- a/services/contacts/app/js/HttpController.js +++ b/services/contacts/app/js/HttpController.js @@ -64,16 +64,16 @@ module.exports = HttpController = { contacts.push({ user_id, n: data.n, - ts: data.ts + ts: data.ts, }) } HttpController._sortContacts(contacts) 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({ - contact_ids + contact_ids, }) }) }, @@ -96,5 +96,5 @@ module.exports = HttpController = { } } }) - } + }, } diff --git a/services/contacts/app/js/mongodb.js b/services/contacts/app/js/mongodb.js index d34d080451..ecd9017283 100644 --- a/services/contacts/app/js/mongodb.js +++ b/services/contacts/app/js/mongodb.js @@ -24,5 +24,5 @@ async function setupDb() { module.exports = { db, ObjectId, - waitForDb + waitForDb, } diff --git a/services/contacts/config/settings.defaults.js b/services/contacts/config/settings.defaults.js index fa6b97b6d6..516d362492 100644 --- a/services/contacts/config/settings.defaults.js +++ b/services/contacts/config/settings.defaults.js @@ -5,17 +5,17 @@ module.exports = { internal: { contacts: { port: 3036, - host: process.env.LISTEN_ADDRESS || 'localhost' - } + host: process.env.LISTEN_ADDRESS || 'localhost', + }, }, mongo: { options: { useUnifiedTopology: - (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true' + (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true', }, url: process.env.MONGO_CONNECTION_STRING || - `mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex` - } + `mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`, + }, } diff --git a/services/contacts/test/acceptance/js/ContactsApp.js b/services/contacts/test/acceptance/js/ContactsApp.js index 1f98213591..d2d28085e4 100644 --- a/services/contacts/test/acceptance/js/ContactsApp.js +++ b/services/contacts/test/acceptance/js/ContactsApp.js @@ -31,7 +31,7 @@ module.exports = { this.initing = true this.callbacks.push(callback) waitForDb().then(() => { - return app.listen(3036, 'localhost', (error) => { + return app.listen(3036, 'localhost', error => { if (error != null) { throw error } @@ -45,5 +45,5 @@ module.exports = { })() }) }) - } + }, } diff --git a/services/contacts/test/acceptance/js/GettingContactsTests.js b/services/contacts/test/acceptance/js/GettingContactsTests.js index ac0e424e96..4ba97e8e41 100644 --- a/services/contacts/test/acceptance/js/GettingContactsTests.js +++ b/services/contacts/test/acceptance/js/GettingContactsTests.js @@ -33,7 +33,7 @@ describe('Getting Contacts', function () { { method: 'GET', url: `${HOST}/user/${this.user_id}/contacts`, - json: true + json: true, }, (error, response, body) => { response.statusCode.should.equal(200) @@ -57,8 +57,8 @@ describe('Getting Contacts', function () { method: 'POST', url: `${HOST}/user/${user_id}/contacts`, json: { - contact_id - } + contact_id, + }, }, cb ) @@ -66,11 +66,11 @@ describe('Getting Contacts', function () { return async.series( [ // 2 is preferred since touched twice, then 3 since most recent, then 1 - (cb) => ContactsApp.ensureRunning(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_3, cb) + cb => ContactsApp.ensureRunning(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_3, cb), ], done ) @@ -81,14 +81,14 @@ describe('Getting Contacts', function () { { method: 'GET', url: `${HOST}/user/${this.user_id}/contacts`, - json: true + json: true, }, (error, response, body) => { response.statusCode.should.equal(200) body.contact_ids.should.deep.equal([ this.contact_id_2, this.contact_id_3, - this.contact_id_1 + this.contact_id_1, ]) return done() } @@ -100,13 +100,13 @@ describe('Getting Contacts', function () { { method: 'GET', url: `${HOST}/user/${this.user_id}/contacts?limit=2`, - json: true + json: true, }, (error, response, body) => { response.statusCode.should.equal(200) body.contact_ids.should.deep.equal([ this.contact_id_2, - this.contact_id_3 + this.contact_id_3, ]) return done() } diff --git a/services/contacts/test/setup.js b/services/contacts/test/setup.js index eb9883ffcc..0219b771d5 100644 --- a/services/contacts/test/setup.js +++ b/services/contacts/test/setup.js @@ -3,7 +3,7 @@ const SandboxedModule = require('sandboxed-module') SandboxedModule.configure({ requires: { 'logger-sharelatex': { log() {} }, - '@overleaf/metrics': { timeAsyncMethod() {} } + '@overleaf/metrics': { timeAsyncMethod() {} }, }, - globals: { Buffer, console, process } + globals: { Buffer, console, process }, }) diff --git a/services/contacts/test/unit/js/ContactsManagerTests.js b/services/contacts/test/unit/js/ContactsManagerTests.js index aa4af08a66..981471daaf 100644 --- a/services/contacts/test/unit/js/ContactsManagerTests.js +++ b/services/contacts/test/unit/js/ContactsManagerTests.js @@ -25,9 +25,9 @@ describe('ContactManager', function () { requires: { './mongodb': { db: (this.db = { contacts: {} }), - ObjectId - } - } + ObjectId, + }, + }, }) this.user_id = ObjectId().toString() this.contact_id = ObjectId().toString() @@ -57,19 +57,19 @@ describe('ContactManager', function () { .calledWith( { user_id: sinon.match( - (o) => o.toString() === this.user_id.toString() - ) + o => o.toString() === this.user_id.toString() + ), }, { $inc: { - 'contacts.mock_contact.n': 1 + 'contacts.mock_contact.n': 1, }, $set: { - 'contacts.mock_contact.ts': new Date() - } + 'contacts.mock_contact.ts': new Date(), + }, }, { - upsert: true + upsert: true, } ) .should.equal(true) @@ -98,7 +98,7 @@ describe('ContactManager', function () { return describe('getContacts', function () { beforeEach(function () { this.user = { - contacts: ['mock', 'contacts'] + contacts: ['mock', 'contacts'], } return (this.db.contacts.findOne = sinon .stub() @@ -113,9 +113,7 @@ describe('ContactManager', function () { it("should find the user's contacts", function () { return this.db.contacts.findOne .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) }) diff --git a/services/contacts/test/unit/js/HttpControllerTests.js b/services/contacts/test/unit/js/HttpControllerTests.js index e458acfb5c..2bbb86b3ac 100644 --- a/services/contacts/test/unit/js/HttpControllerTests.js +++ b/services/contacts/test/unit/js/HttpControllerTests.js @@ -21,8 +21,8 @@ describe('HttpController', function () { beforeEach(function () { this.HttpController = SandboxedModule.require(modulePath, { requires: { - './ContactManager': (this.ContactManager = {}) - } + './ContactManager': (this.ContactManager = {}), + }, }) this.user_id = 'mock-user-id' this.contact_id = 'mock-contact-id' @@ -87,7 +87,7 @@ describe('HttpController', function () { this.contacts = { 'user-id-1': { n: 2, 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() @@ -108,7 +108,7 @@ describe('HttpController', function () { return it('should return a sorted list of contacts by count and timestamp', function () { return this.res.send .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) }) @@ -123,7 +123,7 @@ describe('HttpController', function () { return it('should return the most commonly used contacts up to the limit', function () { return this.res.send .calledWith({ - contact_ids: ['user-id-2', 'user-id-1'] + contact_ids: ['user-id-2', 'user-id-1'], }) .should.equal(true) }) @@ -140,7 +140,7 @@ describe('HttpController', function () { return it('should return an empty list', function () { return this.res.send .calledWith({ - contact_ids: [] + contact_ids: [], }) .should.equal(true) })