From 9442d16f9d239012b780a845ca5d4f319fab655a Mon Sep 17 00:00:00 2001 From: Sergio Sinuco Date: Mon, 9 Oct 2023 12:21:21 -0500 Subject: [PATCH] Change /auth to /login --- projects/04-burger-queen-api/e2e/auth.spec.js | 14 +++++++------- projects/04-burger-queen-api/e2e/globalSetup.js | 4 ++-- projects/04-burger-queen-api/e2e/users.spec.js | 6 +++--- .../guides/GETTING-STARTED-MONGODB.md | 2 +- .../guides/GETTING-STARTED-MONGODB.pt.md | 2 +- projects/04-burger-queen-api/routes/auth.js | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/projects/04-burger-queen-api/e2e/auth.spec.js b/projects/04-burger-queen-api/e2e/auth.spec.js index 58d75ff2c..2a5f46d63 100644 --- a/projects/04-burger-queen-api/e2e/auth.spec.js +++ b/projects/04-burger-queen-api/e2e/auth.spec.js @@ -2,14 +2,14 @@ const config = require('../config'); const { fetch, fetchWithAuth } = process; -describe('POST /auth', () => { +describe('POST /login', () => { it('should respond with 400 when email and password missing', () => ( - fetch('/auth', { method: 'POST' }) + fetch('/login', { method: 'POST' }) .then((resp) => expect(resp.status).toBe(400)) )); it('should respond with 400 when email is missing', () => ( - fetch('/auth', { + fetch('/login', { method: 'POST', body: { email: '', password: 'xxxx' }, }) @@ -17,7 +17,7 @@ describe('POST /auth', () => { )); it('should respond with 400 when password is missing', () => ( - fetch('/auth', { + fetch('/login', { method: 'POST', body: { email: 'foo@bar.baz' }, }) @@ -25,7 +25,7 @@ describe('POST /auth', () => { )); it('fail with 404 credentials dont match', () => ( - fetch('/auth', { + fetch('/login', { method: 'POST', body: { email: `foo-${Date.now()}@bar.baz`, password: 'xxxx' }, }) @@ -33,7 +33,7 @@ describe('POST /auth', () => { )); it('should create new auth token and allow access using it', () => ( - fetch('/auth', { + fetch('/login', { method: 'POST', body: { email: config.adminEmail, password: config.adminPassword }, }) @@ -41,7 +41,7 @@ describe('POST /auth', () => { expect(resp.status).toBe(200); return resp.json(); }) - .then(({ token }) => fetchWithAuth(token)(`/users/${config.adminEmail}`)) + .then(({ accessToken }) => fetchWithAuth(accessToken)(`/users/${config.adminEmail}`)) .then((resp) => { expect(resp.status).toBe(200); return resp.json(); diff --git a/projects/04-burger-queen-api/e2e/globalSetup.js b/projects/04-burger-queen-api/e2e/globalSetup.js index 1dd242ef7..622f3bab8 100644 --- a/projects/04-burger-queen-api/e2e/globalSetup.js +++ b/projects/04-burger-queen-api/e2e/globalSetup.js @@ -63,7 +63,7 @@ const createTestUser = () => fetchAsAdmin('/users', { if (resp.status !== 200) { throw new Error(`Error: Could not create test user - response ${resp.status}`); } - return fetch('/auth', { method: 'POST', body: __e2e.testUserCredentials }); + return fetch('/login', { method: 'POST', body: __e2e.testUserCredentials }); }) .then((resp) => { if (resp.status !== 200) { @@ -73,7 +73,7 @@ const createTestUser = () => fetchAsAdmin('/users', { }) .then(({ token }) => Object.assign(__e2e, { testUserToken: token })); -const checkAdminCredentials = () => fetch('/auth', { +const checkAdminCredentials = () => fetch('/login', { method: 'POST', body: __e2e.adminUserCredentials, }) diff --git a/projects/04-burger-queen-api/e2e/users.spec.js b/projects/04-burger-queen-api/e2e/users.spec.js index 08b8cc76a..928c992a1 100644 --- a/projects/04-burger-queen-api/e2e/users.spec.js +++ b/projects/04-burger-queen-api/e2e/users.spec.js @@ -237,7 +237,7 @@ describe('PUT /users/:uid', () => { body: { password: 'garmadon' }, }) .then((resp) => expect(resp.status).toBe(200)) - .then(() => fetch('/auth', { + .then(() => fetch('/login', { method: 'POST', body: { email: 'test@test.test', password: 'garmadon' }, })) @@ -254,7 +254,7 @@ describe('PUT /users/:uid', () => { body: { password: 'ohmygod' }, }) .then((resp) => expect(resp.status).toBe(200)) - .then(() => fetch('/auth', { + .then(() => fetch('/login', { method: 'POST', body: { email: 'test@test.test', password: 'ohmygod' }, })) @@ -286,7 +286,7 @@ describe('DELETE /users/:uid', () => { const credentials = { email: `foo-${Date.now()}@bar.baz`, password: '1234' }; return fetchAsAdmin('/users', { method: 'POST', body: credentials }) .then((resp) => expect(resp.status).toBe(200)) - .then(() => fetch('/auth', { method: 'POST', body: credentials })) + .then(() => fetch('/login', { method: 'POST', body: credentials })) .then((resp) => { expect(resp.status).toBe(200); return resp.json(); diff --git a/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.md b/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.md index e4966e158..85de8b845 100644 --- a/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.md +++ b/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.md @@ -177,7 +177,7 @@ Puedes confirmar si tu código funciona revisando la base de datos y con un test ### TODO 3: Implementar autenticación de usuario -En `routes/auth.js` está la ruta '/auth' definida, con un +En `routes/auth.js` está la ruta '/login' definida, con un ```js // TODO: Authenticate the user diff --git a/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.pt.md b/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.pt.md index ba2556129..8f4371670 100644 --- a/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.pt.md +++ b/projects/04-burger-queen-api/guides/GETTING-STARTED-MONGODB.pt.md @@ -173,7 +173,7 @@ dados e realizando um teste unitário. ### TODO 3: Implementar autenticación de usuario -En routes/auth.js, a rota '/auth' está definida com um +En routes/auth.js, a rota '/login' está definida com um ```js // TODO: Authenticate the user diff --git a/projects/04-burger-queen-api/routes/auth.js b/projects/04-burger-queen-api/routes/auth.js index 8037ee03e..95627b652 100644 --- a/projects/04-burger-queen-api/routes/auth.js +++ b/projects/04-burger-queen-api/routes/auth.js @@ -6,9 +6,9 @@ const { secret } = config; /** @module auth */ module.exports = (app, nextMain) => { /** - * @name /auth + * @name /login * @description Creates an authentication token. - * @path {POST} /auth + * @path {POST} /login * @body {String} email Email * @body {String} password Password * @response {Object} resp