Skip to content

Commit b1b7874

Browse files
committed
Add tests for bankrupt:cdn task
1 parent 6c405df commit b1b7874

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@ RSpec/DescribeClass:
1919
Exclude:
2020
- 'spec/bankrupt/tasks_spec.rb'
2121

22+
RSpec/MessageSpies:
23+
Enabled: false
24+
25+
RSpec/MultipleExpectations:
26+
Exclude:
27+
- 'spec/bankrupt/tasks_spec.rb'
28+
2229
RSpec/NestedGroups:
2330
Max: 6

spec/bankrupt/tasks_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
'..', 'fixtures')))
2424
stub_const('LOG', Logger.new(File::NULL))
2525

26+
stub_const('CDN_BUCKET', 'bankrupt-test')
27+
stub_const('CDN_PREFIX', 'test')
28+
stub_const('VERSION', '1.0.0')
29+
2630
# test that we rename files that have the hash in them from webpack
2731
File.rename(
2832
File.join(APP_ROOT, 'public', 'app.js'),
@@ -54,4 +58,61 @@
5458
)
5559
end
5660
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
57118
end

0 commit comments

Comments
 (0)