dawarich/spec/services/overland/params_spec.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

2024-07-08 17:56:08 -04:00
# frozen_string_literal: true
2024-04-06 13:09:38 -04:00
require 'rails_helper'
RSpec.describe Overland::Params do
describe '#call' do
2024-07-08 17:56:08 -04:00
# This file contains one valid point and one invalid point w/out coordinates
let(:file_path) { 'spec/fixtures/files/overland/geodata.json' }
2024-04-06 13:09:38 -04:00
let(:file) { File.open(file_path) }
let(:json) { JSON.parse(file.read) }
let(:expected_json) do
{
2025-02-22 16:37:21 -05:00
lonlat: 'POINT(-122.030581 37.3318)',
2024-04-06 13:09:38 -04:00
battery_status: 'charging',
battery: 89,
altitude: 0,
accuracy: 30,
vertical_accuracy: -1,
velocity: 4,
ssid: 'launchpad',
tracker_id: '',
timestamp: DateTime.parse('2015-10-01T08:00:00-0700'),
raw_data: json['locations'][0]
}
end
subject(:params) { described_class.new(json).call }
it 'returns a hash with the correct keys' do
expect(params[0].keys).to match_array(
%i[
battery_status
battery
altitude
accuracy
vertical_accuracy
velocity
ssid
tracker_id
timestamp
raw_data
2025-02-22 16:37:21 -05:00
lonlat
2024-04-06 13:09:38 -04:00
]
)
end
it 'returns a hash with the correct values' do
expect(params[0]).to eq(expected_json)
end
2024-07-08 17:56:08 -04:00
it 'returns the correct number of points' do
expect(params.size).to eq(1)
end
2024-04-06 13:09:38 -04:00
end
end