From 167dfadfea3412956f6807e342740dd600179f80 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Mon, 17 Feb 2020 07:38:24 +0000 Subject: [PATCH] prettier: convert test/acceptance decaffeinated files to Prettier format --- .../test/acceptance/js/ContactsApp.js | 60 +++--- .../acceptance/js/GettingContactsTests.js | 186 ++++++++++-------- 2 files changed, 134 insertions(+), 112 deletions(-) diff --git a/services/contacts/test/acceptance/js/ContactsApp.js b/services/contacts/test/acceptance/js/ContactsApp.js index 97e6d8148d..d192b0386c 100644 --- a/services/contacts/test/acceptance/js/ContactsApp.js +++ b/services/contacts/test/acceptance/js/ContactsApp.js @@ -11,33 +11,37 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const app = require('../../../app'); -require("logger-sharelatex").logger.level("error"); +const app = require('../../../app') +require('logger-sharelatex').logger.level('error') module.exports = { - running: false, - initing: false, - callbacks: [], - ensureRunning(callback) { - if (callback == null) { callback = function(error) {}; } - if (this.running) { - return callback(); - } else if (this.initing) { - return this.callbacks.push(callback); - } else { - this.initing = true; - this.callbacks.push(callback); - return app.listen(3036, "localhost", error => { - if (error != null) { throw error; } - this.running = true; - return (() => { - const result = []; - for (callback of Array.from(this.callbacks)) { - result.push(callback()); - } - return result; - })(); - }); - } - } -}; \ No newline at end of file + running: false, + initing: false, + callbacks: [], + ensureRunning(callback) { + if (callback == null) { + callback = function(error) {} + } + if (this.running) { + return callback() + } else if (this.initing) { + return this.callbacks.push(callback) + } else { + this.initing = true + this.callbacks.push(callback) + return app.listen(3036, 'localhost', error => { + if (error != null) { + throw error + } + this.running = true + return (() => { + const result = [] + for (callback of Array.from(this.callbacks)) { + result.push(callback()) + } + return result + })() + }) + } + } +} diff --git a/services/contacts/test/acceptance/js/GettingContactsTests.js b/services/contacts/test/acceptance/js/GettingContactsTests.js index c2598e6bd4..da1b90940b 100644 --- a/services/contacts/test/acceptance/js/GettingContactsTests.js +++ b/services/contacts/test/acceptance/js/GettingContactsTests.js @@ -11,88 +11,106 @@ * DS102: Remove unnecessary code created because of implicit returns * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const sinon = require("sinon"); -const chai = require("chai"); -chai.should(); -const { - expect -} = chai; -const { - ObjectId -} = require("mongojs"); -const request = require("request"); -const async = require("async"); -const ContactsApp = require("./ContactsApp"); -const HOST = "http://localhost:3036"; +const sinon = require('sinon') +const chai = require('chai') +chai.should() +const { expect } = chai +const { ObjectId } = require('mongojs') +const request = require('request') +const async = require('async') +const ContactsApp = require('./ContactsApp') +const HOST = 'http://localhost:3036' -describe("Getting Contacts", function() { - describe("with no contacts", function() { - beforeEach(function(done){ - this.user_id = ObjectId().toString(); - return ContactsApp.ensureRunning(done); - }); - - return it("should return an empty array", function(done) { - return request({ - method: "GET", - url: `${HOST}/user/${this.user_id}/contacts`, - json: true - }, (error, response, body) => { - response.statusCode.should.equal(200); - body.contact_ids.should.deep.equal([]); - return done(); - }); - }); - }); - - return describe("with contacts", function() { - beforeEach(function(done) { - this.user_id = ObjectId().toString(); - this.contact_id_1 = ObjectId().toString(); - this.contact_id_2 = ObjectId().toString(); - this.contact_id_3 = ObjectId().toString(); - - const touchContact = (user_id, contact_id, cb) => request({ - method: "POST", - url: `${HOST}/user/${user_id}/contacts`, - json: { - contact_id - } - }, cb); - - 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) - ], done); - }); - - it("should return a sorted list of contacts", function(done) { - return request({ - method: "GET", - url: `${HOST}/user/${this.user_id}/contacts`, - 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]); - return done(); - }); - }); - - return it("should respect a limit and only return top X contacts", function() { - return request({ - method: "GET", - url: `${HOST}/user/${this.user_id}/contacts?limit=2`, - json: true - }, (error, response, body) => { - response.statusCode.should.equal(200); - body.contact_ids.should.deep.equal([this.contact_id_2, this.contact_id_3]); - return done(); - }); - }); - }); -}); - \ No newline at end of file +describe('Getting Contacts', function() { + describe('with no contacts', function() { + beforeEach(function(done) { + this.user_id = ObjectId().toString() + return ContactsApp.ensureRunning(done) + }) + + return it('should return an empty array', function(done) { + return request( + { + method: 'GET', + url: `${HOST}/user/${this.user_id}/contacts`, + json: true + }, + (error, response, body) => { + response.statusCode.should.equal(200) + body.contact_ids.should.deep.equal([]) + return done() + } + ) + }) + }) + + return describe('with contacts', function() { + beforeEach(function(done) { + this.user_id = ObjectId().toString() + this.contact_id_1 = ObjectId().toString() + this.contact_id_2 = ObjectId().toString() + this.contact_id_3 = ObjectId().toString() + + const touchContact = (user_id, contact_id, cb) => + request( + { + method: 'POST', + url: `${HOST}/user/${user_id}/contacts`, + json: { + contact_id + } + }, + cb + ) + + 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) + ], + done + ) + }) + + it('should return a sorted list of contacts', function(done) { + return request( + { + method: 'GET', + url: `${HOST}/user/${this.user_id}/contacts`, + 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 + ]) + return done() + } + ) + }) + + return it('should respect a limit and only return top X contacts', function() { + return request( + { + method: 'GET', + url: `${HOST}/user/${this.user_id}/contacts?limit=2`, + json: true + }, + (error, response, body) => { + response.statusCode.should.equal(200) + body.contact_ids.should.deep.equal([ + this.contact_id_2, + this.contact_id_3 + ]) + return done() + } + ) + }) + }) +})