Skip to content

Commit f11746e

Browse files
committed
Add attributes and specs for customer presenter
1 parent 6435941 commit f11746e

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

app/models/invoice/data_presenter/customer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
class Invoice
44
class DataPresenter
55
class Customer < Invoice::DataPresenter::Base
6-
attributes :code, :email
6+
attributes :code, :email, :customer_type, :enterprise_name, :enterprise_acn,
7+
:enterprise_charges_sales_tax
78
end
89
end
910
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Invoice::DataPresenter::Customer do
4+
subject(:presenter) { described_class.new(data) }
5+
6+
let(:data) do
7+
{
8+
code: "C001",
9+
email: "customer@example.com",
10+
customer_type: "individual",
11+
enterprise_name: "Da Box",
12+
enterprise_acn: "123456789",
13+
enterprise_charges_sales_tax: true
14+
}
15+
end
16+
17+
it { is_expected.to be_a(Invoice::DataPresenter::Base) }
18+
19+
describe "attribute readers" do
20+
it "exposes code" do
21+
expect(presenter.code).to eq("C001")
22+
end
23+
24+
it "exposes email" do
25+
expect(presenter.email).to eq("customer@example.com")
26+
end
27+
28+
it "exposes customer_type" do
29+
expect(presenter.customer_type).to eq("individual")
30+
end
31+
32+
it "exposes enterprise_name" do
33+
expect(presenter.enterprise_name).to eq("Da Box")
34+
end
35+
36+
it "exposes enterprise_acn" do
37+
expect(presenter.enterprise_acn).to eq("123456789")
38+
end
39+
40+
it "exposes enterprise_charges_sales_tax" do
41+
expect(presenter.enterprise_charges_sales_tax).to be(true)
42+
end
43+
end
44+
45+
context "when data is nil" do
46+
let(:data) { nil }
47+
48+
it "returns nil for all attributes" do
49+
expect(presenter.code).to be_nil
50+
expect(presenter.email).to be_nil
51+
expect(presenter.customer_type).to be_nil
52+
expect(presenter.enterprise_name).to be_nil
53+
expect(presenter.enterprise_acn).to be_nil
54+
expect(presenter.enterprise_charges_sales_tax).to be_nil
55+
end
56+
end
57+
58+
context "when attributes are missing from data" do
59+
let(:data) { {} }
60+
61+
it "returns nil for missing attributes" do
62+
expect(presenter.code).to be_nil
63+
expect(presenter.enterprise_name).to be_nil
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)