summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-02-26 20:20:19 -0600
committerHombreLaser <sebastian-440@live.com>2023-02-26 20:20:19 -0600
commit094ee717f710ea4cf81d221c5bf9660b805da9b1 (patch)
treed3b5d3169bb82c34eb2cb3a0f9d6da72ad5846f7 /spec/requests
parent4a1faf270ae328a1a28d9f8f54d9a96ed41a1542 (diff)
Añade spec para refresh_tokens
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/authentications_spec.rb1
-rw-r--r--spec/requests/post_refresh_tokens_spec.rb27
-rw-r--r--spec/requests/post_user_accounts_spec.rb1
3 files changed, 29 insertions, 0 deletions
diff --git a/spec/requests/authentications_spec.rb b/spec/requests/authentications_spec.rb
index 3b1da3e..6b33402 100644
--- a/spec/requests/authentications_spec.rb
+++ b/spec/requests/authentications_spec.rb
@@ -4,6 +4,7 @@ require 'rails_helper'
RSpec.describe 'POST /api/authenticate', type: :request do
it_behaves_like 'a POST request' do
+ let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }
let(:route) { '/api/authenticate' }
let(:expected_error_messages) { ['Credenciales incorrectas'] }
let(:desired_error_status) { 401 }
diff --git a/spec/requests/post_refresh_tokens_spec.rb b/spec/requests/post_refresh_tokens_spec.rb
new file mode 100644
index 0000000..836e340
--- /dev/null
+++ b/spec/requests/post_refresh_tokens_spec.rb
@@ -0,0 +1,27 @@
+# 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
+ user.update_attribute(:session_key, SecureRandom.hex(16))
+ service_params = { email: user.email, role: user.role, session_key: user.session_key }
+ token = Services::TokenGenerationService.new(service_params).call(DateTime.current - 7.days)
+ headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{token}" }
+ 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/post_user_accounts_spec.rb b/spec/requests/post_user_accounts_spec.rb
index 4370af8..7c5aacc 100644
--- a/spec/requests/post_user_accounts_spec.rb
+++ b/spec/requests/post_user_accounts_spec.rb
@@ -4,6 +4,7 @@ require 'rails_helper'
RSpec.describe 'POST /api/user_accounts', type: :request do
it_behaves_like 'a POST request' do
+ let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }
let(:route) { '/api/user_accounts' }
let(:expected_error_messages) do
["Password can't be blank", 'Email is invalid', "First name can't be blank", "Last name can't be blank",