# frozen_string_literal: true

require File.join(File.expand_path('../../../../test', __dir__), 'test_helper')

module QualityApp
  class TestMrlChemicalsRequirementPermission < Minitest::Test
    include Crossbeams::Responses
    include MrlChemicalsRequirementFactory

    def entity(attrs = {})
      base_attrs = {
        id: 1,
        chemical_id: 1,
        mrl_requirement_id: 1,
        percentage_of_eu_level: 1.0,
        maximum_residue_level: 1.0,
        active: true
      }
      QualityApp::MrlChemicalsRequirement.new(base_attrs.merge(attrs))
    end

    def test_create
      res = QualityApp::TaskPermissionCheck::MrlChemicalsRequirement.call(:create)
      assert res.success, 'Should always be able to create a mrl_chemicals_requirement'
    end

    def test_edit
      QualityApp::MrlChemicalsRequirementRepo.any_instance.stubs(:find_mrl_chemicals_requirement).returns(entity)
      res = QualityApp::TaskPermissionCheck::MrlChemicalsRequirement.call(:edit, 1)
      assert res.success, 'Should be able to edit a mrl_chemicals_requirement'
    end

    def test_delete
      QualityApp::MrlChemicalsRequirementRepo.any_instance.stubs(:find_mrl_chemicals_requirement).returns(entity)
      res = QualityApp::TaskPermissionCheck::MrlChemicalsRequirement.call(:delete, 1)
      assert res.success, 'Should be able to delete a mrl_chemicals_requirement'
    end
  end
end
