Sha256: b3b549102eab4aa5e90a7707684ea416df292a8ff441508e1d27818d60712156

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'
require 'digest/sha1'

class ReportsTest < ActionDispatch::IntegrationTest

  access_tests_for :index,
                   url_helper: 'barkest_core_test_report_path',
                   allow_anon: false,
                   allow_any_user: false,
                   allow_admin: true

  def setup
    @admin = users(:admin)
  end

  # CSV is easy, it's content won't change.
  test 'should get csv' do
    log_in_as @admin
    get barkest_core_test_report_path(format: :csv)

    assert_equal 'text/csv', response.content_type.to_s

    valid_csv = "Code,Name,Email,Date of Birth,Hire Date,Pay Rate,Hours\nSMIJOH,John Smith,j.smith@example.com,01/01/1980,05/01/2010,15.5,2260\n"
    assert_equal valid_csv, response.body
  end

  # PDF is a bit more complex, but we try our damnedest to make it consistent, even going so far as forging the creation_date.
  # The SHA1 should match up.
  test 'should get pdf' do
    log_in_as @admin
    get barkest_core_test_report_path(format: :pdf)

    assert_equal 'application/pdf', response.content_type.to_s

    valid_sha1 = '5aba48603c5e93674e67022b38524dd5d1a953c4'
    computed_sha1 = Digest::SHA1.hexdigest(response.body)
    assert_equal valid_sha1, computed_sha1
  end

  # XLSX is the same as PDF as far as testing goes.
  test 'should get xlsx' do
    log_in_as @admin
    get barkest_core_test_report_path(format: :xlsx)

    assert_equal 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', response.content_type.to_s

    valid_sha1 = 'e6292ab2ea16a209ccd985a00d823d15c6c6a947'
    computed_sha1 = Digest::SHA1.hexdigest(response.body)
    assert_equal valid_sha1, computed_sha1
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barkest_core-1.5.4.0 test/integration/reports_test.rb
barkest_core-1.5.3.0 test/integration/reports_test.rb