diff --git a/Gemfile b/Gemfile index cb1e7c09..71df581b 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ end group :test do gem 'shoulda-matchers' gem 'simplecov' + gem 'super_diff' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 35d74a6f..04238fcc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,7 @@ GEM mutex_m tzinfo (~> 2.0) ast (2.4.2) + attr_extras (7.1.0) base64 (0.2.0) bcrypt (3.1.20) bigdecimal (3.1.7) @@ -163,11 +164,14 @@ GEM racc (~> 1.4) nokogiri (1.16.3-x86_64-linux) racc (~> 1.4) + optimist (3.1.0) orm_adapter (0.5.0) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) racc + patience_diff (1.2.0) + optimist (~> 3.0) pg (1.5.6) pry (0.14.2) coderay (~> 1.1) @@ -300,6 +304,10 @@ GEM stimulus-rails (1.3.3) railties (>= 6.0.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) railties (>= 6.0.0) tailwindcss-rails (2.3.0-arm64-darwin) @@ -357,6 +365,7 @@ DEPENDENCIES simplecov sprockets-rails stimulus-rails + super_diff tailwindcss-rails turbo-rails tzinfo-data diff --git a/spec/serializers/export_serializer_spec.rb b/spec/serializers/export_serializer_spec.rb new file mode 100644 index 00000000..280c011b --- /dev/null +++ b/spec/serializers/export_serializer_spec.rb @@ -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