From 2ae0cd8a8dc6d630ee1a7a84ddf6111609dbdeb7 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 30 Mar 2023 17:29:40 -0600 Subject: Mejora la estructura de los specs --- .../post_refresh_tokens_controller_spec.rb | 26 ---------------------- .../refresh_tokens_controller/post_spec.rb | 26 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 spec/requests/refresh_tokens_controller/post_refresh_tokens_controller_spec.rb create mode 100644 spec/requests/refresh_tokens_controller/post_spec.rb (limited to 'spec/requests/refresh_tokens_controller') diff --git a/spec/requests/refresh_tokens_controller/post_refresh_tokens_controller_spec.rb b/spec/requests/refresh_tokens_controller/post_refresh_tokens_controller_spec.rb deleted file mode 100644 index 5d8f8f0..0000000 --- a/spec/requests/refresh_tokens_controller/post_refresh_tokens_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe 'POST /api/refresh_tokens', type: :request do - let(:user) { create(:user_account) } - let(:token) { jwt(user) } - - it 'generates a new JSON web token' do - headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token['refresh']}" } - post('/api/refresh_tokens', headers:) - expect(response).to have_http_status(200) - expect(response.body).to include_strings(%w[refresh token]) - end - - context 'with an expired token' do - it 'returns an error message' do - service_params = { email: user.email, role: user.role } - jwt = Services::TokenGenerationService.new(service_params).call(DateTime.current - 5.days) - headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{jwt[:refresh]}" } - post('/api/refresh_tokens', headers:) - expect(response).to have_http_status(401) - expect(response.body).to include('error_message') - end - end -end diff --git a/spec/requests/refresh_tokens_controller/post_spec.rb b/spec/requests/refresh_tokens_controller/post_spec.rb new file mode 100644 index 0000000..5d8f8f0 --- /dev/null +++ b/spec/requests/refresh_tokens_controller/post_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'POST /api/refresh_tokens', type: :request do + let(:user) { create(:user_account) } + let(:token) { jwt(user) } + + it 'generates a new JSON web token' do + headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token['refresh']}" } + post('/api/refresh_tokens', headers:) + expect(response).to have_http_status(200) + expect(response.body).to include_strings(%w[refresh token]) + end + + context 'with an expired token' do + it 'returns an error message' do + service_params = { email: user.email, role: user.role } + jwt = Services::TokenGenerationService.new(service_params).call(DateTime.current - 5.days) + headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{jwt[:refresh]}" } + post('/api/refresh_tokens', headers:) + expect(response).to have_http_status(401) + expect(response.body).to include('error_message') + end + end +end -- cgit v1.2.3