-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa02b40
commit baccbb3
Showing
3 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Manifolds::Services::BigQueryService do | ||
let(:logger) { instance_double("Logger") } | ||
let(:service) { described_class.new(logger) } | ||
let(:project_name) { "test_project" } | ||
let(:config_path) { "./projects/#{project_name}/config.yml" } | ||
let(:config) do | ||
{ | ||
"dimensions" => [ | ||
{ "name" => "STRING" }, | ||
{ "directQualified" => "BOOLEAN" } | ||
] | ||
} | ||
end | ||
|
||
before do | ||
allow(File).to receive(:exist?).with(config_path).and_return(true) | ||
allow(YAML).to receive(:load_file).with(config_path).and_return(config) | ||
allow(FileUtils).to receive(:mkdir_p) | ||
allow(File).to receive(:write) | ||
allow(logger).to receive(:info) # Allow 'info' to be called to avoid unexpected message errors | ||
end | ||
|
||
describe "#generate_dimensions_schema" do | ||
it "checks if the configuration file exists" do | ||
service.generate_dimensions_schema(project_name) | ||
expect(File).to have_received(:exist?).with(config_path) | ||
end | ||
|
||
context "when configuration file does not exist" do | ||
before do | ||
allow(File).to receive(:exist?).with(config_path).and_return(false) | ||
allow(logger).to receive(:error) | ||
end | ||
|
||
it "logs an error message" do | ||
service.generate_dimensions_schema(project_name) | ||
expect(logger).to have_received(:error).with("Config file missing for project 'test_project'.") | ||
end | ||
end | ||
|
||
it "writes the dimensions schema to a file" do | ||
service.generate_dimensions_schema(project_name) | ||
expect(File).to have_received(:write).with("./projects/#{project_name}/bq/dimensions.json", anything) | ||
end | ||
|
||
it "logs success message" do | ||
service.generate_dimensions_schema(project_name) | ||
expect(logger).to have_received(:info).with("Generated BigQuery dimensions table schema for 'test_project'.") | ||
end | ||
end | ||
end |