2024-09-02 16:01:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Points::GeojsonSerializer do
|
|
|
|
|
describe '#call' do
|
|
|
|
|
subject(:serializer) { described_class.new(points).call }
|
|
|
|
|
|
2025-01-20 11:59:13 -05:00
|
|
|
let(:points) do
|
|
|
|
|
(1..3).map do |i|
|
|
|
|
|
create(:point, timestamp: 1.day.ago + i.minutes)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-02 16:01:51 -04:00
|
|
|
let(:expected_json) do
|
|
|
|
|
{
|
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
|
features: points.map do |point|
|
|
|
|
|
{
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Point',
|
2025-05-22 13:09:43 -04:00
|
|
|
coordinates: [point.lon, point.lat]
|
2024-09-02 16:01:51 -04:00
|
|
|
},
|
|
|
|
|
properties: PointSerializer.new(point).call
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns JSON' do
|
|
|
|
|
expect(serializer).to eq(expected_json.to_json)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|