mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Fix tests
This commit is contained in:
parent
f492a69fbb
commit
a2b20cfdf1
4 changed files with 45 additions and 12 deletions
|
|
@ -35,6 +35,10 @@ class ImportsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@import = Import.new
|
||||
|
||||
authorize @import
|
||||
|
||||
files_params = params.dig(:import, :files)
|
||||
raw_files = Array(files_params).reject(&:blank?)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,22 +3,39 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Api::V1::Stats', type: :request do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe 'GET /index' do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:stats_in_2020) { create_list(:stat, 12, year: 2020, user:) }
|
||||
let!(:stats_in_2021) { create_list(:stat, 12, year: 2021, user:) }
|
||||
let!(:points_in_2020) do
|
||||
let(:user) { create(:user) }
|
||||
let(:stats_in_2020) { create_list(:stat, 12, year: 2020, user:) }
|
||||
let(:stats_in_2021) { create_list(:stat, 12, year: 2021, user:) }
|
||||
let(:points_in_2020) do
|
||||
(1..85).map do |i|
|
||||
create(:point, :with_geodata, :reverse_geocoded, timestamp: Time.zone.local(2020, 1, 1).to_i + i.hours, user:)
|
||||
create(:point, :with_geodata,
|
||||
timestamp: Time.zone.local(2020, 1, 1).to_i + i.hours,
|
||||
user:,
|
||||
country_name: 'Test Country',
|
||||
city: 'Test City',
|
||||
reverse_geocoded_at: Time.current)
|
||||
end
|
||||
end
|
||||
let!(:points_in_2021) do
|
||||
let(:points_in_2021) do
|
||||
(1..95).map do |i|
|
||||
create(:point, :with_geodata, :reverse_geocoded, timestamp: Time.zone.local(2021, 1, 1).to_i + i.hours, user:)
|
||||
create(:point, :with_geodata,
|
||||
timestamp: Time.zone.local(2021, 1, 1).to_i + i.hours,
|
||||
user:,
|
||||
country_name: 'Test Country',
|
||||
city: 'Test City',
|
||||
reverse_geocoded_at: Time.current)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
# Create all the test data
|
||||
stats_in_2020
|
||||
stats_in_2021
|
||||
points_in_2020
|
||||
points_in_2021
|
||||
end
|
||||
|
||||
let(:expected_json) do
|
||||
{
|
||||
totalDistanceKm: (stats_in_2020.map(&:distance).sum + stats_in_2021.map(&:distance).sum) / 1000,
|
||||
|
|
@ -84,3 +101,4 @@ RSpec.describe 'Api::V1::Stats', type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ RSpec.describe PointSerializer do
|
|||
'course' => point.course,
|
||||
'course_accuracy' => point.course_accuracy,
|
||||
'external_track_id' => point.external_track_id,
|
||||
'track_id' => point.track_id
|
||||
'track_id' => point.track_id,
|
||||
'country_name' => point.read_attribute(:country_name)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,12 +30,22 @@ RSpec.describe StatsSerializer do
|
|||
let!(:stats_in_2021) { create_list(:stat, 12, year: 2021, user:) }
|
||||
let!(:points_in_2020) do
|
||||
(1..85).map do |i|
|
||||
create(:point, :with_geodata, :reverse_geocoded, timestamp: Time.zone.local(2020, 1, 1).to_i + i.hours, user:)
|
||||
create(:point, :with_geodata,
|
||||
timestamp: Time.zone.local(2020, 1, 1).to_i + i.hours,
|
||||
user:,
|
||||
country_name: 'Test Country',
|
||||
city: 'Test City',
|
||||
reverse_geocoded_at: Time.current)
|
||||
end
|
||||
end
|
||||
let!(:points_in_2021) do
|
||||
(1..95).map do |i|
|
||||
create(:point, :with_geodata, :reverse_geocoded, timestamp: Time.zone.local(2021, 1, 1).to_i + i.hours, user:)
|
||||
create(:point, :with_geodata,
|
||||
timestamp: Time.zone.local(2021, 1, 1).to_i + i.hours,
|
||||
user:,
|
||||
country_name: 'Test Country',
|
||||
city: 'Test City',
|
||||
reverse_geocoded_at: Time.current)
|
||||
end
|
||||
end
|
||||
let(:expected_json) do
|
||||
|
|
|
|||
Loading…
Reference in a new issue