Skip to content

Commit

Permalink
ap-4508: Add class to handle linked_application_types
Browse files Browse the repository at this point in the history
  • Loading branch information
kmahern committed Oct 18, 2023
1 parent 046c382 commit 00bc2c3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/models/linked_application_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class LinkedApplicationType
LINK_TYPES = [
{ code: "FAMILY", description: "Family" },
{ code: "LEGAL", description: "Legal" },
].freeze

def self.link_types
LINK_TYPES
end

def self.link_type(code)
LINK_TYPES.find { |link_type| link_type[:code] == code }
end

def self.link_description(code)
link_type = link_type(code)
return nil unless link_type

link_type[:description]
end
end
46 changes: 46 additions & 0 deletions spec/models/linked_application_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "rails_helper"

RSpec.describe LinkedApplicationType do
describe ".link_types" do
let(:link_types) do
[
{ code: "FAMILY", description: "Family" },
{ code: "LEGAL", description: "Legal" },
]
end

it "returns link types" do
expect(described_class.link_types).to eq link_types
end
end

describe ".link_type" do
context "when code exists" do
let(:family_link_type) { { code: "FAMILY", description: "Family" } }

it "returns link type" do
expect(described_class.link_type("FAMILY")).to eq family_link_type
end
end

context "when code does not exist" do
it "returns link type" do
expect(described_class.link_type("xxx")).to be_nil
end
end
end

describe ".description" do
context "when code exists" do
it "returns link type descrition" do
expect(described_class.link_description("LEGAL")).to eq "Legal"
end
end

context "when code does not exist" do
it "returns link type" do
expect(described_class.link_description("xxx")).to be_nil
end
end
end
end

0 comments on commit 00bc2c3

Please sign in to comment.