From 6b49fe21f76883e039a2c149ecd5906c9d038de3 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 25 Feb 2023 00:20:59 -0600 Subject: Añade spec de creación de usuarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/support/sessions_helper.rb | 12 ++++++++++++ spec/support/shared_examples/requests/post_request.rb | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 spec/support/sessions_helper.rb (limited to 'spec/support') diff --git a/spec/support/sessions_helper.rb b/spec/support/sessions_helper.rb new file mode 100644 index 0000000..eeb12d8 --- /dev/null +++ b/spec/support/sessions_helper.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'rails_helper' + +# Module to generate JWTs for use in specs. +module SessionsHelper + def jwt(user) + user_params = { credentials: { email: user.email, password: user.password } } + post('/api/authenticate', user_params.to_json) + JSON.parse(response.body)['token'] + end +end \ No newline at end of file diff --git a/spec/support/shared_examples/requests/post_request.rb b/spec/support/shared_examples/requests/post_request.rb index 6ea2a86..a253281 100644 --- a/spec/support/shared_examples/requests/post_request.rb +++ b/spec/support/shared_examples/requests/post_request.rb @@ -11,9 +11,9 @@ RSpec.shared_examples 'a POST request' do context 'with incorrect parameters' do it 'returns a client side error http status and a error message' do - post('/api/authenticate', params: wrong_params.to_json, headers:) + post(route, params: wrong_params.to_json, headers:) expect(response).to have_http_status(desired_error_status) - expect(response.body).to include(expected_error_message) + expect(response.body).to include_strings(expected_error_messages) end end end -- cgit v1.2.3