1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

test statistics generation

This commit is contained in:
Sylvain 2022-01-18 15:34:21 +01:00
parent e4a0798b8a
commit 5b69c0f46f
4 changed files with 77 additions and 0 deletions

View File

@ -1,5 +1,6 @@
# Changelog Fab-manager
- Add a test for statistics generation
- Fix a bug: statistics not built for instances with plans created before v4.3.3
- Fix a bug: when requesting to send the sso migration code, the email was case-sensitive.
- Fix a bug: the adminsys email was case-sensitive.

View File

@ -179,3 +179,13 @@ availability_18:
updated_at: 2017-02-15 15:53:35.154433000 Z
nb_total_places: 5
destroying: false
availability_19:
id: 19
start_at: <%= 1.day.from_now.utc.change({hour: 8}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= 1.day.from_now.utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2017-02-15 15:53:35.154433000 Z
updated_at: 2017-02-15 15:53:35.154433000 Z
nb_total_places:
destroying: false

View File

@ -103,3 +103,8 @@ machines_availability_21:
id: 21
machine_id: 2
availability_id: 16
machines_availability_22:
id: 22
machine_id: 1
availability_id: 19

View File

@ -0,0 +1,61 @@
# 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