require 'test_helper'

class AssetManagerIntegrationTest
  class CreatingAnOrganisationLogo < ActiveSupport::TestCase
    setup do
      Whitehall.stubs(:use_asset_manager).returns(true)

      @filename = '960x640_jpeg.jpg'
      @organisation = FactoryGirl.build(
        :organisation,
        organisation_logo_type_id: OrganisationLogoType::CustomLogo.id,
        logo: File.open(Rails.root.join('test', 'fixtures', 'images', @filename))
      )
    end

    test 'sends the logo to Asset Manager' do
      Services.asset_manager.expects(:create_whitehall_asset).with do |args|
        args[:file].is_a?(File) &&
          args[:legacy_url_path] =~ /#{@filename}/
      end

      @organisation.save!
    end

    test 'saves the logo to the file system' do
      @organisation.save!

      assert File.exist?(@organisation.logo.path)
    end
  end
end

Add integration test for asset manager
Add integration test for asset manager

This is a happy-path test for uploading assets to asset manager. We're
currently using the Organisation model but this could be replaced with any
other model that mounts an uploader.

This should give us some confidence that we haven't broken anything as we make
changes to `AssetManagerAndQuarantinedFileStorage` and also gives us a place to
add a similar test for removing assets.
