|
109 | 109 | count: 1) do |yielder| |
110 | 110 | yielder.call("Bundle not found\n") |
111 | 111 | 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 | + |
112 | 119 | second_request_info = mock_streaming_response(render_full_url, 200) do |yielder| |
113 | 120 | yielder.call("Hello, world!\n") |
114 | 121 | end |
|
124 | 131 | expect(first_request_info[:request].body.to_s).to include("renderingRequest=console.log") |
125 | 132 | expect(first_request_info[:request].body.to_s).not_to include("bundle") |
126 | 133 |
|
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) |
131 | 137 |
|
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") |
135 | 145 | end |
136 | 146 |
|
137 | 147 | 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| |
139 | 150 | yielder.call("Bundle not found\n") |
140 | 151 | 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| |
142 | 161 | yielder.call("Bundle still not found\n") |
143 | 162 | end |
144 | 163 |
|
|
153 | 172 | expect(first_request_info[:request].body.to_s).to include("renderingRequest=console.log") |
154 | 173 | expect(first_request_info[:request].body.to_s).not_to include("bundle") |
155 | 174 |
|
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) |
159 | 182 |
|
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") |
163 | 186 | end |
164 | 187 |
|
165 | 188 | it "raises incompatible error when server returns incompatible error" do |
|
0 commit comments