Skip to content

Commit

Permalink
plugs template, report_builder and data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ottohenrique committed Jul 5, 2021
1 parent d4e89aa commit b681e4a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
6 changes: 5 additions & 1 deletion spec/lib/report_builder_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


let(:orders) { [order1, order2, order3] }
let(:client) { OpenStruct.new(first_name: "John", last_name: "Doe", orders: orders) }
let(:client) { OpenStruct.new(first_name: "John", last_name: "Doe", email: "johndoe@example.com", orders: orders) }

subject { ReportBuilderClient.new(client) }

Expand All @@ -64,4 +64,8 @@
context "#last_order_amount" do
it { expect(subject.last_order_amount).to eq(30.0) }
end

context "#email" do
it { expect(subject.email).to eq("johndoe@example.com") }
end
end
18 changes: 18 additions & 0 deletions spec/lib/report_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'
require 'ostruct'

require_relative './../../src/lib/report_builder.rb'

describe ReportBuilder do
let(:subscribers) { [OpenStruct.new(first_name: "John", last_name: "Doe", orders: [])]}
let(:template) { TemplateParser.new("{{ subscriber_full_name }} {{ last_order_amount }}")}
let(:store) { OpenStruct.new(name: "A Big Store", subscribers: subscribers) }

let(:recipients) { ["johndoe@example.com"] }

subject { ReportBuilderStore.new(store, template, recipients) }

context "#build" do
it { fail }
end
end
1 change: 1 addition & 0 deletions spec/mail_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative './../src/mail_app.rb'

describe MailApp do

context '#send_mail' do
let(:html_template) do
<<~TEMPLATE
Expand Down
10 changes: 10 additions & 0 deletions src/lib/report_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ReportBuilder
def initialize(store, template, recipients)
@store = ReportBuilderStore.new(store)
@template = template
@recipients = recipients
end

def build
end
end
4 changes: 4 additions & 0 deletions src/lib/report_builder_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def full_name
@subscriber.first_name + " " + @subscriber.last_name
end

def email
@subscriber.email
end

def last_order_amount
@subscriber.orders.last.total
end
Expand Down
15 changes: 10 additions & 5 deletions src/mail_app.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require_relative './lib/template_parser.rb'
require_relative './lib/report_builder.rb'

class MailApp
def self.send_mail(campaing, recipients_list)
recipients = recipients_list.reduce({}) do |list, recipient|
list[recipient] = {}
list
end
template = TemplateParser.new(campaing.html)
report = ReportBuilder.new(campaign.store, template, recipients_list)

{recipient_variables: recipients, html: campaing.html, sender: 'from@example.com'}
{
sender: 'from@example.com',
html: campaing.html,
recipient_variables: report.build
}
end
end

0 comments on commit b681e4a

Please sign in to comment.