mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-28 19:41:33 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -4,8 +4,8 @@ const MockRequest = require('../helpers/MockRequest')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const modulePath = '../../../../app/src/Features/Errors/HttpErrorHandler.js'
|
||||
|
||||
describe('HttpErrorHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('HttpErrorHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.req = new MockRequest()
|
||||
this.res = new MockResponse()
|
||||
|
||||
@@ -19,8 +19,8 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('handleErrorByStatusCode', function() {
|
||||
it('returns the http status code of 400 errors', function() {
|
||||
describe('handleErrorByStatusCode', function () {
|
||||
it('returns the http status code of 400 errors', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -31,7 +31,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(400)
|
||||
})
|
||||
|
||||
it('returns the http status code of 500 errors', function() {
|
||||
it('returns the http status code of 500 errors', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -42,7 +42,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(500)
|
||||
})
|
||||
|
||||
it('returns the http status code of any 5xx error', function() {
|
||||
it('returns the http status code of any 5xx error', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -53,7 +53,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(588)
|
||||
})
|
||||
|
||||
it('returns the http status code of any 4xx error', function() {
|
||||
it('returns the http status code of any 4xx error', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -64,7 +64,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(488)
|
||||
})
|
||||
|
||||
it('returns 500 for http status codes smaller than 400', function() {
|
||||
it('returns 500 for http status codes smaller than 400', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -75,7 +75,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(500)
|
||||
})
|
||||
|
||||
it('returns 500 for http status codes larger than 600', function() {
|
||||
it('returns 500 for http status codes larger than 600', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -86,13 +86,13 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.statusCode).to.equal(500)
|
||||
})
|
||||
|
||||
it('returns 500 when the error has no http status code', function() {
|
||||
it('returns 500 when the error has no http status code', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(this.req, this.res, err)
|
||||
expect(this.res.statusCode).to.equal(500)
|
||||
})
|
||||
|
||||
it('uses the conflict() error handler', function() {
|
||||
it('uses the conflict() error handler', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -103,7 +103,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.body).to.equal('conflict')
|
||||
})
|
||||
|
||||
it('uses the forbidden() error handler', function() {
|
||||
it('uses the forbidden() error handler', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -114,7 +114,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.body).to.equal('restricted')
|
||||
})
|
||||
|
||||
it('uses the notFound() error handler', function() {
|
||||
it('uses the notFound() error handler', function () {
|
||||
const err = new Error()
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
this.req,
|
||||
@@ -125,7 +125,7 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.res.body).to.equal('not found')
|
||||
})
|
||||
|
||||
it('uses the unprocessableEntity() error handler', function() {
|
||||
it('uses the unprocessableEntity() error handler', function () {
|
||||
const err = new Error()
|
||||
err.httpStatusCode = 422
|
||||
this.HttpErrorHandler.handleErrorByStatusCode(
|
||||
@@ -138,18 +138,18 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('badRequest', function() {
|
||||
it('returns 400', function() {
|
||||
describe('badRequest', function () {
|
||||
it('returns 400', function () {
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res)
|
||||
expect(this.res.statusCode).to.equal(400)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res)
|
||||
expect(this.res.body).to.equal('client error')
|
||||
})
|
||||
|
||||
it("should render a template including the error message when content-type is 'html'", function() {
|
||||
it("should render a template including the error message when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res, 'an error')
|
||||
expect(this.res.renderedTemplate).to.equal('general/400')
|
||||
@@ -159,7 +159,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should render a default template when content-type is 'html' and no message is provided", function() {
|
||||
it("should render a default template when content-type is 'html' and no message is provided", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res)
|
||||
expect(this.res.renderedTemplate).to.equal('general/400')
|
||||
@@ -169,7 +169,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object when content-type is 'json'", function() {
|
||||
it("should return a json object when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res, 'an error', {
|
||||
foo: 'bar'
|
||||
@@ -180,25 +180,25 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return an empty json object when content-type is 'json' and no message and info are provided", function() {
|
||||
it("should return an empty json object when content-type is 'json' and no message and info are provided", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.badRequest(this.req, this.res)
|
||||
expect(JSON.parse(this.res.body)).to.deep.equal({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('conflict', function() {
|
||||
it('returns 409', function() {
|
||||
describe('conflict', function () {
|
||||
it('returns 409', function () {
|
||||
this.HttpErrorHandler.conflict(this.req, this.res)
|
||||
expect(this.res.statusCode).to.equal(409)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.conflict(this.req, this.res)
|
||||
expect(this.res.body).to.equal('conflict')
|
||||
})
|
||||
|
||||
it("should render a template including the error message when content-type is 'html'", function() {
|
||||
it("should render a template including the error message when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.unprocessableEntity(this.req, this.res, 'an error')
|
||||
expect(this.res.renderedTemplate).to.equal('general/400')
|
||||
@@ -208,7 +208,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object when content-type is 'json'", function() {
|
||||
it("should return a json object when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.unprocessableEntity(
|
||||
this.req,
|
||||
@@ -225,18 +225,18 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('forbidden', function() {
|
||||
it('returns 403', function() {
|
||||
describe('forbidden', function () {
|
||||
it('returns 403', function () {
|
||||
this.HttpErrorHandler.forbidden(this.req, this.res)
|
||||
expect(this.res.statusCode).to.equal(403)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.forbidden(this.req, this.res)
|
||||
expect(this.res.body).to.equal('restricted')
|
||||
})
|
||||
|
||||
it("should render a template when content-type is 'html'", function() {
|
||||
it("should render a template when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.forbidden(this.req, this.res)
|
||||
expect(this.res.renderedTemplate).to.equal('user/restricted')
|
||||
@@ -245,7 +245,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object when content-type is 'json'", function() {
|
||||
it("should return a json object when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.forbidden(this.req, this.res, 'an error', {
|
||||
foo: 'bar'
|
||||
@@ -257,18 +257,18 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('notFound', function() {
|
||||
it('returns 404', function() {
|
||||
describe('notFound', function () {
|
||||
it('returns 404', function () {
|
||||
this.HttpErrorHandler.notFound(this.req, this.res)
|
||||
expect(this.res.statusCode).to.equal(404)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.notFound(this.req, this.res)
|
||||
expect(this.res.body).to.equal('not found')
|
||||
})
|
||||
|
||||
it("should render a template when content-type is 'html'", function() {
|
||||
it("should render a template when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.notFound(this.req, this.res)
|
||||
expect(this.res.renderedTemplate).to.equal('general/404')
|
||||
@@ -277,7 +277,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object when content-type is 'json'", function() {
|
||||
it("should return a json object when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.notFound(this.req, this.res, 'an error', {
|
||||
foo: 'bar'
|
||||
@@ -289,18 +289,18 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unprocessableEntity', function() {
|
||||
it('returns 422', function() {
|
||||
describe('unprocessableEntity', function () {
|
||||
it('returns 422', function () {
|
||||
this.HttpErrorHandler.unprocessableEntity(this.req, this.res)
|
||||
expect(this.res.statusCode).to.equal(422)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.unprocessableEntity(this.req, this.res)
|
||||
expect(this.res.body).to.equal('unprocessable entity')
|
||||
})
|
||||
|
||||
it("should render a template including the error message when content-type is 'html'", function() {
|
||||
it("should render a template including the error message when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.unprocessableEntity(this.req, this.res, 'an error')
|
||||
expect(this.res.renderedTemplate).to.equal('general/400')
|
||||
@@ -310,7 +310,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object when content-type is 'json'", function() {
|
||||
it("should return a json object when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.unprocessableEntity(
|
||||
this.req,
|
||||
@@ -326,13 +326,13 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('legacyInternal', function() {
|
||||
it('returns 500', function() {
|
||||
describe('legacyInternal', function () {
|
||||
it('returns 500', function () {
|
||||
this.HttpErrorHandler.legacyInternal(this.req, this.res, new Error())
|
||||
expect(this.res.statusCode).to.equal(500)
|
||||
})
|
||||
|
||||
it('should send the error to the logger', function() {
|
||||
it('should send the error to the logger', function () {
|
||||
const error = new Error('message')
|
||||
this.HttpErrorHandler.legacyInternal(
|
||||
this.req,
|
||||
@@ -343,12 +343,12 @@ describe('HttpErrorHandler', function() {
|
||||
expect(this.logger.error).to.have.been.calledWith(error)
|
||||
})
|
||||
|
||||
it('should print a message when no content-type is included', function() {
|
||||
it('should print a message when no content-type is included', function () {
|
||||
this.HttpErrorHandler.legacyInternal(this.req, this.res, new Error())
|
||||
expect(this.res.body).to.equal('internal server error')
|
||||
})
|
||||
|
||||
it("should render a template when content-type is 'html'", function() {
|
||||
it("should render a template when content-type is 'html'", function () {
|
||||
this.req.accepts = () => 'html'
|
||||
this.HttpErrorHandler.legacyInternal(this.req, this.res, new Error())
|
||||
expect(this.res.renderedTemplate).to.equal('general/500')
|
||||
@@ -357,7 +357,7 @@ describe('HttpErrorHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it("should return a json object with a static message when content-type is 'json'", function() {
|
||||
it("should return a json object with a static message when content-type is 'json'", function () {
|
||||
this.req.accepts = () => 'json'
|
||||
this.HttpErrorHandler.legacyInternal(
|
||||
this.req,
|
||||
|
||||
Reference in New Issue
Block a user