Skip to content

Commit

Permalink
assorted fixes 7
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Oct 19, 2023
1 parent d51bb75 commit c1eef4b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/models/email_attachment/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def cache_attachment(attachment, email:)
email_attachment.is_inline = attachment.is_inline
email_attachment.content_id = attachment.content_id
email_attachment.file.attach(
io: StringIO.new(attachment.content_bytes),
io: StringIO.new(Base64.decode64(attachment.content_bytes)),
filename: attachment.name,
content_type: attachment.content_type,
)
Expand Down
6 changes: 2 additions & 4 deletions lib/tasks/case_management.rake
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ namespace :case_management do

desc "Populate shared inbox emails"
task :seed_shared_inbox_emails, [:messages_after] => :environment do |_t, args|
include Support::Messages::Outlook

messages_after = Time.zone.parse(args.fetch(:emails_since_date, "01/10/2021 00:00:00"))
SynchroniseMailFolder.call(MailFolder.new(messages_after:, folder: :inbox))
SynchroniseMailFolder.call(MailFolder.new(messages_after:, folder: :sent_items))
Email.cache_messages_in_folder("Inbox", messages_after:)
Email.cache_messages_in_folder("SentItems", messages_after:)
end

desc "Populate frameworks"
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/email_attachments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FactoryBot.define do
factory :email_attachment, class: "EmailAttachment" do
file { Rack::Test::UploadedFile.new(Rails.root.join("spec/support/assets/support/email_attachments/attachment.txt"), "text/plain") }

association :email, factory: :support_email

trait :without_file do
file { nil }
end
end
end
28 changes: 28 additions & 0 deletions spec/factories/emails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FactoryBot.define do
factory :email, class: "Email" do
subject { "Support Case #001" }

body { "<html><head></head><body><h1>My support request</h1><p>Please update my case</p></body></html>" }
sender { { address: "[email protected]", name: "Sender 1" } }
recipients { [{ address: "[email protected]", name: "Recipient 1" }] }
to_recipients { [{ address: "[email protected]", name: "To Recipient" }] }
cc_recipients { [{ address: "[email protected]", name: "CC Recipient" }] }
bcc_recipients { [{ address: "[email protected]", name: "BCC Recipient" }] }
outlook_conversation_id { "MyString" }
case_id { "" }
sent_at { "2021-12-15 11:51:12" }
outlook_received_at { "2021-12-15 11:51:12" }
outlook_read_at { "2021-12-15 11:51:12" }
is_read { false }
template { nil }
association :case, factory: :support_case

trait :inbox do
folder { :inbox }
end

trait :sent_items do
folder { :sent_items }
end
end
end
26 changes: 1 addition & 25 deletions spec/factories/support/email.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
FactoryBot.define do
factory :support_email, class: "Support::Email" do
subject { "Support Case #001" }

body { "<html><head></head><body><h1>My support request</h1><p>Please update my case</p></body></html>" }
sender { { address: "[email protected]", name: "Sender 1" } }
recipients { [{ address: "[email protected]", name: "Recipient 1" }] }
to_recipients { [{ address: "[email protected]", name: "To Recipient" }] }
cc_recipients { [{ address: "[email protected]", name: "CC Recipient" }] }
bcc_recipients { [{ address: "[email protected]", name: "BCC Recipient" }] }
outlook_conversation_id { "MyString" }
case_id { "" }
sent_at { "2021-12-15 11:51:12" }
outlook_received_at { "2021-12-15 11:51:12" }
outlook_read_at { "2021-12-15 11:51:12" }
is_read { false }
template { nil }
association :case, factory: :support_case

trait :inbox do
folder { :inbox }
end

trait :sent_items do
folder { :sent_items }
end
factory :support_email, parent: :email do
end
end
9 changes: 1 addition & 8 deletions spec/factories/support/email_attachments.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
FactoryBot.define do
factory :support_email_attachment, class: "Support::EmailAttachment" do
file { Rack::Test::UploadedFile.new(Rails.root.join("spec/support/assets/support/email_attachments/attachment.txt"), "text/plain") }

association :email, factory: :support_email

trait :without_file do
file { nil }
end
factory :support_email_attachment, parent: :email_attachment do
end
end

0 comments on commit c1eef4b

Please sign in to comment.