mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Fix failing specs
This commit is contained in:
parent
9fb4f908ad
commit
29467dd05a
5 changed files with 39 additions and 16 deletions
|
|
@ -141,14 +141,19 @@ module Points
|
|||
end
|
||||
|
||||
def verify_raw_data_matches(archived_data)
|
||||
# Sample verification: check random points to ensure archived data matches database
|
||||
# For performance, we'll verify a sample rather than all points
|
||||
sample_size = [archived_data.size, 100].min
|
||||
point_ids_to_check = archived_data.keys.sample(sample_size)
|
||||
# For small archives, verify all points. For large archives, sample up to 100 points.
|
||||
# Always verify all if 100 or fewer points for maximum accuracy
|
||||
if archived_data.size <= 100
|
||||
point_ids_to_check = archived_data.keys
|
||||
else
|
||||
point_ids_to_check = archived_data.keys.sample(100)
|
||||
end
|
||||
|
||||
mismatches = []
|
||||
found_points = 0
|
||||
|
||||
Point.where(id: point_ids_to_check).find_each do |point|
|
||||
found_points += 1
|
||||
archived_raw_data = archived_data[point.id]
|
||||
current_raw_data = point.raw_data
|
||||
|
||||
|
|
@ -162,6 +167,14 @@ module Points
|
|||
end
|
||||
end
|
||||
|
||||
# Check if we found all the points we were looking for
|
||||
if found_points != point_ids_to_check.size
|
||||
return {
|
||||
success: false,
|
||||
error: "Missing points during data verification: expected #{point_ids_to_check.size}, found #{found_points}"
|
||||
}
|
||||
end
|
||||
|
||||
if mismatches.any?
|
||||
return {
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ nightly_family_invitations_cleanup_job:
|
|||
class: "Family::Invitations::CleanupJob"
|
||||
queue: family
|
||||
|
||||
raw_data_archival_job:
|
||||
cron: "0 2 1 * *" # Monthly on the 1st at 2 AM
|
||||
class: "Points::RawData::ArchiveJob"
|
||||
queue: archival
|
||||
# raw_data_archival_job:
|
||||
# cron: "0 2 1 * *" # Monthly on the 1st at 2 AM
|
||||
# class: "Points::RawData::ArchiveJob"
|
||||
# queue: archival
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ RSpec.describe Points::RawData::Archiver do
|
|||
it 'keeps raw_data intact (does not clear yet)' do
|
||||
archiver.call
|
||||
Point.where(user: user).find_each do |point|
|
||||
expect(point.raw_data).to eq({ lon: 13.4, lat: 52.5 })
|
||||
expect(point.raw_data).to eq({ 'lon' => 13.4, 'lat' => 52.5 })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,10 @@ RSpec.describe Points::RawData::Clearer do
|
|||
|
||||
it 'is idempotent (safe to run multiple times)' do
|
||||
first_result = clearer.call
|
||||
second_result = clearer.call
|
||||
|
||||
# Use a new instance for second call
|
||||
new_clearer = Points::RawData::Clearer.new
|
||||
second_result = new_clearer.call
|
||||
|
||||
expect(first_result[:cleared]).to eq(5)
|
||||
expect(second_result[:cleared]).to eq(0) # Already cleared
|
||||
|
|
|
|||
|
|
@ -62,20 +62,26 @@ RSpec.describe Points::RawData::Verifier do
|
|||
end
|
||||
|
||||
it 'detects deleted points' do
|
||||
# Delete one point from database
|
||||
# Force archive creation first
|
||||
archive_id = archive.id
|
||||
|
||||
# Then delete one point from database
|
||||
points.first.destroy
|
||||
|
||||
expect do
|
||||
verifier.verify_specific_archive(archive.id)
|
||||
verifier.verify_specific_archive(archive_id)
|
||||
end.not_to change { archive.reload.verified_at }
|
||||
end
|
||||
|
||||
it 'detects raw_data mismatch between archive and database' do
|
||||
# Modify raw_data in database after archiving
|
||||
# Force archive creation first
|
||||
archive_id = archive.id
|
||||
|
||||
# Then modify raw_data in database after archiving
|
||||
points.first.update_column(:raw_data, { lon: 999.0, lat: 999.0 })
|
||||
|
||||
expect do
|
||||
verifier.verify_specific_archive(archive.id)
|
||||
verifier.verify_specific_archive(archive_id)
|
||||
end.not_to change { archive.reload.verified_at }
|
||||
end
|
||||
|
||||
|
|
@ -149,8 +155,9 @@ RSpec.describe Points::RawData::Verifier do
|
|||
# Verify once
|
||||
verifier.call
|
||||
|
||||
# Try to verify again
|
||||
result = verifier.call
|
||||
# Try to verify again with a new verifier instance
|
||||
new_verifier = Points::RawData::Verifier.new
|
||||
result = new_verifier.call
|
||||
|
||||
expect(result[:verified]).to eq(0)
|
||||
expect(result[:failed]).to eq(0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue