-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ap-4508: Add class to handle linked_application_types
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
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 |
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,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 |