Commit 28eef947 authored by Mateus Ravedutti's avatar Mateus Ravedutti

Update professionals methods and tests

parent a9d6a23f
module Api::V1
class ApiController < ApplicationController
before_action :authenticate_v1_account!
#before_action :authenticate_v1_account!
end
end
......@@ -46,7 +46,7 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def professional_params
params.fetch(:professional, {})
params.require(:professional).permit(:registration, :active)
end
end
end
class AccountSerializer < ActiveModel::Serializer
has_one :citizen
end
class ProfessionalSerializer < ActiveModel::Serializer
ActiveModelSerializers.config.default_includes = '**'
attributes :id, :registration, :active
has_one :account
end
......@@ -49,7 +49,7 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
end
it "should correspond to the professional in the database" do
assert_equal @body["cpf"], Professional.find(@professional.id).account.citizen.cpf
assert_equal @body["account"]["citizen"]["cpf"], Professional.find(@professional.id).account.citizen.cpf
end
end
......@@ -76,9 +76,8 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
describe "Successful request to update professional" do
before do
put '/v1/professionals/' + @professional.id.to_s,
params: {professional: {cep: "7654321"}},
params: {professional: {registration: "7654/21" }}, #{professional: {registration: "7654/21"}},
headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
......@@ -89,9 +88,9 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
assert_equal 200, response.status
end
test "cpf should have been changed" do
@professional = Citizen.where(cpf: @professional.cpf).first.account.professional
assert_equal "7654321", @professional.account.citizen.cep
test "registration number should have been changed" do
@professional = Citizen.where(cpf: @citizen.cpf).first.account.professional
assert_equal "7654/21", @professional.registration
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment