channel_filter.rb 1.2 KB

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