Skip to content

Commit d0fd234

Browse files
authored
Fixes HealthInsurance endpoint to return custom and not custom values. (#242)
* Fixes HealthInsurance endpoint to return custom, not custom and seed health insurances when no Custom param is passed * Fixes HealthInsurance request specs to correctly test return of it endpoint with custom false
1 parent b1ce00d commit d0fd234

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

app/operations/health_insurances/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def apply_custom_filter(query)
2323
if %w[true false].include?(params[:custom])
2424
query.by_custom(custom: params[:custom], user: user)
2525
else
26-
query.where(user: user)
26+
query.where(user: [user, nil])
2727
end
2828
end
2929
end

spec/requests/api/v1/health_insurances_request_spec.rb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,108 @@
4444
end
4545
end
4646

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+
47149
context "when there are no health insurances" do
48150
before do
49151
headers = auth_token_for(create(:user))

0 commit comments

Comments
 (0)