|
4 | 4 | let(:test_data_dir) { File.join(File.dirname(__FILE__), 'test-data', 'app_size_metrics') }
|
5 | 5 | let(:mocked_endpoint) { 'https://localhost/api/metrics' }
|
6 | 6 | let(:mocked_token) { 'token/1' }
|
7 |
| - |
8 |
| - # Utility method to turn a minified JSON into a pretty-formatted JSON (without the GZIP fake prefix if any) |
9 |
| - # To make any test failure and diff easier to debug |
10 |
| - def pretty_json(json_string) |
11 |
| - JSON.pretty_generate(JSON.parse(json_string)) |
12 |
| - end |
| 7 | + let(:fake_ipa_size) { 1337 } # The value used in the `app-thinning.plist` and `app-size-metrics-payload.json` fixtures |
13 | 8 |
|
14 | 9 | def test_app_size_action(fake_ipa_size:, expected_json:, **other_action_args)
|
15 | 10 | in_tmp_dir do |tmp_dir|
|
@@ -43,9 +38,9 @@ def test_app_size_action(fake_ipa_size:, expected_json:, **other_action_args)
|
43 | 38 | expect do
|
44 | 39 | last_received_body_uncompressed = Zlib.gunzip(last_received_body)
|
45 | 40 | end.not_to raise_error, 'Payload was not valid GZipped data'
|
46 |
| - # Compare the payloads as pretty-formatted JSON, to make the diff in test failures more readable if one happen |
47 |
| - expect(pretty_json(last_received_body_uncompressed)).to eq(pretty_json(expected_json)), 'Decompressed JSON payload was not as expected' |
48 |
| - # Compare the payloads as raw uncompressed data as a final check |
| 41 | + # Compare the JSON payloads as parsed objects for nicer diffs |
| 42 | + expect(JSON.parse(last_received_body_uncompressed)).to eq(JSON.parse(expected_json)), 'Decompressed JSON payload was not as expected' |
| 43 | + # Compare the payloads as uncompressed, raw string as a final check |
49 | 44 | expect(last_received_body_uncompressed).to eq(expected_json)
|
50 | 45 | end
|
51 | 46 | end
|
@@ -78,7 +73,7 @@ def test_app_size_action(fake_ipa_size:, expected_json:, **other_action_args)
|
78 | 73 | expected_json = JSON.parse(File.read(expected_fixture)).to_json
|
79 | 74 |
|
80 | 75 | test_app_size_action(
|
81 |
| - fake_ipa_size: 1337, |
| 76 | + fake_ipa_size: fake_ipa_size, |
82 | 77 | expected_json: expected_json,
|
83 | 78 | app_thinning_plist_path: app_thinning_plist_path,
|
84 | 79 | app_name: 'wordpress',
|
|
0 commit comments