Skip to content

Commit

Permalink
Add tests for bankrupt:cdn task
Browse files Browse the repository at this point in the history
  • Loading branch information
mfinelli committed Jun 10, 2019
1 parent 6c405df commit b1b7874
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ RSpec/DescribeClass:
Exclude:
- 'spec/bankrupt/tasks_spec.rb'

RSpec/MessageSpies:
Enabled: false

RSpec/MultipleExpectations:
Exclude:
- 'spec/bankrupt/tasks_spec.rb'

RSpec/NestedGroups:
Max: 6
61 changes: 61 additions & 0 deletions spec/bankrupt/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
'..', 'fixtures')))
stub_const('LOG', Logger.new(File::NULL))

stub_const('CDN_BUCKET', 'bankrupt-test')
stub_const('CDN_PREFIX', 'test')
stub_const('VERSION', '1.0.0')

# test that we rename files that have the hash in them from webpack
File.rename(
File.join(APP_ROOT, 'public', 'app.js'),
Expand Down Expand Up @@ -54,4 +58,61 @@
)
end
end

describe 'cdn' do
before do
Rake::Task['bankrupt:manifest'].reenable
Rake::Task['bankrupt:manifest'].invoke
Rake::Task['bankrupt:cdn'].reenable
end

let(:s3_double) { Aws::S3::Client.new(stub_responses: true) }
let(:s3_response) do
class MockResponse
def etag
'ok'
end
end

MockResponse.new
end

# rubocop:disable RSpec/ExampleLength
it 'uploads files to s3' do
allow(Aws::S3::Client).to receive(:new).and_return(s3_double)

expect(s3_double).to receive(:put_object).with(
bucket: 'bankrupt-test',
key: 'test/app-a4197ed8dcb93d681801318bd25a41ed.css',
body: "body {\n color: red;\n}\n",
acl: 'private',
content_length: 23,
content_type: 'text/css',
cache_control: 'public, max-age=31536000',
server_side_encryption: 'AES256',
storage_class: 'STANDARD',
metadata: {
bankruptVersion: 'v1.0.0'
}
).and_return(s3_response)

expect(s3_double).to receive(:put_object).with(
bucket: 'bankrupt-test',
key: 'test/app-9b33890bb13bb1d8f975e9ab3902c05f.js',
body: "alert('yolo');\n",
acl: 'private',
content_length: 15,
content_type: 'application/ecmascript',
cache_control: 'public, max-age=31536000',
server_side_encryption: 'AES256',
storage_class: 'STANDARD',
metadata: {
bankruptVersion: 'v1.0.0'
}
).and_return(s3_response)

Rake::Task['bankrupt:cdn'].invoke
end
# rubocop:enable RSpec/ExampleLength
end
end

0 comments on commit b1b7874

Please sign in to comment.