occupations_controller_test.rb 2.21 KB
Newer Older
Rafael Ravedutti's avatar
Rafael Ravedutti committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# This file is part of Agendador.
#
# Agendador is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Agendador is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Agendador.  If not, see <https://www.gnu.org/licenses/>.

16 17 18 19 20
require 'test_helper'

class OccupationsControllerTest < ActionDispatch::IntegrationTest
  describe "Token access" do
    before do
21 22 23 24 25
      @parana = State.new(
        abbreviation: "PR",
        ibge_code: "41",
        name: "Paraná"
      )
mateus ravedutti's avatar
mateus ravedutti committed
26 27
      @parana.save!

28 29 30 31 32
      @curitiba = City.new(
        ibge_code: "4106902",
        name: "Curitiba",
        state_id: @parana.id
      )
mateus ravedutti's avatar
mateus ravedutti committed
33 34
      @curitiba.save!

35 36 37
      @citizen = Citizen.new(
        cpf: "10845922904",
        birth_date: "Apr 18 1997",
38
        cep: "80530336",
39 40 41
        email: "test@example.com",
        name: "Test Example",
        phone1: "(12)1212-1212",
42 43
        address_street: "Street from Curitiba",
        address_number: "421",
44 45 46
        city_id: @curitiba.id,
        rg: "1234567"
      )
47
      @citizen.active = true
48 49 50 51 52 53

      @account = Account.new(
        uid: @citizen.cpf,
        password: "123mudar",
        password_confirmation: "123mudar"
      )
54 55 56
      @account.save!
      @citizen.account_id = @account.id
      @citizen.save!
57 58 59

      @curitiba_city_hall = CityHall.new(
        name: "Prefeitura de Curitiba",
60
        cep: "81530110",
61 62 63 64 65 66 67 68
        neighborhood: "Test neighborhood",
        address_street: "Test street",
        address_number: "123",
        city_id: @curitiba.id,
        phone1: "1414141414",
        active: true,
        block_text: "Test block text"
      )
69 70 71 72 73 74 75 76 77
      @curitiba_city_hall.save!

      @auth_headers = @account.create_new_auth_token

      @token     = @auth_headers['access-token']
      @client_id = @auth_headers['client']
      @expiry    = @auth_headers['expiry']
    end
  end
78
end