dm_event 4.2.3.2 → 4.2.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,49 +28,62 @@ describe Registration, :type => :model do
28
28
  registration = create :registration, workshop: workshop, amount_paid_cents: 20000
29
29
  expect(registration.payment_owed).to eq Money.new(30000, 'EUR')
30
30
  end
31
-
31
+
32
32
  #------------------------------------------------------------------------------
33
33
  it "with partial payment with discount" do
34
34
  workshop = create :workshop_with_price
35
35
  registration = create :registration, workshop: workshop, amount_paid_cents: 20000, discount_value: 50, discount_use_percent: true
36
36
  expect(registration.payment_owed).to eq Money.new(5000, 'EUR')
37
37
  end
38
-
38
+
39
39
  #------------------------------------------------------------------------------
40
40
  it "first recurring payment" do
41
41
  workshop = create :workshop_with_recurring_price
42
42
  registration = create :registration, workshop: workshop
43
43
  expect(registration.payment_owed).to eq Money.new(10000, 'EUR')
44
44
  end
45
-
45
+
46
46
  #------------------------------------------------------------------------------
47
- it "recurring payment with partial payment" do
47
+ it "recurring payment with initial partial payment" do
48
48
  workshop = create :workshop_with_recurring_price
49
49
  registration = create :registration, workshop: workshop, amount_paid_cents: 20000
50
+ expect(registration.payment_owed).to eq Money.new(0, 'EUR')
51
+ end
52
+
53
+ #------------------------------------------------------------------------------
54
+ it "recurring payment with two payments made" do
55
+ workshop = create :workshop_with_recurring_price
56
+ registration = create :registration, workshop: workshop, created_at: 55.days.ago, amount_paid_cents: 20000
57
+ expect(registration.payment_owed).to eq Money.new(0, 'EUR')
58
+
59
+ registration = create :registration, workshop: workshop, created_at: 65.days.ago, amount_paid_cents: 20000
50
60
  expect(registration.payment_owed).to eq Money.new(10000, 'EUR')
51
61
  end
52
-
62
+
63
+ #------------------------------------------------------------------------------
64
+ it "recurring payment with no payments made" do
65
+ workshop = create :workshop_with_recurring_price
66
+ registration = create :registration, workshop: workshop, created_at: 55.days.ago
67
+ expect(registration.payment_owed).to eq Money.new(20000, 'EUR')
68
+
69
+ registration = create :registration, workshop: workshop, created_at: 65.days.ago
70
+ expect(registration.payment_owed).to eq Money.new(30000, 'EUR')
71
+ end
72
+
53
73
  #------------------------------------------------------------------------------
54
74
  it "recurring payment with mostly paid" do
55
75
  workshop = create :workshop_with_recurring_price
56
- registration = create :registration, workshop: workshop, amount_paid_cents: 45000
76
+ registration = create :registration, workshop: workshop, created_at: 130.days.ago, amount_paid_cents: 45000
57
77
  expect(registration.payment_owed).to eq Money.new(5000, 'EUR')
58
78
  end
59
-
79
+
60
80
  #------------------------------------------------------------------------------
61
81
  it "discounted recurring payment with partial payment" do
62
82
  workshop = create :workshop_with_recurring_price
63
83
  registration = create :registration, workshop: workshop, discount_value: 50, discount_use_percent: true
64
84
  expect(registration.payment_owed).to eq Money.new(10000, 'EUR')
65
85
  end
66
-
67
- #------------------------------------------------------------------------------
68
- it "pay remaining amount if within 20 EUR" do
69
- workshop = create :workshop_with_recurring_price
70
- registration = create :registration, workshop: workshop, amount_paid_cents: 39000
71
- expect(registration.payment_owed).to eq Money.new(11000, 'EUR')
72
- end
73
-
86
+
74
87
  #------------------------------------------------------------------------------
75
88
  it "pay 0 if no workshop prices" do
76
89
  workshop = create :workshop
@@ -78,6 +91,98 @@ describe Registration, :type => :model do
78
91
  expect(workshop.workshop_prices.empty?).to be true
79
92
  expect(registration.payment_owed).to eq Money.new(0, 'EUR')
80
93
  end
