Skip to content

Commit b5e78bc

Browse files
authored
test(api): refactor specs to test JSON responses via API endpoints (#228)
1 parent b911903 commit b5e78bc

File tree

5 files changed

+9
-312
lines changed

5 files changed

+9
-312
lines changed

app/services/json_serializer_service.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

spec/requests/api/units_json_inspection_history_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@
8383
expect(unit_with_inspections.inspections.first.complete?).to eq(true)
8484
end
8585

86-
it "returns correct data when called directly on model" do
87-
# Test the serializer directly
88-
json = JsonSerializerService.serialize_unit(unit.reload)
86+
it "returns correct data through the API endpoint" do
87+
# Test through the actual endpoint
88+
get "/units/#{unit.id}.json"
89+
json = JSON.parse(response.body, symbolize_names: true)
8990

9091
expect(json[:inspection_history]).to be_present
9192
expect(json[:inspection_history].length).to eq(1)

spec/requests/api/units_json_real_world_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@
6464
found_unit = Unit.find_by(id: unit.id.upcase)
6565
expect(found_unit).to eq(unit)
6666

67-
# Test serializer directly with the found unit
68-
json = JsonSerializerService.serialize_unit(found_unit)
69-
expect(json[:inspection_history]).to be_present
70-
7167
# Now test through the actual endpoint
7268
get "/units/#{unit.id}.json"
7369
response_json = JSON.parse(response.body)

spec/requests/inspections/inspections_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,14 @@ def mock_failing_update(error_messages = ["Update error"])
741741
end
742742

743743
it "serves JSON via .json format" do
744-
allow(JsonSerializerService).to receive(:serialize_inspection).and_return({id: inspection.id})
745-
746744
get "/inspections/#{inspection.id}.json"
747745
expect(response).to have_http_status(:success)
748746
expect(response.content_type).to include("application/json")
747+
748+
json = JSON.parse(response.body)
749+
expect(json).to be_present
750+
expect(json).to have_key("complete")
751+
expect(json).to have_key("urls")
749752
end
750753

751754
it "serves QR code via .png format" do

spec/services/json_serializer_service_spec.rb

Lines changed: 0 additions & 258 deletions
This file was deleted.

0 commit comments

Comments
 (0)