mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 22:29:01 +02:00
[misc] run format_fix and lint:fix
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 = {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ async function setupDb() {
|
||||
module.exports = {
|
||||
db,
|
||||
ObjectId,
|
||||
waitForDb
|
||||
waitForDb,
|
||||
}
|
||||
|
||||
@@ -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`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
})()
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user