mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Add test for ExportSerializer
This commit is contained in:
parent
7c9ba57e16
commit
52ad7b3535
3 changed files with 72 additions and 0 deletions
1
Gemfile
1
Gemfile
|
|
@ -35,6 +35,7 @@ end
|
||||||
group :test do
|
group :test do
|
||||||
gem 'shoulda-matchers'
|
gem 'shoulda-matchers'
|
||||||
gem 'simplecov'
|
gem 'simplecov'
|
||||||
|
gem 'super_diff'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ GEM
|
||||||
mutex_m
|
mutex_m
|
||||||
tzinfo (~> 2.0)
|
tzinfo (~> 2.0)
|
||||||
ast (2.4.2)
|
ast (2.4.2)
|
||||||
|
attr_extras (7.1.0)
|
||||||
base64 (0.2.0)
|
base64 (0.2.0)
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.20)
|
||||||
bigdecimal (3.1.7)
|
bigdecimal (3.1.7)
|
||||||
|
|
@ -163,11 +164,14 @@ GEM
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.16.3-x86_64-linux)
|
nokogiri (1.16.3-x86_64-linux)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
|
optimist (3.1.0)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
parallel (1.24.0)
|
parallel (1.24.0)
|
||||||
parser (3.3.0.5)
|
parser (3.3.0.5)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
racc
|
racc
|
||||||
|
patience_diff (1.2.0)
|
||||||
|
optimist (~> 3.0)
|
||||||
pg (1.5.6)
|
pg (1.5.6)
|
||||||
pry (0.14.2)
|
pry (0.14.2)
|
||||||
coderay (~> 1.1)
|
coderay (~> 1.1)
|
||||||
|
|
@ -300,6 +304,10 @@ GEM
|
||||||
stimulus-rails (1.3.3)
|
stimulus-rails (1.3.3)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
stringio (3.1.0)
|
stringio (3.1.0)
|
||||||
|
super_diff (0.11.0)
|
||||||
|
attr_extras (>= 6.2.4)
|
||||||
|
diff-lcs
|
||||||
|
patience_diff
|
||||||
tailwindcss-rails (2.3.0-aarch64-linux)
|
tailwindcss-rails (2.3.0-aarch64-linux)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
tailwindcss-rails (2.3.0-arm64-darwin)
|
tailwindcss-rails (2.3.0-arm64-darwin)
|
||||||
|
|
@ -357,6 +365,7 @@ DEPENDENCIES
|
||||||
simplecov
|
simplecov
|
||||||
sprockets-rails
|
sprockets-rails
|
||||||
stimulus-rails
|
stimulus-rails
|
||||||
|
super_diff
|
||||||
tailwindcss-rails
|
tailwindcss-rails
|
||||||
turbo-rails
|
turbo-rails
|
||||||
tzinfo-data
|
tzinfo-data
|
||||||
|
|
|
||||||
62
spec/serializers/export_serializer_spec.rb
Normal file
62
spec/serializers/export_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ExportSerializer do
|
||||||
|
describe '#call' do
|
||||||
|
subject(:serializer) { described_class.new(points, user_email).call }
|
||||||
|
|
||||||
|
let(:user_email) { 'ab@cd.com' }
|
||||||
|
let(:points) { create_list(:point, 2) }
|
||||||
|
let(:expected_json) do
|
||||||
|
{
|
||||||
|
user_email => {
|
||||||
|
'dawarich-export' => [
|
||||||
|
{
|
||||||
|
lat: points.first.latitude,
|
||||||
|
lon: points.first.longitude,
|
||||||
|
bs: 'u',
|
||||||
|
batt: points.first.battery,
|
||||||
|
p: points.first.ping,
|
||||||
|
alt: points.first.altitude,
|
||||||
|
acc: points.first.accuracy,
|
||||||
|
vac: points.first.vertical_accuracy,
|
||||||
|
vel: points.first.velocity,
|
||||||
|
conn: 'w',
|
||||||
|
SSID: points.first.ssid,
|
||||||
|
BSSID: points.first.bssid,
|
||||||
|
m: 'p',
|
||||||
|
tid: points.first.tracker_id,
|
||||||
|
tst: points.first.timestamp.to_i,
|
||||||
|
inrids: points.first.inrids,
|
||||||
|
inregions: points.first.in_regions,
|
||||||
|
topic: points.first.topic
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lat: points.second.latitude,
|
||||||
|
lon: points.second.longitude,
|
||||||
|
bs: 'u',
|
||||||
|
batt: points.second.battery,
|
||||||
|
p: points.second.ping,
|
||||||
|
alt: points.second.altitude,
|
||||||
|
acc: points.second.accuracy,
|
||||||
|
vac: points.second.vertical_accuracy,
|
||||||
|
vel: points.second.velocity,
|
||||||
|
conn: 'w',
|
||||||
|
SSID: points.second.ssid,
|
||||||
|
BSSID: points.second.bssid,
|
||||||
|
m: 'p',
|
||||||
|
tid: points.second.tracker_id,
|
||||||
|
tst: points.second.timestamp.to_i,
|
||||||
|
inrids: points.second.inrids,
|
||||||
|
inregions: points.second.in_regions,
|
||||||
|
topic: points.second.topic
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns JSON' do
|
||||||
|
expect(serializer).to eq(expected_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue