Merge pull request #33413 from overleaf/revert-33040-em-parse-req-errors

Revert "Replace isZodErrorLike with custom error types in request validation"

GitOrigin-RevId: 1f51fe9e14ffabf283f1229552d3887136420f8f
This commit is contained in:
Eric Mc Sween
2026-05-06 08:06:41 +00:00
committed by Copybot
parent 98def949ec
commit 3da2d53acb
16 changed files with 80 additions and 100 deletions
@@ -176,12 +176,31 @@ describe('Authentication', function () {
}
})
it('should return 400 with bad email (missing @)', async function () {
const { statusCode } = await tryLoginWithEmail('foo')
const { statusCode, body } = 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 } = await tryLoginWithEmail(1)
const { statusCode, body } = 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,13 +219,14 @@ 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 } = await this.user.doRequest('POST', {
const { response, body } = 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,6 +375,11 @@ 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()
}
)
@@ -399,6 +404,14 @@ 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()
}
)
@@ -685,7 +685,7 @@ describe('SubscriptionController', function () {
ctx.next = sinon.stub()
await expect(
ctx.SubscriptionController.pauseSubscription(ctx.req, ctx.res, ctx.next)
).to.be.rejectedWith('Invalid request parameters')
).to.be.rejectedWith('Invalid params')
})
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 { InvalidRequestError } from '@overleaf/validation-tools'
import { ZodError } from 'zod'
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(
InvalidRequestError
ZodError
)
})
})