94
+ end
95
+
96
+ #------------------------------------------------------------------------------
97
+ it 'knows if a non-recurring payment is past due' do
98
+ workshop = create :workshop_with_price
99
+ registration = create :registration, workshop: workshop, created_at: 3.days.ago
100
+ expect(registration.past_due?).to eq false
101
+
102
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago
103
+ expect(registration.past_due?).to eq true
104
+
105
+ registration = create :registration, workshop: workshop, created_at: Time.now
106
+ expect(registration.past_due?).to eq false
81
107
 
108
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago, amount_paid_cents: 10000
109
+ expect(registration.past_due?).to eq true
110
+ end
111
+
112
+ #------------------------------------------------------------------------------
113
+ it 'knows if a recurring payment is past due' do
114
+ workshop = create :workshop_with_recurring_price
115
+ registration = create :registration, workshop: workshop, created_at: 3.days.ago
116
+ expect(registration.past_due?).to eq false
117
+
118
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago
119
+ expect(registration.past_due?).to eq true
120
+
121
+ registration = create :registration, workshop: workshop, created_at: 25.days.ago, amount_paid_cents: 10000
122
+ expect(registration.past_due?).to eq false
123
+ end
124
+
125
+ describe '#payment_reminder_due?' do
126
+ #------------------------------------------------------------------------------
127
+ it 'non-recurring payment reminder due after 7 day grace period' do
128
+ workshop = create :workshop_with_price
129
+ registration = create :registration, workshop: workshop, created_at: 6.days.ago
130
+ expect(registration.payment_reminder_due?).to eq false
131
+
132
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago
133
+ expect(registration.payment_reminder_due?).to eq true
134
+
135
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago, amount_paid_cents: 5000
136
+ expect(registration.payment_reminder_due?).to eq true
137
+ end
138
+
139
+ #------------------------------------------------------------------------------
140
+ it 'non-recurring payment reminder due after 14 days last reminder sent' do
141
+ workshop = create :workshop_with_price
142
+ registration = create :registration, workshop: workshop, created_at: 10.days.ago
143
+ registration.payment_reminder_sent_on = nil
144
+ expect(registration.payment_reminder_due?).to eq true
145
+
146
+ registration = create :registration, workshop: workshop, created_at: 30.days.ago
147
+ registration.payment_reminder_sent_on = 10.days.ago
148
+ expect(registration.payment_reminder_due?).to eq false
149
+ registration.payment_reminder_sent_on = 14.days.ago
150
+ expect(registration.payment_reminder_due?).to eq true
151
+ end
152
+
153
+ #------------------------------------------------------------------------------
154
+ it 'payment reminder respects preferred_payment_reminder_hold_until' do
155
+ workshop = create :workshop_with_price
156
+ registration = create :registration, workshop: workshop, created_at: 30.days.ago
157
+ registration.preferred_payment_reminder_hold_until = 10.days.from_now
158
+ registration.payment_reminder_sent_on = 20.days.ago
159
+ expect(registration.payment_reminder_due?).to eq false
160
+
161
+ registration.preferred_payment_reminder_hold_until = 2.days.ago
162
+ expect(registration.payment_reminder_due?).to eq true
163
+ end
164
+
165
+ #------------------------------------------------------------------------------
166
+ it 'recurring payment reminder due after 7 day grace period' do
167
+ workshop = create :workshop_with_recurring_price
168
+ registration = create :registration, workshop: workshop, created_at: 6.days.ago
169
+ expect(registration.payment_reminder_due?).to eq false
170
+
171
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago
172
+ expect(registration.payment_reminder_due?).to eq true
173
+
174
+ registration = create :registration, workshop: workshop, created_at: 8.days.ago, amount_paid_cents: 5000
175
+ expect(registration.payment_reminder_due?).to eq true
176
+ end
177
+
178
+ #------------------------------------------------------------------------------
179
+ it 'recurring payment reminder due at 3rd payment and 7 day grace period' do
180
+ workshop = create :workshop_with_recurring_price
181
+ registration = create :registration, workshop: workshop, created_at: 65.days.ago, amount_paid_cents: 20000
182
+ expect(registration.payment_reminder_due?).to eq false
183
+
184
+ registration = create :registration, workshop: workshop, created_at: 70.days.ago, amount_paid_cents: 20000
185
+ expect(registration.payment_reminder_due?).to eq true
186
+ end
82
187
  end
83
188
  end
