Skip to content

Commit 469e2e5

Browse files
Fix request_spec.rb tests to match new upload-assets endpoint behavior
Updated two failing tests to reflect the architectural change where bundles are now uploaded via a separate POST to /upload-assets instead of being included in the render request form data: - "reuploads bundles when bundle not found on renderer" - "raises duplicate bundle upload error when server asks for bundle twice" Both tests now properly mock the /upload-assets endpoint and verify that bundles are uploaded separately from render requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1ede3e2 commit 469e2e5

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

react_on_rails_pro/spec/react_on_rails_pro/request_spec.rb

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@
109109
count: 1) do |yielder|
110110
yielder.call("Bundle not found\n")
111111
end
112+
113+
# Mock the /upload-assets endpoint that gets called when send_bundle is true
114+
upload_assets_url = "#{renderer_url}/upload-assets"
115+
upload_request_info = mock_streaming_response(upload_assets_url, 200, count: 1) do |yielder|
116+
yielder.call("Assets uploaded\n")
117+
end
118+
112119
second_request_info = mock_streaming_response(render_full_url, 200) do |yielder|
113120
yielder.call("Hello, world!\n")
114121
end
@@ -124,21 +131,33 @@
124131
expect(first_request_info[:request].body.to_s).to include("renderingRequest=console.log")
125132
expect(first_request_info[:request].body.to_s).not_to include("bundle")
126133

127-
# Second request should have a bundle
128-
# It's a multipart/form-data request, so we can access the form directly
129-
second_request_body = second_request_info[:request].body.instance_variable_get(:@body)
130-
second_request_form = second_request_body.instance_variable_get(:@form)
134+
# The bundle should be sent via the /upload-assets endpoint
135+
upload_request_body = upload_request_info[:request].body.instance_variable_get(:@body)
136+
upload_request_form = upload_request_body.instance_variable_get(:@form)
131137

132-
expect(second_request_form).to have_key("bundle_server_bundle.js")
133-
expect(second_request_form["bundle_server_bundle.js"][:body]).to be_a(FakeFS::Pathname)
134-
expect(second_request_form["bundle_server_bundle.js"][:body].to_s).to eq(server_bundle_path)
138+
expect(upload_request_form).to have_key("bundle_server_bundle.js")
139+
expect(upload_request_form["bundle_server_bundle.js"][:body]).to be_a(FakeFS::Pathname)
140+
expect(upload_request_form["bundle_server_bundle.js"][:body].to_s).to eq(server_bundle_path)
141+
142+
# Second render request should also not have a bundle
143+
expect(second_request_info[:request].body.to_s).to include("renderingRequest=console.log")
144+
expect(second_request_info[:request].body.to_s).not_to include("bundle")
135145
end
136146

137147
it "raises duplicate bundle upload error when server asks for bundle twice" do
138-
first_request_info = mock_streaming_response(render_full_url, ReactOnRailsPro::STATUS_SEND_BUNDLE) do |yielder|
148+
first_request_info = mock_streaming_response(render_full_url, ReactOnRailsPro::STATUS_SEND_BUNDLE,
149+
count: 1) do |yielder|
139150
yielder.call("Bundle not found\n")
140151
end
141-
second_request_info = mock_streaming_response(render_full_url, ReactOnRailsPro::STATUS_SEND_BUNDLE) do |yielder|
152+
153+
# Mock the /upload-assets endpoint that gets called when send_bundle is true
154+
upload_assets_url = "#{renderer_url}/upload-assets"
155+
upload_request_info = mock_streaming_response(upload_assets_url, 200, count: 1) do |yielder|
156+
yielder.call("Assets uploaded\n")
157+
end
158+
159+
second_request_info = mock_streaming_response(render_full_url, ReactOnRailsPro::STATUS_SEND_BUNDLE,
160+
count: 1) do |yielder|
142161
yielder.call("Bundle still not found\n")
143162
end
144163

@@ -153,13 +172,17 @@
153172
expect(first_request_info[:request].body.to_s).to include("renderingRequest=console.log")
154173
expect(first_request_info[:request].body.to_s).not_to include("bundle")
155174

156-
# Second request should have a bundle
157-
second_request_body = second_request_info[:request].body.instance_variable_get(:@body)
158-
second_request_form = second_request_body.instance_variable_get(:@form)
175+
# The bundle should be sent via the /upload-assets endpoint
176+
upload_request_body = upload_request_info[:request].body.instance_variable_get(:@body)
177+
upload_request_form = upload_request_body.instance_variable_get(:@form)
178+
179+
expect(upload_request_form).to have_key("bundle_server_bundle.js")
180+
expect(upload_request_form["bundle_server_bundle.js"][:body]).to be_a(FakeFS::Pathname)
181+
expect(upload_request_form["bundle_server_bundle.js"][:body].to_s).to eq(server_bundle_path)
159182

160-
expect(second_request_form).to have_key("bundle_server_bundle.js")
161-
expect(second_request_form["bundle_server_bundle.js"][:body]).to be_a(FakeFS::Pathname)
162-
expect(second_request_form["bundle_server_bundle.js"][:body].to_s).to eq(server_bundle_path)
183+
# Second render request should also not have a bundle
184+
expect(second_request_info[:request].body.to_s).to include("renderingRequest=console.log")
185+
expect(second_request_info[:request].body.to_s).not_to include("bundle")
163186
end
164187

165188
it "raises incompatible error when server returns incompatible error" do

0 commit comments

Comments
 (0)