mirror of
https://github.com/usetrmnl/trmnl-api.git
synced 2026-04-29 13:35:13 -07:00
Fixed palette model to use name and label attributes
Use of `id` (a.k.a. name) and `name` (a.k.a. label) was confusing and not an accurate representation of what these attributes are. This corrects the API design mistakes by having the model transform these keys appropriately. Milestone: minor
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "refinements/hash"
|
||||
|
||||
module TRMNL
|
||||
module API
|
||||
module Models
|
||||
# Models the data of the API response.
|
||||
Palette = Struct.new :id, :name, :grays, :colors, :framework_class do
|
||||
def self.for(attributes) = new(**attributes)
|
||||
Palette = Struct.new :name, :label, :grays, :colors, :framework_class do
|
||||
using Refinements::Hash
|
||||
|
||||
def self.for(attributes) = new(**attributes.transform_keys(name: :label, id: :name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,8 +39,8 @@ RSpec.describe TRMNL::API::Endpoints::Palette do
|
||||
expect(result).to be_success(
|
||||
[
|
||||
TRMNL::API::Models::Palette[
|
||||
id: "test",
|
||||
name: "Test",
|
||||
name: "test",
|
||||
label: "Test",
|
||||
grays: 2,
|
||||
colors: %w[#000000 #FFFFFF],
|
||||
framework_class: "screen--1bit"
|
||||
|
||||
@@ -13,7 +13,15 @@ RSpec.describe TRMNL::API::Models::Palette do
|
||||
framework_class: "screen--1bit"
|
||||
}
|
||||
|
||||
expect(described_class.for(attributes)).to eq(described_class[**attributes])
|
||||
expect(described_class.for(attributes)).to eq(
|
||||
described_class[
|
||||
name: "test",
|
||||
label: "Test",
|
||||
grays: 2,
|
||||
colors: %w[#000000 #FFFFFF],
|
||||
framework_class: "screen--1bit"
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user