Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/amocrm/models/custom_field_get_by_id_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CustomField < Amocrm::Internal::Type::BaseModel
# @!attribute code
#
# @return [String, nil]
optional :code, String
optional :code, String, nil?: true

# @!attribute entity_type
#
Expand All @@ -34,7 +34,7 @@ class CustomField < Amocrm::Internal::Type::BaseModel
# @!attribute group_id
#
# @return [Integer, nil]
optional :group_id, Integer
optional :group_id, Integer, nil?: true

# @!attribute is_deletable
#
Expand Down Expand Up @@ -78,10 +78,10 @@ class CustomField < Amocrm::Internal::Type::BaseModel

# @!method initialize(id: nil, code: nil, entity_type: nil, enums: nil, group_id: nil, is_deletable: nil, is_multiple: nil, is_required: nil, is_visible: nil, name: nil, settings: nil, sort: nil, type: nil)
# @param id [Integer]
# @param code [String]
# @param code [String, nil]
# @param entity_type [String]
# @param enums [Array<Object>]
# @param group_id [Integer]
# @param group_id [Integer, nil]
# @param is_deletable [Boolean]
# @param is_multiple [Boolean]
# @param is_required [Boolean]
Expand Down
12 changes: 6 additions & 6 deletions rbi/amocrm/models/custom_field_get_by_id_response.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Amocrm
sig { returns(T.nilable(String)) }
attr_reader :code

sig { params(code: String).void }
sig { params(code: T.nilable(String)).void }
attr_writer :code

sig { returns(T.nilable(String)) }
Expand All @@ -49,7 +49,7 @@ module Amocrm
sig { returns(T.nilable(Integer)) }
attr_reader :group_id

sig { params(group_id: Integer).void }
sig { params(group_id: T.nilable(Integer)).void }
attr_writer :group_id

sig { returns(T.nilable(T::Boolean)) }
Expand Down Expand Up @@ -103,10 +103,10 @@ module Amocrm
sig do
params(
id: Integer,
code: String,
code: T.nilable(String),
entity_type: String,
enums: T::Array[T.anything],
group_id: Integer,
group_id: T.nilable(Integer),
is_deletable: T::Boolean,
is_multiple: T::Boolean,
is_required: T::Boolean,
Expand Down Expand Up @@ -138,10 +138,10 @@ module Amocrm
override.returns(
{
id: Integer,
code: String,
code: T.nilable(String),
entity_type: String,
enums: T::Array[T.anything],
group_id: Integer,
group_id: T.nilable(Integer),
is_deletable: T::Boolean,
is_multiple: T::Boolean,
is_required: T::Boolean,
Expand Down
16 changes: 8 additions & 8 deletions sig/amocrm/models/custom_field_get_by_id_response.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module Amocrm
type custom_field =
{
id: Integer,
code: String,
code: String?,
entity_type: String,
enums: ::Array[top],
group_id: Integer,
group_id: Integer?,
is_deletable: bool,
is_multiple: bool,
is_required: bool,
Expand All @@ -31,7 +31,7 @@ module Amocrm

attr_reader code: String?

def code=: (String) -> String
def code=: (String?) -> String?

attr_reader entity_type: String?

Expand All @@ -43,7 +43,7 @@ module Amocrm

attr_reader group_id: Integer?

def group_id=: (Integer) -> Integer
def group_id=: (Integer?) -> Integer?

attr_reader is_deletable: bool?

Expand Down Expand Up @@ -79,10 +79,10 @@ module Amocrm

def initialize: (
?id: Integer,
?code: String,
?code: String?,
?entity_type: String,
?enums: ::Array[top],
?group_id: Integer,
?group_id: Integer?,
?is_deletable: bool,
?is_multiple: bool,
?is_required: bool,
Expand All @@ -95,10 +95,10 @@ module Amocrm

def to_hash: -> {
id: Integer,
code: String,
code: String?,
entity_type: String,
enums: ::Array[top],
group_id: Integer,
group_id: Integer?,
is_deletable: bool,
is_multiple: bool,
is_required: bool,
Expand Down
54 changes: 54 additions & 0 deletions test/amocrm/models/custom_field_get_by_id_response_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require_relative "../test_helper"

class Amocrm::Test::CustomFieldGetByIDResponseModelTest < Minitest::Test
extend Minitest::Serial
include WebMock::API

def before_all
super
WebMock.enable!
end

def teardown
WebMock.reset!
super
end

def after_all
WebMock.disable!
super
end

# amoCRM answers with an explicit null for code and group_id; the success
# variant must still win the union instead of being read as a Problem.
def test_get_by_id_with_null_fields_is_a_custom_field
stub_request(:get, "http://localhost/api/v4/leads/custom_fields/921871")
.to_return_json(
status: 200,
body: {
id: 921_871,
name: "stack",
type: "select",
code: nil,
group_id: nil,
currency: nil,
tracking_callback: nil,
remind: nil,
chained_lists: nil,
enums: [{id: 1, value: "ruby"}]
}
)

response = client.custom_fields.get_by_id(921_871, entity_type: "leads")

assert_instance_of(Amocrm::Models::CustomFieldGetByIDResponse::CustomField, response)
assert_equal("stack", response.name)
assert_equal(1, response.enums.size)
end

private

def client = Amocrm::Client.new(base_url: "http://localhost", token: "t", subdomain: "s", max_retries: 0)
end
Loading