|
44 | 44 | end |
45 | 45 | end |
46 | 46 |
|
| 47 | + context "when Custom param is true" do |
| 48 | + let!(:user) { create(:user) } |
| 49 | + let!(:health_insurance_custom) { create(:health_insurance, custom: true, user: user) } |
| 50 | + let(:health_insurance_not_custom) { create(:health_insurance, custom: false, user: user) } |
| 51 | + let(:health_insurance_default) { create(:health_insurance, custom: false, user: nil) } |
| 52 | + |
| 53 | + before do |
| 54 | + headers = auth_token_for(user) |
| 55 | + params = { custom: true } |
| 56 | + get "/api/v1/health_insurances", headers: headers, params: params |
| 57 | + end |
| 58 | + |
| 59 | + it "returns ok" do |
| 60 | + expect(response).to have_http_status(:ok) |
| 61 | + end |
| 62 | + |
| 63 | + it "returns health_insurances" do |
| 64 | + expect(response.parsed_body[0]).to eq( |
| 65 | + { |
| 66 | + "id" => health_insurance_custom.id, |
| 67 | + "name" => health_insurance_custom.name, |
| 68 | + "custom" => true, |
| 69 | + "user_id" => user.id |
| 70 | + } |
| 71 | + ) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context "when Custom param is false" do |
| 76 | + let!(:user) { create(:user) } |
| 77 | + let(:health_insurance_custom) { create(:health_insurance, custom: true, user: user) } |
| 78 | + let!(:health_insurance_not_custom) { create(:health_insurance, custom: false, user: user) } |
| 79 | + let!(:health_insurance_default) { create(:health_insurance, custom: false, user: nil) } |
| 80 | + |
| 81 | + before do |
| 82 | + headers = auth_token_for(user) |
| 83 | + params = { custom: false } |
| 84 | + get "/api/v1/health_insurances", headers: headers, params: params |
| 85 | + end |
| 86 | + |
| 87 | + it "returns ok" do |
| 88 | + expect(response).to have_http_status(:ok) |
| 89 | + end |
| 90 | + |
| 91 | + it "returns health_insurances" do |
| 92 | + expect(response.parsed_body).to include( |
| 93 | + { |
| 94 | + "id" => health_insurance_not_custom.id, |
| 95 | + "name" => health_insurance_not_custom.name, |
| 96 | + "custom" => false, |
| 97 | + "user_id" => user.id |
| 98 | + }, |
| 99 | + { |
| 100 | + "id" => health_insurance_default.id, |
| 101 | + "name" => health_insurance_default.name, |
| 102 | + "custom" => false, |
| 103 | + "user_id" => nil |
| 104 | + } |
| 105 | + ) |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + context "when Custom param is missing" do |
| 110 | + let!(:user) { create(:user) } |
| 111 | + let!(:health_insurance_custom) { create(:health_insurance, custom: true, user: user) } |
| 112 | + let!(:health_insurance_not_custom) { create(:health_insurance, custom: false, user: user) } |
| 113 | + let!(:health_insurance_default) { create(:health_insurance, custom: false, user: nil) } |
| 114 | + |
| 115 | + before do |
| 116 | + headers = auth_token_for(user) |
| 117 | + params = {} |
| 118 | + get "/api/v1/health_insurances", headers: headers, params: params |
| 119 | + end |
| 120 | + |
| 121 | + it "returns ok" do |
| 122 | + expect(response).to have_http_status(:ok) |
| 123 | + end |
| 124 | + |
| 125 | + it "returns health_insurances" do |
| 126 | + expect(response.parsed_body).to include( |
| 127 | + { |
| 128 | + "id" => health_insurance_custom.id, |
| 129 | + "name" => health_insurance_custom.name, |
| 130 | + "custom" => true, |
| 131 | + "user_id" => user.id |
| 132 | + }, |
| 133 | + { |
| 134 | + "id" => health_insurance_not_custom.id, |
| 135 | + "name" => health_insurance_not_custom.name, |
| 136 | + "custom" => false, |
| 137 | + "user_id" => user.id |
| 138 | + }, |
| 139 | + { |
| 140 | + "id" => health_insurance_default.id, |
| 141 | + "name" => health_insurance_default.name, |
| 142 | + "custom" => false, |
| 143 | + "user_id" => nil |
| 144 | + } |
| 145 | + ) |
| 146 | + end |
| 147 | + end |
| 148 | + |
47 | 149 | context "when there are no health insurances" do |
48 | 150 | before do |
49 | 151 | headers = auth_token_for(create(:user)) |
|
0 commit comments