mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #33490 from overleaf/em-parse-req-errors-2
Reintroduce custom error types in request validation GitOrigin-RevId: 1985ca04c8fe693fb836b042517d94700343bc46
This commit is contained in:
@@ -176,31 +176,12 @@ describe('Authentication', function () {
|
||||
}
|
||||
})
|
||||
it('should return 400 with bad email (missing @)', async function () {
|
||||
const { statusCode, body } = await tryLoginWithEmail('foo')
|
||||
const { statusCode } = await tryLoginWithEmail('foo')
|
||||
expect(statusCode).to.equal(400)
|
||||
expect(body).to.deep.equal({
|
||||
name: 'ZodValidationError',
|
||||
details: [
|
||||
{ code: 'custom', path: [], message: 'Invalid email address' },
|
||||
],
|
||||
statusCode: 400,
|
||||
})
|
||||
})
|
||||
it('should return 400 with bad email (number)', async function () {
|
||||
const { statusCode, body } = await tryLoginWithEmail(1)
|
||||
const { statusCode } = await tryLoginWithEmail(1)
|
||||
expect(statusCode).to.equal(400)
|
||||
expect(body).to.deep.equal({
|
||||
name: 'ZodValidationError',
|
||||
details: [
|
||||
{
|
||||
expected: 'string',
|
||||
code: 'invalid_type',
|
||||
path: [],
|
||||
message: 'Invalid input: expected string, received number',
|
||||
},
|
||||
],
|
||||
statusCode: 400,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -219,14 +219,13 @@ describe('Project CRUD', function () {
|
||||
})
|
||||
it('returns a 400 when publicAccessLevel is an unsupported access level', async function () {
|
||||
await this.user.makePrivate(this.projectId)
|
||||
const { response, body } = await this.user.doRequest('POST', {
|
||||
const { response } = await this.user.doRequest('POST', {
|
||||
url: `/project/${this.projectId}/settings/admin`,
|
||||
json: {
|
||||
publicAccessLevel: 'readOnly',
|
||||
},
|
||||
})
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body.details[0].message).to.equal('unexpected access level')
|
||||
const project = await Project.findById(this.projectId).exec()
|
||||
expect(project.publicAccesLevel).to.equal('private')
|
||||
})
|
||||
|
||||
@@ -375,11 +375,6 @@ describe('ProjectInviteTests', function () {
|
||||
return done(err)
|
||||
}
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body.details).to.have.lengthOf(1)
|
||||
expect(response.body.details[0].path).to.eql(['body', 'email'])
|
||||
expect(response.body.details[0].message).to.equal(
|
||||
'Invalid input: expected string, received object'
|
||||
)
|
||||
done()
|
||||
}
|
||||
)
|
||||
@@ -404,14 +399,6 @@ describe('ProjectInviteTests', function () {
|
||||
return done(err)
|
||||
}
|
||||
expect(response.statusCode).to.equal(400)
|
||||
expect(body.details).to.have.lengthOf(1)
|
||||
expect(response.body.details[0].path).to.eql([
|
||||
'body',
|
||||
'privileges',
|
||||
])
|
||||
expect(response.body.details[0].message).to.equal(
|
||||
'Invalid option: expected one of "readOnly"|"readAndWrite"|"review"'
|
||||
)
|
||||
done()
|
||||
}
|
||||
)
|
||||
|
||||
@@ -845,8 +845,8 @@ describe('CompileController', function () {
|
||||
|
||||
it('should reject the request', function (ctx) {
|
||||
ctx.next.should.have.been.calledWithMatch({
|
||||
name: 'ParamsError',
|
||||
cause: asZodError({
|
||||
name: 'InvalidParamsError',
|
||||
zodError: asZodError({
|
||||
code: 'custom',
|
||||
path: ['params', 'file'],
|
||||
message: 'path traversal detected',
|
||||
@@ -868,8 +868,8 @@ describe('CompileController', function () {
|
||||
|
||||
it('should reject the request', function (ctx) {
|
||||
ctx.next.should.have.been.calledWithMatch({
|
||||
name: 'ParamsError',
|
||||
cause: asZodError({
|
||||
name: 'InvalidParamsError',
|
||||
zodError: asZodError({
|
||||
origin: 'string',
|
||||
code: 'invalid_format',
|
||||
format: 'regex',
|
||||
|
||||
@@ -695,7 +695,7 @@ describe('SubscriptionController', function () {
|
||||
ctx.next = sinon.stub()
|
||||
await expect(
|
||||
ctx.SubscriptionController.pauseSubscription(ctx.req, ctx.res, ctx.next)
|
||||
).to.be.rejectedWith('Invalid params')
|
||||
).to.be.rejectedWith('Invalid request parameters')
|
||||
})
|
||||
|
||||
it('should throw an error if an invalid pause length is provided', async function (ctx) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assert, beforeEach, describe, it, vi } from 'vitest'
|
||||
import sinon from 'sinon'
|
||||
import { ZodError } from 'zod'
|
||||
import { InvalidRequestError } from '@overleaf/validation-tools'
|
||||
|
||||
const modulePath = '../../../../app/src/Features/Tags/TagsController.mjs'
|
||||
|
||||
@@ -202,7 +202,7 @@ describe('TagsController', function () {
|
||||
it('without a name', function (ctx) {
|
||||
ctx.req.body = { name: undefined }
|
||||
ctx.TagsController.renameTag(ctx.req, ctx.res).should.be.rejectedWith(
|
||||
ZodError
|
||||
InvalidRequestError
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user