Commit bf3f803b authored by Mateus Ravedutti's avatar Mateus Ravedutti

Professionals test draft

parent f4b04b61
require 'test_helper'
class ProfessionalsControllerTest < ActionDispatch::IntegrationTest
def professional
@professional ||= professionals :one
end
class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
describe "Token access" do
before do
@citizen= Citizen.new(cpf: "123.456.789-04",
birth_date: "18/04/1997",
cep: "1234567",
email: "test@example.com",
name: "Test Example",
phone1: "(12)1212-1212",
rg: "1234567")
@account = Account.new(uid: @citizen.cpf,
password: "123mudar",
password_confirmation: "123mudar")
@professional = Professional.new(active: true,
registration: "123")
@account.save!
@professional.account_id = @account.id
@professional.save!
@professional.account_id = @account.id
@professional.save!
def test_index
get professionals_url
assert_response :success
end
@auth_headers = @account.create_new_auth_token
def test_create
assert_difference('Professional.count') do
post professionals_url, params: { professional: { } }
@token = @auth_headers['access-token']
@client_id = @auth_headers['client']
@expiry = @auth_headers['expiry']
end
assert_response 201
end
describe "Successful request to show professional" do
before do
get '/v1/professionals/' + @professional.id.to_s, params: {},
headers: @auth_headers
def test_show
get professional_url(professional)
assert_response :success
end
@body = JSON.parse(response.body)
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
def test_update
patch professional_url(professional), params: { professional: { } }
assert_response 200
end
it "should be successful" do
assert_equal 200, response.status
end
it "should correspond to the current account" do
assert_equal @body["id"], @controller.current_account.professional.id
end
it "should correspond to the professional in the database" do
assert_equal @body["cpf"], Professional.find(@professional.id).account.citizen.cpf
end
end
describe "Successful request to delete professional" do
before do
delete '/v1/professionals/' + @professional.id.to_s, params: {},
headers: @auth_headers
def test_destroy
assert_difference('Professional.count', -1) do
delete professional_url(professional)
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
assert_equal 204, response.status
end
it "should have been deleted" do
assert_nil Professional.where(id: @professional.id).first
end
end
assert_response 204
describe "Successful request to update professional" do
before do
put '/v1/professionals/' + @professional.id.to_s,
params: {professional: {cep: "7654321"}},
headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
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
end
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