|
1 | 1 | require "flipper/cloud/migrate" |
| 2 | +require "flipper/typecast" |
2 | 3 | require "webmock/rspec" |
3 | 4 |
|
4 | 5 | RSpec.describe Flipper::Cloud, ".migrate" do |
|
18 | 19 | ENV["FLIPPER_CLOUD_URL"] = original |
19 | 20 | end |
20 | 21 |
|
| 22 | + def decompress_request_body |
| 23 | + raw = WebMock::RequestRegistry.instance.requested_signatures.hash.keys.last.body |
| 24 | + JSON.parse(Flipper::Typecast.from_gzip(raw)) |
| 25 | + end |
| 26 | + |
21 | 27 | describe ".migrate" do |
22 | 28 | it "returns a MigrateResult with code and url on success" do |
23 | 29 | stub_request(:post, "http://localhost:5555/api/migrate") |
|
37 | 43 | Flipper::Cloud.migrate(flipper, app_name: "MyApp") |
38 | 44 |
|
39 | 45 | expect(stub).to have_been_requested |
40 | | - body = JSON.parse(WebMock::RequestRegistry.instance.requested_signatures.hash.keys.last.body) |
| 46 | + body = decompress_request_body |
41 | 47 | expect(body["metadata"]["app_name"]).to eq("MyApp") |
42 | 48 | expect(body["export"]["version"]).to eq(1) |
43 | 49 | expect(body["export"]["features"]).to have_key("search") |
44 | 50 | end |
45 | 51 |
|
| 52 | + it "sends gzip-compressed request body" do |
| 53 | + stub = stub_request(:post, "http://localhost:5555/api/migrate") |
| 54 | + .with(headers: {"content-encoding" => "gzip"}) |
| 55 | + .to_return(status: 200, body: '{"url":"http://localhost:5555/cloud/setup/abc"}') |
| 56 | + |
| 57 | + Flipper::Cloud.migrate(flipper) |
| 58 | + |
| 59 | + expect(stub).to have_been_requested |
| 60 | + body = decompress_request_body |
| 61 | + expect(body["export"]["features"]).to have_key("search") |
| 62 | + end |
| 63 | + |
46 | 64 | it "handles error responses" do |
47 | 65 | stub_request(:post, "http://localhost:5555/api/migrate") |
48 | 66 | .to_return(status: 500, body: '{"error":"Internal Server Error"}') |
|
107 | 125 | expect(stub).to have_been_requested |
108 | 126 | end |
109 | 127 |
|
110 | | - it "sends export contents as the body" do |
| 128 | + it "sends gzip-compressed export contents as the body" do |
111 | 129 | stub = stub_request(:post, "http://localhost:5555/adapter/import") |
| 130 | + .with(headers: {"content-encoding" => "gzip"}) |
112 | 131 | .to_return(status: 204, body: "") |
113 | 132 |
|
114 | 133 | Flipper::Cloud.push("test-token", flipper) |
115 | 134 |
|
116 | | - body = JSON.parse(WebMock::RequestRegistry.instance.requested_signatures.hash.keys.last.body) |
| 135 | + expect(stub).to have_been_requested |
| 136 | + body = decompress_request_body |
117 | 137 | expect(body["version"]).to eq(1) |
118 | 138 | expect(body["features"]).to have_key("search") |
119 | 139 | end |
|
0 commit comments