-
Notifications
You must be signed in to change notification settings - Fork 71
/
product_purchase_spec.rb
110 lines (91 loc) · 2.68 KB
/
product_purchase_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require "spec_helper"
describe CandyCheck::PlayStore::ProductPurchases::ProductPurchase do
subject { CandyCheck::PlayStore::ProductPurchases::ProductPurchase.new(fake_product_purchase) }
describe "valid and non-consumed product" do
let(:fake_product_purchase) do
FakeProductPurchase.new(
consumption_state: 0,
developer_payload: "payload that gets stored and returned",
kind: "androidpublisher#productPurchase",
order_id: "ABC123",
purchase_state: 0,
purchase_time_millis: 1421676237413,
)
end
it "is valid?" do
_(subject.valid?).must_be_true
end
it "is not consumed" do
_(subject.consumed?).must_be_false
end
it "returns the purchase_state" do
_(subject.purchase_state).must_equal 0
end
it "returns the consumption_state" do
_(subject.consumption_state).must_equal 0
end
it "returns the developer_payload" do
_(subject.developer_payload).must_equal "payload that gets stored and returned"
end
it "returns the kind" do
_(subject.kind).must_equal "androidpublisher#productPurchase"
end
it "returns the purchase_time_millis" do
_(subject.purchase_time_millis).must_equal 1_421_676_237_413
end
it "returns the purchased_at" do
expected = DateTime.new(2015, 1, 19, 14, 3, 57)
_(subject.purchased_at).must_equal expected
end
end
describe "valid and consumed product" do
let(:fake_product_purchase) do
FakeProductPurchase.new(
consumption_state: 1,
developer_payload: "payload that gets stored and returned",
kind: "androidpublisher#productPurchase",
order_id: "ABC123",
purchase_state: 0,
purchase_time_millis: 1421676237413,
)
end
it "is valid?" do
_(subject.valid?).must_be_true
end
it "is consumed?" do
_(subject.consumed?).must_be_true
end
end
describe "non-valid product" do
let(:fake_product_purchase) do
FakeProductPurchase.new(
consumption_state: 0,
developer_payload: "payload that gets stored and returned",
kind: "androidpublisher#productPurchase",
order_id: "ABC123",
purchase_state: 1,
purchase_time_millis: 1421676237413,
)
end
it "is valid?" do
_(subject.valid?).must_be_false
end
end
private
class FakeProductPurchase
FIELDS = [
:consumption_state,
:developer_payload,
:kind,
:order_id,
:purchase_state,
:purchase_time_millis,
].freeze
attr_accessor(*FIELDS)
def initialize(hash)
FIELDS.each do |key|
self.public_send("#{key}=", hash[key])
end
end
end
end