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
d8d7f2413c
commit
cf35c71461
4 changed files with 30 additions and 24 deletions
File diff suppressed because one or more lines are too long
|
|
@ -22,20 +22,11 @@ RSpec.describe Points::RawDataArchive, type: :model do
|
|||
it { is_expected.to validate_numericality_of(:month).is_greater_than_or_equal_to(1).is_less_than_or_equal_to(12) }
|
||||
it { is_expected.to validate_numericality_of(:chunk_number).is_greater_than(0) }
|
||||
|
||||
context 'when updating' do
|
||||
it 'validates file is attached' do
|
||||
archive = create(:points_raw_data_archive, user: user)
|
||||
archive.file.purge if archive.file.attached?
|
||||
|
||||
expect(archive).not_to be_valid
|
||||
expect(archive.errors[:file]).to include('must be attached')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'scopes' do
|
||||
let!(:recent_archive) { create(:points_raw_data_archive, user: user, archived_at: 1.day.ago) }
|
||||
let!(:old_archive) { create(:points_raw_data_archive, user: user, archived_at: 2.years.ago) }
|
||||
let!(:recent_archive) { create(:points_raw_data_archive, user: user, year: 2024, month: 5, archived_at: 1.day.ago) }
|
||||
let!(:old_archive) { create(:points_raw_data_archive, user: user, year: 2023, month: 5, archived_at: 2.years.ago) }
|
||||
|
||||
describe '.recent' do
|
||||
it 'returns archives from last 30 days' do
|
||||
|
|
@ -58,7 +49,9 @@ RSpec.describe Points::RawDataArchive, type: :model do
|
|||
|
||||
it 'returns archives for specific month ordered by chunk number' do
|
||||
result = described_class.for_month(user.id, 2024, 6)
|
||||
expect(result).to eq([june_archive, june_archive_2])
|
||||
expect(result.map(&:chunk_number)).to eq([1, 2])
|
||||
expect(result).to include(june_archive, june_archive_2)
|
||||
expect(result).not_to include(july_archive)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,7 +35,11 @@ RSpec.describe PointSerializer do
|
|||
'course_accuracy' => point.course_accuracy,
|
||||
'external_track_id' => point.external_track_id,
|
||||
'track_id' => point.track_id,
|
||||
'country_name' => point.read_attribute(:country_name)
|
||||
'country_name' => point.read_attribute(:country_name),
|
||||
'raw_data_archived' => point.raw_data_archived,
|
||||
'raw_data_archive_id' => point.raw_data_archive_id,
|
||||
'timestamp_year' => point.timestamp_year,
|
||||
'timestamp_month' => point.timestamp_month
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -138,27 +138,36 @@ RSpec.describe Points::RawData::Archiver do
|
|||
allow(ENV).to receive(:[]).with('ARCHIVE_RAW_DATA').and_return('true')
|
||||
end
|
||||
|
||||
let(:test_date) { 3.months.ago.beginning_of_month }
|
||||
let(:test_date_utc) { Time.at(test_date.to_i).utc }
|
||||
# Use UTC from the start to avoid timezone issues
|
||||
let(:test_date_utc) { 3.months.ago.utc.beginning_of_month }
|
||||
let!(:june_points_batch1) do
|
||||
create_list(:point, 2, user: user,
|
||||
timestamp: test_date.to_i,
|
||||
timestamp: test_date_utc.to_i,
|
||||
raw_data: { lon: 13.4, lat: 52.5 })
|
||||
end
|
||||
|
||||
xit 'creates additional chunks for same month' do
|
||||
it 'creates additional chunks for same month' do
|
||||
# First archival
|
||||
archiver.archive_specific_month(user.id, test_date_utc.year, test_date_utc.month)
|
||||
expect(Points::RawDataArchive.for_month(user.id, test_date_utc.year, test_date_utc.month).count).to eq(1)
|
||||
expect(Points::RawDataArchive.last.chunk_number).to eq(1)
|
||||
|
||||
# Add more points for same month (retrospective import)
|
||||
mid_month = test_date_utc + 15.days
|
||||
june_points_batch2 = create_list(:point, 2, user: user,
|
||||
timestamp: mid_month.to_i,
|
||||
raw_data: { lon: 14.0, lat: 53.0 })
|
||||
# Verify first batch is archived
|
||||
june_points_batch1.each(&:reload)
|
||||
expect(june_points_batch1.all? { |p| p.raw_data_archived }).to be true
|
||||
|
||||
# Second archival
|
||||
# Add more points for same month (retrospective import)
|
||||
# Use unique timestamps to avoid uniqueness validation errors
|
||||
mid_month = test_date_utc + 15.days
|
||||
june_points_batch2 = [
|
||||
create(:point, user: user, timestamp: mid_month.to_i, raw_data: { lon: 14.0, lat: 53.0 }),
|
||||
create(:point, user: user, timestamp: (mid_month + 1.hour).to_i, raw_data: { lon: 14.0, lat: 53.0 })
|
||||
]
|
||||
|
||||
# Verify second batch exists and is not archived
|
||||
expect(june_points_batch2.all? { |p| !p.raw_data_archived }).to be true
|
||||
|
||||
# Second archival should create chunk 2
|
||||
archiver.archive_specific_month(user.id, test_date_utc.year, test_date_utc.month)
|
||||
expect(Points::RawDataArchive.for_month(user.id, test_date_utc.year, test_date_utc.month).count).to eq(2)
|
||||
expect(Points::RawDataArchive.last.chunk_number).to eq(2)
|
||||
|
|
|
|||
Loading…
Reference in a new issue