From 4c2900fb08eb8a9778ad4cc3f5e7330bb4e45ef5 Mon Sep 17 00:00:00 2001 From: Melony Franchini Date: Sun, 22 Oct 2023 13:57:21 -0600 Subject: [PATCH] Refactor: Add unrestful routes for login/logout --- config/routes.rb | 4 ++-- spec/requests/api/v1/sessions_request_spec.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index abd0ec8..ce95d73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,8 @@ # resources :users, only: [:show] #for ease of understanding, we will skip resoruces for now put '/puzzles', to: 'puzzles#index' - post '/login', to: 'sessions#create' - delete '/logout', to: 'sessions#destroy' + post '/users/:user_id/login', to: 'sessions#create' + delete '/users/:user_id/logout', to: 'sessions#destroy' get '/users/:user_id', to: 'users#show' get '/users/:user_id/dashboard', to: 'users#dashboard' diff --git a/spec/requests/api/v1/sessions_request_spec.rb b/spec/requests/api/v1/sessions_request_spec.rb index a5977b4..f25cd4d 100644 --- a/spec/requests/api/v1/sessions_request_spec.rb +++ b/spec/requests/api/v1/sessions_request_spec.rb @@ -19,7 +19,7 @@ } headers = { 'CONTENT_TYPE' => 'application/json' } - post '/api/v1/login', headers:, params: JSON.generate(login_data) + post "/api/v1/users/#{user.id}/login", headers:, params: JSON.generate(login_data) expect(response).to have_http_status(201) expect(session[:user_id]).to eq(user.id) @@ -43,7 +43,7 @@ } headers = { 'CONTENT_TYPE' => 'application/json' } - post '/api/v1/login', headers:, params: JSON.generate(login_data) + post "/api/v1/users/#{user.id}/login", headers:, params: JSON.generate(login_data) expect(response).to have_http_status(401) @@ -63,12 +63,12 @@ login_data = { email: user.email, password: user.password } headers = { 'CONTENT_TYPE' => 'application/json' } - post '/api/v1/login', headers:, params: JSON.generate(login_data) + post "/api/v1/users/#{user.id}/login", headers:, params: JSON.generate(login_data) expect(response).to have_http_status(201) expect(session[:user_id]).to eq(user.id) - delete '/api/v1/logout' + delete "/api/v1/users/#{user.id}/logout" expect(response).to have_http_status(204) expect(session[:user_id]).to be_nil @@ -83,14 +83,14 @@ # login_data = { email: user.email, password: user.password } # headers = { 'CONTENT_TYPE' => 'application/json' } - # post '/api/v1/login', headers:, params: JSON.generate(login_data) + # post "/api/v1/users/#{user.id}/login", headers:, params: JSON.generate(login_data) # expect(response).to have_http_status(201) # expect(session[:user_id]).to eq(user.id) - # delete '/api/v1/logout' + # delete "/api/v1/users/007/logout" - # expect(response).to have_http_status(???) + # expect(response).to have_http_status(401) # expect(session[:user_id]).to eq(user.id) # end end