Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registred company return not exists #2713

Merged
merged 16 commits into from
Nov 26, 2024
Merged
17 changes: 9 additions & 8 deletions app/interactions/actions/contact_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call
maybe_attach_legal_doc
validate_ident
maybe_change_email
maybe_company_is_relevant
# maybe_company_is_relevant
commit
validate_contact
end
Expand Down Expand Up @@ -78,15 +78,16 @@ def validate_ident_birthday
@error = true
end

def maybe_company_is_relevant
return true unless contact.org?
# def maybe_company_is_relevant
# return true unless contact.org?

company_status = contact.return_company_status
return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
# company_status = contact.return_company_status

contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))
@error = true
end
# return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
# contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))

# @error = true
# end

def maybe_attach_legal_doc
::Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false)
Expand Down
2 changes: 1 addition & 1 deletion app/models/contact/company_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def return_company_status
def return_company_data
return unless org?

company_register.simple_data(registration_number: ident)
company_register.simple_data(registration_number: ident.to_s)
rescue CompanyRegister::NotAvailableError
[]
end
Expand Down
70 changes: 61 additions & 9 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: btree_gin; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -2636,6 +2629,40 @@ CREATE SEQUENCE public.repp_logs_id_seq
ALTER SEQUENCE public.repp_logs_id_seq OWNED BY public.repp_logs.id;


--
-- Name: reserve_domain_invoices; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.reserve_domain_invoices (
id bigint NOT NULL,
invoice_number character varying,
domain_names character varying[] DEFAULT '{}'::character varying[],
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
status integer DEFAULT 0,
metainfo character varying
);


--
-- Name: reserve_domain_invoices_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.reserve_domain_invoices_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: reserve_domain_invoices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.reserve_domain_invoices_id_seq OWNED BY public.reserve_domain_invoices.id;


--
-- Name: reserved_domains; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3417,6 +3444,13 @@ ALTER TABLE ONLY public.registrars ALTER COLUMN id SET DEFAULT nextval('public.r
ALTER TABLE ONLY public.repp_logs ALTER COLUMN id SET DEFAULT nextval('public.repp_logs_id_seq'::regclass);


--
-- Name: reserve_domain_invoices id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.reserve_domain_invoices ALTER COLUMN id SET DEFAULT nextval('public.reserve_domain_invoices_id_seq'::regclass);


--
-- Name: reserved_domains id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3976,6 +4010,14 @@ ALTER TABLE ONLY public.repp_logs
ADD CONSTRAINT repp_logs_pkey PRIMARY KEY (id);


--
-- Name: reserve_domain_invoices reserve_domain_invoices_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.reserve_domain_invoices
ADD CONSTRAINT reserve_domain_invoices_pkey PRIMARY KEY (id);


--
-- Name: reserved_domains reserved_domains_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -4784,6 +4826,13 @@ CREATE INDEX index_registrant_verifications_on_created_at ON public.registrant_v
CREATE INDEX index_registrant_verifications_on_domain_id ON public.registrant_verifications USING btree (domain_id);


--
-- Name: index_reserve_domain_invoices_on_invoice_number; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_reserve_domain_invoices_on_invoice_number ON public.reserve_domain_invoices USING btree (invoice_number);


--
-- Name: index_setting_entries_on_code; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -5613,8 +5662,11 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230711083811'),
('20240816091049'),
('20240816092636'),
('20240903131540'),
('20240924103554'),
('20241015071505');
('20241015071505'),
('20241030095636'),
('20241104104620'),
('20241112093540'),
('20241112124405');


66 changes: 33 additions & 33 deletions test/integration/repp/v1/contacts/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,39 +188,39 @@ def test_returns_error_response_if_throttled
ENV['shunter_enabled'] = 'false'
end

def test_returns_error_response_if_company_not_existed
original_new_method = CompanyRegister::Client.method(:new)
CompanyRegister::Client.define_singleton_method(:new) do
object = original_new_method.call
def object.simple_data(registration_number:)
[Company.new('1234567', 'ACME Ltd', 'K')]
end
object
end

request_body = {
"contact": {
"name": 'Donald Trump',
"phone": '+372.51111112',
"email": '[email protected]',
"ident": {
"ident_type": 'org',
"ident_country_code": 'EE',
"ident": '70000313',
},
},
}

post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)

assert_response :bad_request
assert_equal 2003, json[:code]
puts json[:message]
assert json[:message].include? 'Company is not registered'

CompanyRegister::Client.define_singleton_method(:new, original_new_method)
end
# def test_returns_error_response_if_company_not_existed
# original_new_method = CompanyRegister::Client.method(:new)
# CompanyRegister::Client.define_singleton_method(:new) do
# object = original_new_method.call
# def object.simple_data(registration_number:)
# [Company.new('1234567', 'ACME Ltd', 'K')]
# end
# object
# end

# request_body = {
# "contact": {
# "name": 'Donald Trump',
# "phone": '+372.51111112',
# "email": '[email protected]',
# "ident": {
# "ident_type": 'org',
# "ident_country_code": 'EE',
# "ident": '70000313',
# },
# },
# }

# post '/repp/v1/contacts', headers: @auth_headers, params: request_body
# json = JSON.parse(response.body, symbolize_names: true)

# assert_response :bad_request
# assert_equal 2003, json[:code]
# puts json[:message]
# assert json[:message].include? 'Company is not registered'

# CompanyRegister::Client.define_singleton_method(:new, original_new_method)
# end

def test_contact_created_with_existed_company
original_new_method = CompanyRegister::Client.method(:new)
Expand Down
Loading