Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NVMakarenko committed Nov 30, 2024
1 parent b4bdc86 commit 4950070
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/fixtures/files/unlighthouse_report.json
Original file line number Diff line number Diff line change
@@ -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
}
]
26 changes: 26 additions & 0 deletions spec/lib/convert_json_to_csv_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4950070

Please sign in to comment.