From 4950070b813037455c9fb3db49858f5e1f35ae2a Mon Sep 17 00:00:00 2001 From: NVMakarenko Date: Sat, 30 Nov 2024 21:57:05 +0200 Subject: [PATCH] add tests --- spec/fixtures/files/unlighthouse_report.json | 18 ++++++++++++++ spec/lib/convert_json_to_csv_spec.rb | 26 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 spec/fixtures/files/unlighthouse_report.json create mode 100644 spec/lib/convert_json_to_csv_spec.rb diff --git a/spec/fixtures/files/unlighthouse_report.json b/spec/fixtures/files/unlighthouse_report.json new file mode 100644 index 000000000..2984245d6 --- /dev/null +++ b/spec/fixtures/files/unlighthouse_report.json @@ -0,0 +1,18 @@ +[ + { + "path": "/en", + "score": 0.78, + "performance": 0.64, + "accessibility": 0.86, + "best-practices": 0.79, + "seo": 0.83 + }, + { + "path": "/en/about-us", + "score": 0.78, + "performance": 0.63, + "accessibility": 0.77, + "best-practices": 0.79, + "seo": 0.92 + } +] diff --git a/spec/lib/convert_json_to_csv_spec.rb b/spec/lib/convert_json_to_csv_spec.rb new file mode 100644 index 000000000..9e98a9420 --- /dev/null +++ b/spec/lib/convert_json_to_csv_spec.rb @@ -0,0 +1,26 @@ +require "rails_helper" + +RSpec.describe ConvertJsonToCsv do + let(:input_file) { "spec/fixtures/files/unlighthouse_report.json" } + let(:output_file) { "spec/fixtures/files/output.csv" } + + after do + File.delete(output_file) if File.exist?(output_file) + end + + describe ".perform" do + it "converts JSON to CSV" do + ConvertJsonToCsv.perform(input_file, output_file) + csv_content = CSV.read(output_file, headers: true) + + expect(csv_content.headers).to eq(["path", "score", "performance", "accessibility", "best-practices", "seo"]) + + expect(csv_content[0]["path"]).to eq("/en") + expect(csv_content[0]["score"]).to eq("0.78") + expect(csv_content[0]["performance"]).to eq("0.64") + expect(csv_content[0]["accessibility"]).to eq("0.86") + expect(csv_content[0]["best-practices"]).to eq("0.79") + expect(csv_content[0]["seo"]).to eq("0.83") + end + end +end