|
23 | 23 | '..', 'fixtures'))) |
24 | 24 | stub_const('LOG', Logger.new(File::NULL)) |
25 | 25 |
|
| 26 | + stub_const('CDN_BUCKET', 'bankrupt-test') |
| 27 | + stub_const('CDN_PREFIX', 'test') |
| 28 | + stub_const('VERSION', '1.0.0') |
| 29 | + |
26 | 30 | # test that we rename files that have the hash in them from webpack |
27 | 31 | File.rename( |
28 | 32 | File.join(APP_ROOT, 'public', 'app.js'), |
|
54 | 58 | ) |
55 | 59 | end |
56 | 60 | end |
| 61 | + |
| 62 | + describe 'cdn' do |
| 63 | + before do |
| 64 | + Rake::Task['bankrupt:manifest'].reenable |
| 65 | + Rake::Task['bankrupt:manifest'].invoke |
| 66 | + Rake::Task['bankrupt:cdn'].reenable |
| 67 | + end |
| 68 | + |
| 69 | + let(:s3_double) { Aws::S3::Client.new(stub_responses: true) } |
| 70 | + let(:s3_response) do |
| 71 | + class MockResponse |
| 72 | + def etag |
| 73 | + 'ok' |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + MockResponse.new |
| 78 | + end |
| 79 | + |
| 80 | + # rubocop:disable RSpec/ExampleLength |
| 81 | + it 'uploads files to s3' do |
| 82 | + allow(Aws::S3::Client).to receive(:new).and_return(s3_double) |
| 83 | + |
| 84 | + expect(s3_double).to receive(:put_object).with( |
| 85 | + bucket: 'bankrupt-test', |
| 86 | + key: 'test/app-a4197ed8dcb93d681801318bd25a41ed.css', |
| 87 | + body: "body {\n color: red;\n}\n", |
| 88 | + acl: 'private', |
| 89 | + content_length: 23, |
| 90 | + content_type: 'text/css', |
| 91 | + cache_control: 'public, max-age=31536000', |
| 92 | + server_side_encryption: 'AES256', |
| 93 | + storage_class: 'STANDARD', |
| 94 | + metadata: { |
| 95 | + bankruptVersion: 'v1.0.0' |
| 96 | + } |
| 97 | + ).and_return(s3_response) |
| 98 | + |
| 99 | + expect(s3_double).to receive(:put_object).with( |
| 100 | + bucket: 'bankrupt-test', |
| 101 | + key: 'test/app-9b33890bb13bb1d8f975e9ab3902c05f.js', |
| 102 | + body: "alert('yolo');\n", |
| 103 | + acl: 'private', |
| 104 | + content_length: 15, |
| 105 | + content_type: 'application/ecmascript', |
| 106 | + cache_control: 'public, max-age=31536000', |
| 107 | + server_side_encryption: 'AES256', |
| 108 | + storage_class: 'STANDARD', |
| 109 | + metadata: { |
| 110 | + bankruptVersion: 'v1.0.0' |
| 111 | + } |
| 112 | + ).and_return(s3_response) |
| 113 | + |
| 114 | + Rake::Task['bankrupt:cdn'].invoke |
| 115 | + end |
| 116 | + # rubocop:enable RSpec/ExampleLength |
| 117 | + end |
57 | 118 | end |
0 commit comments