mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-30 11:24:21 +01:00
62 lines
1.8 KiB
Ruby
62 lines
1.8 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'test_helper'
|
||
|
|
||
|
class StatisticServiceTest < ActiveSupport::TestCase
|
||
|
setup do
|
||
|
@user = User.members.without_subscription.first
|
||
|
@admin = User.with_role(:admin).first
|
||
|
login_as(@admin, scope: :user)
|
||
|
end
|
||
|
|
||
|
def test
|
||
|
machine_stats_count = Stats::Machine.all.count
|
||
|
subscription_stats_count = Stats::Subscription.all.count
|
||
|
|
||
|
# Create a reservation to generate an invoice
|
||
|
machine = Machine.find(1)
|
||
|
availability = Availability.find(19)
|
||
|
post '/api/local_payment/confirm_payment', params: {
|
||
|
customer_id: @user.id,
|
||
|
items: [
|
||
|
{
|
||
|
reservation: {
|
||
|
reservable_id: machine.id,
|
||
|
reservable_type: machine.class.name,
|
||
|
slots_attributes: [
|
||
|
{
|
||
|
start_at: availability.start_at.to_s(:iso8601),
|
||
|
end_at: (availability.start_at + 1.hour).to_s(:iso8601),
|
||
|
availability_id: availability.id
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}.to_json, headers: default_headers
|
||
|
|
||
|
# Create a subscription to generate another invoice
|
||
|
plan = Plan.find_by(group_id: @user.group.id, type: 'Plan')
|
||
|
post '/api/local_payment/confirm_payment',
|
||
|
params: {
|
||
|
customer_id: @user.id,
|
||
|
items: [
|
||
|
{
|
||
|
subscription: {
|
||
|
plan_id: plan.id
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}.to_json, headers: default_headers
|
||
|
|
||
|
# Build the stats for today, we expect the above invoices (reservation+subscription) to appear in the resulting stats
|
||
|
StatisticService.new.generate_statistic(
|
||
|
start_date: DateTime.current.beginning_of_day,
|
||
|
end_date: DateTime.current.end_of_day
|
||
|
)
|
||
|
|
||
|
assert_equal machine_stats_count + 1, Stats::Machine.all.count
|
||
|
assert_equal subscription_stats_count + 1, Stats::Subscription.all.count
|
||
|
end
|
||
|
end
|