@@ -0,0 +1,137 @@
1
+ require 'rails_helper'
2
+ DmCore.config.locales = [:en, :de]
3
+
4
+ describe WorkshopPrice, :type => :model do
5
+ setup_account
6
+
7
+ describe "workshop_prices" do
8
+
9
+ # let(:workshop) { create(:workshop) }
10
+
11
+ #------------------------------------------------------------------------------
12
+ it "creates price correctly" do
13
+ attributes = WorkshopPrice.prepare_prices('price' => '11000', 'price_currency' => 'JPY',
14
+ 'alt1_price' => '500', 'alt1_price_currency' => 'EUR',
15
+ 'alt2_price' => '30000', 'alt2_price_currency' => 'USD')
16
+ workshop_price = WorkshopPrice.new(attributes)
17
+ expect(workshop_price.price).to eq(Money.new(11000, 'JPY'))
18
+ expect(workshop_price.alt1_price).to eq(Money.new(50000, 'EUR'))
19
+ expect(workshop_price.alt2_price).to eq(Money.new(3000000, 'USD'))
20
+ end
21
+
22
+ #------------------------------------------------------------------------------
23
+ it 'can be sold out' do
24
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'))
25
+ expect(workshop_price.total_available).to eq(nil)
26
+ expect(workshop_price.sold_out?(1)).to eq false
27
+
28
+ workshop_price.total_available = 0
29
+ expect(workshop_price.sold_out?(1)).to eq true
30
+
31
+ workshop_price.total_available = 10
32
+ expect(workshop_price.sold_out?(1)).to eq false
33
+ expect(workshop_price.sold_out?(10)).to eq true
34
+ end
35
+
36
+ describe '#visible?' do
37
+ #------------------------------------------------------------------------------
38
+ it 'is has not time limits' do
39
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'))
40
+ expect(workshop_price.visible?).to eq true
41
+ end
42
+
43
+ #------------------------------------------------------------------------------
44
+ it 'should not be visible yet' do
45
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), valid_starting_on: 1.day.from_now, valid_until: 2.days.from_now)
46
+ expect(workshop_price.visible?).to eq false
47
+ end
48
+
49
+ #------------------------------------------------------------------------------
50
+ it 'should be visible within this period' do
51
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), valid_starting_on: 1.day.ago, valid_until: 2.days.from_now)
52
+ expect(workshop_price.visible?).to eq true
53
+ end
54
+
55
+ #------------------------------------------------------------------------------
56
+ it 'should not be visible after period' do
57
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), valid_starting_on: 3.days.ago, valid_until: 1.day.ago)
58
+ expect(workshop_price.visible?).to eq false
59
+ end
60
+ end
61
+
62
+ #------------------------------------------------------------------------------
63
+ it 'should format price correctly' do
64
+ workshop_price = WorkshopPrice.new(price: Money.new(534, 'USD'))
65
+ expect(workshop_price.price_formatted).to eq '$5.34'
66
+
67
+ workshop_price.price = nil
68
+ expect(workshop_price.price_formatted).to eq ''
69
+
70
+ workshop_price.price = Money.new(534, 'JPY')
71
+ expect(workshop_price.price_formatted).to eq '¥534'
72
+ end
73
+
74
+ #------------------------------------------------------------------------------
75
+ it 'has recurring payments' do
76
+ workshop_price = WorkshopPrice.new(price: Money.new(534, 'USD'))
77
+ expect(workshop_price.recurring_payments?).to eq false
78
+ workshop_price.recurring_number = 3
79
+ expect(workshop_price.recurring_payments?).to eq true
80
+ end
81
+
82
+ #------------------------------------------------------------------------------
83
+ it 'returns the amount to be paid for each payment' do
84
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'))
85
+ expect(workshop_price.payment_price).to eq Money.new(500, 'USD')
86
+
87
+ workshop_price.recurring_number = 2
88
+ expect(workshop_price.payment_price).to eq Money.new(250, 'USD')
89
+ end
90
+
91
+ #------------------------------------------------------------------------------
92
+ it 'returns list of currencies in use' do
93
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), alt1_price: Money.new(466, 'EUR'), alt2_price: Money.new(570, 'JPY'))
94
+ expect(workshop_price.currency_list).to eq [['USD', 'USD'], ['EUR', 'EUR'], ['JPY', 'JPY']]
95
+ end
96
+
97
+ #------------------------------------------------------------------------------
98
+ it 'takes an amount in one alternate currency and returns value in base currency' do
99
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), alt1_price: Money.new(466, 'EUR'), alt2_price: Money.new(570, 'JPY'))
100
+ expect(workshop_price.to_base_currency(Money.new(250, 'USD'))).to eq Money.new(250, 'USD')
101
+ expect(workshop_price.to_base_currency(Money.new(233, 'EUR'))).to eq Money.new(250, 'USD')
102
+ expect(workshop_price.to_base_currency(Money.new(285, 'JPY'))).to eq Money.new(250, 'USD')
103
+
104
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'))
105
+ expect(workshop_price.to_base_currency(Money.new(250, 'USD'))).to eq Money.new(250, 'USD')
106
+ end
107
+
108
+ #------------------------------------------------------------------------------
109
+ it 'has a one day payment schedule for non-recurring' do
110
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'))
111
+ start_day = 3.days.ago.to_date
112
+ expect(workshop_price.payment_schedule).to eq [{due_on: 0, period_payment: Money.new(500, 'USD'), total_due: Money.new(500, 'USD')}]
113
+ expect(workshop_price.payment_schedule(start_day)).to eq [{due_on: start_day, period_payment: Money.new(500, 'USD'), total_due: Money.new(500, 'USD')}]
114
+
115
+ workshop_price.recurring_number = 3
116
+ workshop_price.recurring_period = 30
117
+ expect(workshop_price.payment_schedule).to eq [
118
+ {due_on: 0, period_payment: Money.new(167, 'USD'), total_due: Money.new(167, 'USD')},
119
+ {due_on: 30, period_payment: Money.new(167, 'USD'), total_due: Money.new(334, 'USD')},
120
+ {due_on: 60, period_payment: Money.new(166, 'USD'), total_due: Money.new(500, 'USD')}]
121
+
122
+ expect(workshop_price.payment_schedule(start_day)).to eq [
123
+ {due_on: start_day, period_payment: Money.new(167, 'USD'), total_due: Money.new(167, 'USD')},
124
+ {due_on: start_day + 30.days, period_payment: Money.new(167, 'USD'), total_due: Money.new(334, 'USD')},
125
+ {due_on: start_day + 60.days, period_payment: Money.new(166, 'USD'), total_due: Money.new(500, 'USD')}]
126
+ end
127
+
128
+ #------------------------------------------------------------------------------
129
+ it 'returns the scheudled payment entry for a date' do
130
+ workshop_price = WorkshopPrice.new(price: Money.new(500, 'USD'), recurring_number: 3, recurring_period: 30)
131
+ start_day = 3.days.ago.to_date
132
+ expect(workshop_price.specific_payment_schedule(Time.now, Time.now.to_date)).to eq({due_on: Time.now.to_date, period_payment: Money.new(167, 'USD'), total_due: Money.new(167, 'USD')})
133
+ expect(workshop_price.specific_payment_schedule(start_day, 5.days.from_now)).to eq({due_on: start_day, period_payment: Money.new(167, 'USD'), total_due: Money.new(167, 'USD')})
134
+ expect(workshop_price.specific_payment_schedule(start_day, 95.days.from_now)).to eq({due_on: start_day + 60.days, period_payment: Money.new(166, 'USD'), total_due: Money.new(500, 'USD')})
135
+ end
136
+ end
137
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm_event
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3.2
4
+ version: 4.2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-10 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dm_core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.3.2
19
+ version: 4.2.3.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.3.2
26
+ version: 4.2.3.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dm_cms
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.3.2
33
+ version: 4.2.3.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.2.3.2
40
+ version: 4.2.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemerchant
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -394,6 +394,7 @@ files:
394
394
  - spec/factories/workshop_factory.rb
395
395
  - spec/factories/workshop_price_factory.rb
396
396
  - spec/models/registration_spec.rb
397
+ - spec/models/workshop_price_spec.rb
397
398
  - spec/models/workshop_spec.rb
398
399
  - spec/rails_helper.rb
399
400
  - spec/spec_helper.rb
@@ -523,6 +524,7 @@ test_files:
523
524
  - spec/factories/workshop_factory.rb
524
525
  - spec/factories/workshop_price_factory.rb
525
526
  - spec/models/registration_spec.rb
527
+ - spec/models/workshop_price_spec.rb
526
528
  - spec/models/workshop_spec.rb
527
529
  - spec/rails_helper.rb
528
530
  - spec/spec_helper.rb