From 76148b27f7501bac061992136852be4303370c8d Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 1 Jun 2021 01:36:53 +0200 Subject: refactor API errors to standard error format --- server/tests/api/users/users-verification.ts | 5 +++-- server/tests/api/users/users.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 1a9a519a0..e0f2f2112 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -19,6 +19,7 @@ import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/l import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User } from '../../../../shared/models/users' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -89,8 +90,8 @@ describe('Test users account verification', function () { }) it('Should not allow login for user with unverified email', async function () { - const resLogin = await login(server.url, server.client, user1, 400) - expect(resLogin.body.error).to.contain('User email is not verified.') + const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) + expect(resLogin.body.detail).to.contain('User email is not verified.') }) it('Should verify the user via email and allow login', async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index cea98aac7..363236b62 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -93,16 +93,16 @@ describe('Test users', function () { const client = { id: 'client', secret: server.client.secret } const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_client') - expect(res.body.error).to.contain('client is invalid') + expect(res.body.type).to.equal('invalid_client') + expect(res.body.detail).to.contain('client is invalid') }) it('Should not login with an invalid client secret', async function () { const client = { id: server.client.id, secret: 'coucou' } const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_client') - expect(res.body.error).to.contain('client is invalid') + expect(res.body.type).to.equal('invalid_client') + expect(res.body.detail).to.contain('client is invalid') }) }) @@ -112,16 +112,16 @@ describe('Test users', function () { const user = { username: 'captain crochet', password: server.user.password } const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_grant') - expect(res.body.error).to.contain('credentials are invalid') + expect(res.body.type).to.equal('invalid_grant') + expect(res.body.detail).to.contain('credentials are invalid') }) it('Should not login with an invalid password', async function () { const user = { username: server.user.username, password: 'mew_three' } const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) - expect(res.body.code).to.equal('invalid_grant') - expect(res.body.error).to.contain('credentials are invalid') + expect(res.body.type).to.equal('invalid_grant') + expect(res.body.detail).to.contain('credentials are invalid') }) it('Should not be able to upload a video', async function () { -- cgit v1.2.3