2022-10-11 15:14:53 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class StoreStatisticServiceTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@order = Order.find(15)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'build stats about orders' do
|
|
|
|
# Build the stats for the last 3 days, we expect the above invoices (reservations+subscription) to appear in the resulting stats
|
|
|
|
::Statistics::BuilderService.generate_statistic({ start_date: DateTime.current.beginning_of_day,
|
|
|
|
end_date: DateTime.current.end_of_day })
|
|
|
|
|
2022-10-11 17:23:45 +02:00
|
|
|
Stats::Order.refresh_index!
|
2022-10-11 15:14:53 +02:00
|
|
|
|
|
|
|
# we should find order id 15 (created today)
|
2022-10-11 17:23:45 +02:00
|
|
|
stat_order = Stats::Order.search(query: { bool: { must: [{ term: { date: DateTime.current.to_date.iso8601 } },
|
2022-10-25 19:10:14 +02:00
|
|
|
{ term: { type: 'store' } }] } }).first
|
2022-10-11 15:14:53 +02:00
|
|
|
assert_not_nil stat_order
|
|
|
|
assert_equal @order.id, stat_order['orderId']
|
|
|
|
check_statistics_on_user(stat_order)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_statistics_on_user(stat)
|
|
|
|
assert_equal @order.statistic_profile.str_gender, stat['gender']
|
|
|
|
assert_equal @order.statistic_profile.age.to_i, stat['age']
|
|
|
|
assert_equal @order.statistic_profile.group.slug, stat['group']
|
|
|
|
end
|
|
|
|
end
|