Skip to content

Commit

Permalink
Test, delete, or nocov remaining uncovered code
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Dec 28, 2023
1 parent 9cebdc2 commit 8b10280
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 54 deletions.
10 changes: 10 additions & 0 deletions spec/remote_generator/services/command_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.describe Foobara::RemoteGenerator::Services::CommandGenerator do
let(:raw_manifest_json) { File.read("spec/fixtures/foobara-manifest.json") }
let(:raw_manifest) { JSON.parse(raw_manifest_json) }
let(:command_manifest) { Foobara::Manifest::Command.new(raw_manifest, %i[command GlobalCommand]) }
let(:generator) { described_class.new(command_manifest) }

it "contains base files" do
expect(generator).to respond_to(:command_name)
end
end
70 changes: 70 additions & 0 deletions spec/remote_generator/services/entity_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
RSpec.describe Foobara::RemoteGenerator::Services::EntityGenerator do
let(:raw_manifest_json) { File.read("spec/fixtures/foobara-manifest.json") }
let(:raw_manifest) { JSON.parse(raw_manifest_json) }
let(:entity_manifest) { Foobara::Manifest::Entity.new(raw_manifest, path) }
let(:path) { [:type, "SomeOrg::Auth::Referral"] }
let(:generator) { generator_class.new(entity_manifest) }
let(:generator_class) { described_class }

it "has the expected names prefixed as necessary" do
expect(generator.atom_name).to eq("ReferralAtom")
expect(generator.loaded_name).to eq("LoadedReferral")
expect(generator.unloaded_name).to eq("UnloadedReferral")
expect(generator.aggregate_name).to eq("ReferralAggregate")
expect(generator.entity_name).to eq("Referral")

expect(generator.atom_name(1)).to eq("Auth.ReferralAtom")
expect(generator.loaded_name(1)).to eq("Auth.LoadedReferral")
expect(generator.unloaded_name(1)).to eq("Auth.UnloadedReferral")
expect(generator.aggregate_name(1)).to eq("Auth.ReferralAggregate")
expect(generator.entity_name(1)).to eq("Auth.Referral")

expect(generator.atom_name(2)).to eq("SomeOrg.Auth.ReferralAtom")
expect(generator.loaded_name(2)).to eq("SomeOrg.Auth.LoadedReferral")
expect(generator.unloaded_name(2)).to eq("SomeOrg.Auth.UnloadedReferral")
expect(generator.aggregate_name(2)).to eq("SomeOrg.Auth.ReferralAggregate")
expect(generator.entity_name(2)).to eq("SomeOrg.Auth.Referral")
end

context "when entity does not have associations" do
let(:path) { [:type, "SomeOrg::Auth::User"] }

it "has the expected names prefixed as necessary" do
expect(generator.atom_name).to eq("LoadedUser")
expect(generator.loaded_name).to eq("LoadedUser")
expect(generator.unloaded_name).to eq("UnloadedUser")
expect(generator.aggregate_name).to eq("UserAggregate")
expect(generator.entity_name).to eq("User")

expect(generator.atom_name(1)).to eq("Auth.LoadedUser")
expect(generator.loaded_name(1)).to eq("Auth.LoadedUser")
expect(generator.unloaded_name(1)).to eq("Auth.UnloadedUser")
expect(generator.aggregate_name(1)).to eq("Auth.UserAggregate")
expect(generator.entity_name(1)).to eq("Auth.User")

expect(generator.atom_name(2)).to eq("SomeOrg.Auth.LoadedUser")
expect(generator.loaded_name(2)).to eq("SomeOrg.Auth.LoadedUser")
expect(generator.unloaded_name(2)).to eq("SomeOrg.Auth.UnloadedUser")
expect(generator.aggregate_name(2)).to eq("SomeOrg.Auth.UserAggregate")
expect(generator.entity_name(2)).to eq("SomeOrg.Auth.User")
end
end

describe "#ts_instance_path" do
context "when it's a loaded generator" do
let(:generator_class) { Foobara::RemoteGenerator::Services::LoadedEntityGenerator }

it "gives the loaded path" do
expect(generator.ts_instance_path).to eq(["LoadedReferral"])
end
end

context "when it's an atom generator" do
let(:generator_class) { Foobara::RemoteGenerator::Services::AtomEntityGenerator }

it "gives the atom path" do
expect(generator.ts_instance_path).to eq(["ReferralAtom"])
end
end
end
end
40 changes: 22 additions & 18 deletions src/remote_generator/services/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def generators_for(manifest, elements_to_generate)
when Manifest::ProcessorClass
Services::ProcessorClassGenerator
else
# :nocov:
raise "Not sure how build a generator for a #{manifest}"
# :nocov:
end

Util.array(generator_classes).map do |generator_class|
Expand All @@ -77,7 +79,9 @@ def initialize(relevant_manifest, elements_to_generate = nil)
end

