solicitations_controller_test.rb 2.53 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 SolicitationsControllerTest < ActionDispatch::IntegrationTest
  describe "Token access" do
    before do
21 22 23 24 25
      @parana = State.new(
        abbreviation: "PR",
        ibge_code: "41",
        name: "Paraná"
      )
26 27
      @parana.save!

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

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

      @account = Account.new(
        uid: @citizen.cpf,
        password: "123mudar",
        password_confirmation: "123mudar"
      )
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
      @account.save!
      @citizen.account_id = @account.id
      @citizen.save!

      @auth_headers = @account.create_new_auth_token

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

    describe "Successful request to create solicitation" do
      before do
        @number_of_solicitations = Solicitation.count

        post '/v1/solicitations', params: {solicitation: {
          city_id: @curitiba.id,
          name: "Teste",
          cpf: "10845922904",
73
          cep: "89218230",
74 75 76
          email: "teste@teste.com",
          phone: "12121212",
          sent: true,
77
        }, permission: "citizen"}, headers: @auth_headers
78 79 80 81 82 83 84 85 86 87

        @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
    end
  end
end