Add tests

This commit is contained in:
Eugene Burmakin 2025-11-14 18:16:51 +01:00
parent 8c4d4d5cbe
commit 3bd59c20c1
3 changed files with 29 additions and 6 deletions

View file

@ -118,12 +118,8 @@ class Imports::SourceDetector
end end
def kml_file? def kml_file?
return false unless filename return false unless filename&.downcase&.end_with?('.kml', '.kmz')
# Must have .kml or .kmz extension AND contain KML XML structure
return false unless filename.downcase.end_with?('.kml', '.kmz')
# Check content for KML structure
content_to_check = content_to_check =
if file_path && File.exist?(file_path) if file_path && File.exist?(file_path)
# Read first 1KB for KML detection # Read first 1KB for KML detection

View file

@ -73,7 +73,10 @@ Rails.application.configure do
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" } config.cache_store = :redis_cache_store, {
url: ENV['REDIS_URL'],
db: ENV.fetch('RAILS_CACHE_DB', 0)
}
# Use a real queuing backend for Active Job (and separate queues per environment). # Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :sidekiq config.active_job.queue_adapter = :sidekiq

View file

@ -74,6 +74,15 @@ RSpec.describe Imports::SourceDetector do
end end
end end
context 'with KML file' do
let(:file_content) { file_fixture('kml/points_with_timestamps.kml').read }
let(:filename) { 'test.kml' }
it 'detects kml format' do
expect(detector.detect_source).to eq(:kml)
end
end
context 'with invalid JSON' do context 'with invalid JSON' do
let(:file_content) { 'invalid json content' } let(:file_content) { 'invalid json content' }
@ -145,6 +154,15 @@ RSpec.describe Imports::SourceDetector do
expect(detector.detect_source).to eq(:geojson) expect(detector.detect_source).to eq(:geojson)
end end
end end
context 'with KML file' do
let(:fixture_path) { file_fixture('kml/points_with_timestamps.kml').to_s }
it 'detects source correctly from file path' do
detector = described_class.new_from_file_header(fixture_path)
expect(detector.detect_source).to eq(:kml)
end
end
end end
describe 'detection accuracy with real fixture files' do describe 'detection accuracy with real fixture files' do
@ -170,5 +188,11 @@ RSpec.describe Imports::SourceDetector do
include_examples 'detects format correctly', :gpx, 'gpx/arc_example.gpx' include_examples 'detects format correctly', :gpx, 'gpx/arc_example.gpx'
include_examples 'detects format correctly', :gpx, 'gpx/garmin_example.gpx' include_examples 'detects format correctly', :gpx, 'gpx/garmin_example.gpx'
include_examples 'detects format correctly', :gpx, 'gpx/gpx_track_multiple_segments.gpx' include_examples 'detects format correctly', :gpx, 'gpx/gpx_track_multiple_segments.gpx'
# Test KML files
include_examples 'detects format correctly', :kml, 'kml/points_with_timestamps.kml'
include_examples 'detects format correctly', :kml, 'kml/linestring_track.kml'
include_examples 'detects format correctly', :kml, 'kml/gx_track.kml'
include_examples 'detects format correctly', :kml, 'kml/multigeometry.kml'
end end
end end