-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' for release 5.4.25
- Loading branch information
Showing
11 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the '{}' from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
prepaid_pack_1: | ||
id: 1 | ||
priceable_type: Machine | ||
priceable_id: 1 | ||
group_id: 1 | ||
amount: 1000 | ||
minutes: 600 | ||
validity_interval: month | ||
validity_count: 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
statistic_profile_prepaid_pack_1: | ||
prepaid_pack_id: 1 | ||
statistic_profile_id: 10 | ||
minutes_used: 600 | ||
expires_at: <%= 11.month.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> | ||
|
||
statistic_profile_prepaid_pack_2: | ||
prepaid_pack_id: 1 | ||
statistic_profile_id: 10 | ||
minutes_used: 0 | ||
expires_at: <%= 12.month.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> |
76 changes: 76 additions & 0 deletions
76
test/integration/reservations/pay_with_prepaid_pack_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Reservations; end | ||
|
||
class Reservations::PayWithPrepaidPackTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@acamus = User.find_by(username: 'acamus') | ||
end | ||
|
||
test 'user reserves a machine and pay by prepaid pack with success' do | ||
login_as(@acamus, scope: :user) | ||
|
||
machine = Machine.first | ||
availability = machine.availabilities.first | ||
|
||
reservations_count = Reservation.count | ||
invoice_count = Invoice.count | ||
invoice_items_count = InvoiceItem.count | ||
|
||
VCR.use_cassette('reservations_create_for_machine_with_prepaid_pack_success') do | ||
post '/api/local_payment/confirm_payment', | ||
params: { | ||
items: [ | ||
{ | ||
reservation: { | ||
reservable_id: machine.id, | ||
reservable_type: machine.class.name, | ||
slots_reservations_attributes: [ | ||
{ | ||
slot_id: availability.slots.first.id | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}.to_json, headers: default_headers | ||
end | ||
|
||
# general assertions | ||
assert_equal 201, response.status | ||
assert_equal reservations_count + 1, Reservation.count | ||
assert_equal invoice_count + 1, Invoice.count | ||
assert_equal invoice_items_count + 1, InvoiceItem.count | ||
|
||
# reservation assertions | ||
reservation = Reservation.last | ||
|
||
assert reservation.original_invoice | ||
assert_equal 1, reservation.original_invoice.invoice_items.count | ||
|
||
# invoice_items assertions | ||
invoice_item = InvoiceItem.last | ||
|
||
assert_equal invoice_item.amount, 0 | ||
assert invoice_item.check_footprint | ||
|
||
# invoice assertions | ||
item = InvoiceItem.find_by(object: reservation) | ||
invoice = item.invoice | ||
assert_invoice_pdf invoice | ||
assert_not_nil invoice.debug_footprint | ||
|
||
assert invoice.payment_gateway_object.blank? | ||
assert_not invoice.total.blank? | ||
assert invoice.check_footprint | ||
|
||
# notification | ||
assert_not_empty Notification.where(attached_object: reservation) | ||
|
||
# prepaid pack | ||
minutes_available = PrepaidPackService.minutes_available(@acamus, machine) | ||
assert_equal minutes_available, 540 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'test_helper' | ||
|
||
class StatisticProfilePrepaidPackTest < ActiveSupport::TestCase | ||
test 'coupon have a expries date' do | ||
prepaid_pack = PrepaidPack.first | ||
user = User.find_by(username: 'jdupond') | ||
p = StatisticProfilePrepaidPack.create!(prepaid_pack: prepaid_pack, statistic_profile: user.statistic_profile) | ||
expires_at = DateTime.current + 12.months | ||
assert p.expires_at.strftime('%Y-%m-%d'), expires_at.strftime('%Y-%m-%d') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class PrepaidPackServiceTest < ActiveSupport::TestCase | ||
setup do | ||
@acamus = User.find_by(username: 'acamus') | ||
@machine = Machine.first | ||
end | ||
|
||
test 'get user packs' do | ||
packs = PrepaidPackService.user_packs(@acamus, @machine) | ||
p = StatisticProfilePrepaidPack.where(statistic_profile_id: @acamus.statistic_profile.id) | ||
assert_not_empty packs | ||
assert_equal packs.length, 1 | ||
assert_equal p.length, 2 | ||
assert_equal packs.first.id, p.last.id | ||
end | ||
|
||
test 'total number of prepaid minutes available' do | ||
minutes_available = PrepaidPackService.minutes_available(@acamus, @machine) | ||
assert_equal minutes_available, 600 | ||
end | ||
|
||
test 'update user pack minutes' do | ||
availabilities_service = Availabilities::AvailabilitiesService.new(@acamus) | ||
|
||
slots = availabilities_service.machines([@machine], @acamus, { start: DateTime.now, end: 1.day.from_now }) | ||
reservation = Reservation.create( | ||
reservable_id: @machine.id, | ||
reservable_type: Machine.name, | ||
slots: [slots[0], slots[1]], | ||
statistic_profile_id: @acamus.statistic_profile.id | ||
) | ||
|
||
PrepaidPackService.update_user_minutes(@acamus, reservation) | ||
minutes_available = PrepaidPackService.minutes_available(@acamus, @machine) | ||
assert_equal minutes_available, 480 | ||
end | ||
end |