summaryrefslogtreecommitdiffhomepage
path: root/test/util/tc_mime_type_utils.rb
blob: f990e8e239e90c562a67c5f8bfd18b5d2f1f0f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

require 'tc_helper'

class TestMimeTypeUtils < Test::Unit::TestCase
  def setup
    stub_request(:get, 'https://example.com/sample-image.png')
      .to_return(body: File.new('examples/sample.png'), status: 200)

    @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
    @test_img_url = "https://example.com/sample-image.png"
  end

  def teardown; end

  def test_mime_type_utils
    assert_equal('image/jpeg', Axlsx::MimeTypeUtils.get_mime_type(@test_img))
    assert_equal('image/png', Axlsx::MimeTypeUtils.get_mime_type_from_uri(@test_img_url))
  end

  def test_escape_uri
    assert_raise(URI::InvalidURIError) { Axlsx::MimeTypeUtils.get_mime_type_from_uri('| ls') }
  end
end