def target_path
# :nocov:
raise "Subclass responsibility"
# :nocov:
end

def target_dir
Expand All @@ -91,7 +95,9 @@ def parent
end

def dependencies
# :nocov:
raise "Subclass responsibility"
# :nocov:
end

def dependency_group
Expand All @@ -106,34 +112,20 @@ def dependency_group

def dependency_roots
unless dependency_group
# :nocov:
raise "This generator was created without a " \
"dependency_group and therefore cannot call #{__method__}"
# :nocov:
end

dependency_group.non_colliding_dependency_roots.sort_by(&:scoped_full_name)
end

def non_colliding_root
unless belongs_to_dependency_group
raise "This generator was created without a " \
"belongs_to_dependency_group and therefore cannot call #{__method__}"
end

belongs_to_dependency_group.non_colliding_root(self)
end

def non_colliding_name
unless belongs_to_dependency_group
raise "This generator was created without a " \
"belongs_to_dependency_group and therefore cannot call #{__method__}"
end

belongs_to_dependency_group.non_colliding_name(self)
end

def generate
unless elements_to_generate
# :nocov:
raise "This generator was created without elements_to_generate and therefore cannot be ran."
# :nocov:
end

dependencies.each do |dependency|
Expand All @@ -149,7 +141,9 @@ def generator_for(manifest)
end

def template_path
# :nocov:
raise "Subclass responsibility"
# :nocov:
end

def absolute_template_path
Expand All @@ -174,7 +168,9 @@ def erb_template
end

def short_name
# :nocov:
raise "Subclass responsibility"
# :nocov:
end

def ts_instance_name
Expand Down Expand Up @@ -225,7 +221,9 @@ def method_missing(method_name, *, &)
if relevant_manifest.respond_to?(method_name)
relevant_manifest.send(method_name, *, &)
else
# :nocov:
super
# :nocov:
end
end

Expand All @@ -251,7 +249,9 @@ def foobara_type_to_ts_type(
end

if type_declaration.relevant_manifest.size > 1
# :nocov:
raise "Converting a #{type_declaration.inspect} to a TS type yet supported"
# :nocov:
end

type_symbol = type_declaration.type
Expand All @@ -277,7 +277,9 @@ def foobara_type_to_ts_type(
if type_string
name ? "#{name} = #{type_string}" : type_string
else
# :nocov:
raise "Not sure how to convert #{type_declaration} to a TS type"
# :nocov:
end
end

Expand Down Expand Up @@ -305,7 +307,9 @@ def entity_to_ts_entity_name(entity, association_depth: AssociationDepth::AMBIGU
when AssociationDepth::AGGREGATE
generator.aggregate_name(points)
else
# :nocov:
raise "Bad association_depth: #{association_depth}"
# :nocov:
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions src/remote_generator/services/command_errors_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ def template_path
"Command/Errors.ts.erb"
end

def uniq_error_generators_by_symbol
@uniq_error_generators_by_symbol ||= begin
set = {}

error_generators.each do |error_generator|
set[error_generator.symbol] = error_generator
end

set.values
end
end

def error_generators
error_types.values.map(&:error).uniq.map do |error|
Services::ErrorGenerator.new(error, elements_to_generate)
Expand Down
23 changes: 3 additions & 20 deletions src/remote_generator/services/entity_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def unloaded_name(points = nil)
*prefix, name = if points
scoped_full_path(points)
else
# TODO: test this
# :nocov:
scoped_path
# :nocov:
end

[*prefix, "Unloaded#{name}"].join(".")
Expand Down Expand Up @@ -79,14 +82,6 @@ def aggregate_name(points = nil)
[*prefix, "#{name}Aggregate"].join(".")
end

def all_names
@all_names ||= if has_associations?
[name, unloaded_name, atom_name, aggregate_name]
else
[name, unloaded_name]
end
end

def entity_generators
types_depended_on.select(&:entity?).map do |entity|
Services::EntityGenerator.new(entity, elements_to_generate)
Expand Down Expand Up @@ -124,18 +119,6 @@ def aggregate_attributes_ts_type
foobara_type_to_ts_type(attributes_type, association_depth:, dependency_group:)
end

def attributes_types_union
attributes_types = if has_associations?
["", "Atom", "Aggregate"]
else
[""]
end

attributes_types.map! { |prefix| "#{entity_name}#{prefix}AttributesType" }

attributes_types.join(" | ")
end

def association_property_names_ts_array
associations.keys.map(&:to_s).inspect
end
Expand Down
4 changes: 0 additions & 4 deletions src/remote_generator/services/processor_class_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def target_path

["base", "processors", *path, basename]
end

def template_path
"ProcessorClass.ts.erb"
end
end
end
end
Expand Down

0 comments on commit 8b10280

Please sign in to comment.