channel_filter.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module ChannelFilterHelper
  3. # Provides a helper method to run the current class Channel::Filter.
  4. # Make sure to define type: :channel_filter in your RSpec.describe call.
  5. #
  6. # @param [Hash] mail_hash contains the parsed mail data
  7. # @param [Channel] channel contains the channel that processes this call which is usually not needed
  8. #
  9. # @example
  10. # filter({:'x-zammad-ticket-id' => 1234, ...})
  11. #
  12. # @return [nil]
  13. def filter(mail_hash, channel: {}, transaction_params: {})
  14. described_class.run(channel, mail_hash, transaction_params)
  15. end
  16. # Provides a helper method to parse a mail String and run the current class Channel::Filter.
  17. # Make sure to define type: :channel_filter in your RSpec.describe call.
  18. #
  19. # @param [String] mail_string contains the plain mail content
  20. # @param [Channel] channel contains the channel that processes this call which is usually not needed
  21. #
  22. # @example
  23. # filter_parsed('From: me@example.com...')
  24. #
  25. # @return [Hash] parsed mails Hash
  26. def filter_parsed(mail_string, channel: {})
  27. Channel::EmailParser.new.parse(mail_string).tap do |mail_hash|
  28. filter(mail_hash, channel: channel)
  29. end
  30. end
  31. end
  32. RSpec.configure do |config|
  33. config.include ChannelFilterHelper, type: :channel_filter
  34. end