From 0ad4748f0c88f993b7b58a7323d0d2f9d75b879d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 29 May 2023 09:48:41 +0200 Subject: [PATCH 1/8] start tests --- db/structure.sql | 52 +++++++++++++++++++ .../requests/upvs/submissions_request_spec.rb | 39 ++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 spec/requests/upvs/submissions_request_spec.rb diff --git a/db/structure.sql b/db/structure.sql index 8d8fa562..22e99246 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1325,6 +1325,41 @@ CREATE SEQUENCE upvs.form_template_related_documents_id_seq ALTER SEQUENCE upvs.form_template_related_documents_id_seq OWNED BY upvs.form_template_related_documents.id; +-- +-- Name: form_template_related_documents_temp; Type: TABLE; Schema: upvs; Owner: - +-- + +CREATE TABLE upvs.form_template_related_documents_temp ( + id bigint NOT NULL, + posp_id character varying NOT NULL, + posp_version character varying NOT NULL, + message_type character varying NOT NULL, + xsd_schema text, + xslt_transformation text, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: form_template_related_documents_temp_id_seq; Type: SEQUENCE; Schema: upvs; Owner: - +-- + +CREATE SEQUENCE upvs.form_template_related_documents_temp_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: form_template_related_documents_temp_id_seq; Type: SEQUENCE OWNED BY; Schema: upvs; Owner: - +-- + +ALTER SEQUENCE upvs.form_template_related_documents_temp_id_seq OWNED BY upvs.form_template_related_documents_temp.id; + + -- -- Name: submissions; Type: TABLE; Schema: upvs; Owner: - -- @@ -1581,6 +1616,13 @@ ALTER TABLE ONLY upvs.egov_application_allow_rules ALTER COLUMN id SET DEFAULT n ALTER TABLE ONLY upvs.form_template_related_documents ALTER COLUMN id SET DEFAULT nextval('upvs.form_template_related_documents_id_seq'::regclass); +-- +-- Name: form_template_related_documents_temp id; Type: DEFAULT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.form_template_related_documents_temp ALTER COLUMN id SET DEFAULT nextval('upvs.form_template_related_documents_temp_id_seq'::regclass); + + -- -- Name: submissions id; Type: DEFAULT; Schema: upvs; Owner: - -- @@ -1860,6 +1902,14 @@ ALTER TABLE ONLY upvs.form_template_related_documents ADD CONSTRAINT form_template_related_documents_pkey PRIMARY KEY (id); +-- +-- Name: form_template_related_documents_temp form_template_related_documents_temp_pkey; Type: CONSTRAINT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.form_template_related_documents_temp + ADD CONSTRAINT form_template_related_documents_temp_pkey PRIMARY KEY (id); + + -- -- Name: submissions submissions_pkey; Type: CONSTRAINT; Schema: upvs; Owner: - -- @@ -1867,6 +1917,8 @@ ALTER TABLE ONLY upvs.form_template_related_documents ALTER TABLE ONLY upvs.submissions ADD CONSTRAINT submissions_pkey PRIMARY KEY (id); + +-- -- Name: index_active_storage_attachments_on_blob_id; Type: INDEX; Schema: public; Owner: - -- diff --git a/spec/requests/upvs/submissions_request_spec.rb b/spec/requests/upvs/submissions_request_spec.rb new file mode 100644 index 00000000..872cfaa4 --- /dev/null +++ b/spec/requests/upvs/submissions_request_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe "Upvs::Submissions", type: :request do + describe "POST create" do + context "with valid params" do + let(:valid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: 'recipient_uri', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + it "creates a new Submission" do + expect { + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + }.to change(Upvs::Submission, :count).by(1) + end + + it "redirects to the created submission" do + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + expect(response).to redirect_to(upvs_submission_path(Upvs::Submission.last)) + end + + it "creates a new Submission that expires in 20 minutes" do + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + expect(Upvs::Submission.last.expires_at).to be <= 20.minutes.from_now + expect(Upvs::Submission.last.expires_at).to be > 19.minutes.from_now + end + end + + # TODO: test with invalid params + end + +end From 00a31929862e84ae22a0374ea6fcb117ed78cbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Tue, 27 Jun 2023 18:06:14 +0200 Subject: [PATCH 2/8] test progress --- .../upvs/submissions_controller.rb | 34 ++--------- app/models/upvs/submission.rb | 46 ++++++++++++-- spec/factories/upvs_submissions.rb | 5 ++ spec/models/upvs/submission_spec.rb | 28 +++++++++ .../requests/upvs/submissions_request_spec.rb | 61 ++++++++++++++++++- 5 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 spec/factories/upvs_submissions.rb create mode 100644 spec/models/upvs/submission_spec.rb diff --git a/app/controllers/upvs/submissions_controller.rb b/app/controllers/upvs/submissions_controller.rb index 4b89d855..4752263e 100644 --- a/app/controllers/upvs/submissions_controller.rb +++ b/app/controllers/upvs/submissions_controller.rb @@ -35,17 +35,11 @@ def switch_account_callback def submit return switch_account_callback unless eid_token&.valid? # If token expires meanwhile - if @upvs_submission.valid? - response = submit_to_sk_api - - if successful_sk_api_submission?(response) - if @upvs_submission.callback_url.present? - redirect_to @upvs_submission.callback_url - else - redirect_to action: :finish - end + if @upvs_submission.submit + if @upvs_submission.callback_url.present? + redirect_to @upvs_submission.callback_url else - raise Upvs::Submission::SkApiError.new + redirect_to action: :finish end else render :new, status: :unprocessable_entity @@ -53,7 +47,6 @@ def submit end def finish - @upvs_submission.update(expires_at: Time.zone.now) end def submission_error @@ -76,25 +69,6 @@ def set_metadata @metadata.og.title = params[:title] || 'Návody.Digital: Podanie' # TODO end - def submit_to_sk_api(client: Faraday) - begin - headers = { "Content-Type": "application/json" } - data = { message: UpvsSubmissions::SktalkMessageBuilder.new.build_sktalk_message(@upvs_submission, eid_token) }.to_json - url = "#{ENV.fetch('SLOVENSKO_SK_API_URL')}/api/sktalk/receive_and_save_to_outbox?token=#{eid_token&.api_token}" - - client.post(url, data, headers) - rescue Exception - raise Upvs::Submission::SkApiError.new - end - end - - def successful_sk_api_submission?(response) - json_body = JSON.parse(response.body) - - return true if (response.status == 200 && json_body["receive_result"] == 0 && json_body["save_to_outbox_result"] == 0) - false - end - def build_upvs_submission @upvs_submission = current_user.build_upvs_submission( submission_params, diff --git a/app/models/upvs/submission.rb b/app/models/upvs/submission.rb index fb437237..f1c5d3ea 100644 --- a/app/models/upvs/submission.rb +++ b/app/models/upvs/submission.rb @@ -31,10 +31,10 @@ class Upvs::Submission < ApplicationRecord before_create { self.uuid = SecureRandom.uuid } # TODO ensure unique in loop before_create { set_new_expiration_time } - validates_presence_of :posp_id, :posp_version, :message_type, :recipient_uri, :message_subject, :form - validate :recipient_uri_allowed?, if: -> { Rails.env.production? } - validate :egov_application_allowed?, if: -> { Rails.env.production? } - validate :valid_xml_form? + validates_presence_of :posp_id, :posp_version, :message_type, :recipient_uri, :message_subject, :form, on: :create + validate :recipient_uri_allowed?, if: -> { Rails.env.production? }, on: :create + validate :egov_application_allowed?, if: -> { Rails.env.production? }, on: :create + validate :valid_xml_form?, on: :create scope :expired, -> { where('expires_at < ?', Time.zone.now) } @@ -68,8 +68,44 @@ def to_param uuid end + def submit(eid_token, client: Faraday) + return false unless valid? + + url = "#{ENV.fetch('SLOVENSKO_SK_API_URL')}/api/sktalk/receive_and_save_to_outbox?token=#{eid_token&.api_token}" + response = submit_to_sk_api(client, url) + + if successful_sk_api_submission?(response) + update(expires_at: Time.zone.now) + return true + else + raise Upvs::Submission::SkApiError.new + end + end + private + def validate + false unless valid? + end + + def submit_to_sk_api(client, url) + begin + headers = { "Content-Type": "application/json" } + data = { message: UpvsSubmissions::SktalkMessageBuilder.new.build_sktalk_message(@upvs_submission, eid_token) }.to_json + + client.post(url, data, headers) + rescue Exception + raise Upvs::Submission::SkApiError.new + end + end + + def successful_sk_api_submission?(response) + json_body = JSON.parse(response.body) + + return true if (response.status == 200 && json_body["receive_result"] == 0 && json_body["save_to_outbox_result"] == 0) + false + end + def set_new_expiration_time self.expires_at = Time.zone.now + 20.minutes end @@ -97,7 +133,7 @@ def recipient_uri_allowed? end def valid_xml_form? - unless Nokogiri::XML(@form).errors.empty? + unless Nokogiri::XML(form).errors.empty? errors.add(:form, "Nevalidný XML formulár") end end diff --git a/spec/factories/upvs_submissions.rb b/spec/factories/upvs_submissions.rb new file mode 100644 index 00000000..b13ea5cd --- /dev/null +++ b/spec/factories/upvs_submissions.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :upvs_submission do + + end +end diff --git a/spec/models/upvs/submission_spec.rb b/spec/models/upvs/submission_spec.rb new file mode 100644 index 00000000..8b502365 --- /dev/null +++ b/spec/models/upvs/submission_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +RSpec.describe Upvs::Submission, type: :model do + context 'with valid attributes' do + let(:valid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: 'recipient_uri', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + before do + submission = described_class.new(valid_attributes) + end + + it 'is valid' do + expect(submission).to be_valid + expect(submission.save).to be_truthy + expect(Upvs::Submission.last.expires_at).to be <= 20.minutes.from_now + expect(Upvs::Submission.last.expires_at).to be > 19.minutes.from_now + end + end +end diff --git a/spec/requests/upvs/submissions_request_spec.rb b/spec/requests/upvs/submissions_request_spec.rb index 872cfaa4..bdacd431 100644 --- a/spec/requests/upvs/submissions_request_spec.rb +++ b/spec/requests/upvs/submissions_request_spec.rb @@ -33,7 +33,66 @@ end end - # TODO: test with invalid params + context 'with empty recipient_uri' do + let(:invalid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: '', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + it 'raises ActiveRecord::RecordInvalid' do + expect { + post upvs_submissions_path, params: { upvs_submission: invalid_attributes } + }.to raise_error(ActiveRecord::RecordInvalid) + end + end + + context 'with invalid xml form' do + let(:invalid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: 'recipient_uri', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + it 'raises ActiveRecord::RecordInvalid' do + expect { + post upvs_submissions_path, params: { upvs_submission: invalid_attributes } + }.to raise_error(ActiveRecord::RecordInvalid) + end + end end + describe "GET show" do + let(:valid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: 'recipient_uri', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + it "renders the show template" do + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + + expect { + get upvs_submission_path(Upvs::Submission.last) + }.to raise_error(ActionView::Template::Error) + end + end end From e5a538214f0e0cafa3c6c9547124cb57d009cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Tue, 4 Jul 2023 10:58:38 +0200 Subject: [PATCH 3/8] tests wip --- app/models/upvs/submission.rb | 3 +-- spec/models/upvs/submission_spec.rb | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/models/upvs/submission.rb b/app/models/upvs/submission.rb index f1c5d3ea..bebb2494 100644 --- a/app/models/upvs/submission.rb +++ b/app/models/upvs/submission.rb @@ -68,10 +68,9 @@ def to_param uuid end - def submit(eid_token, client: Faraday) + def submit(eid_token, client: Faraday, url: "#{ENV.fetch('SLOVENSKO_SK_API_URL')}/api/sktalk/receive_and_save_to_outbox?token=#{eid_token&.api_token}") return false unless valid? - url = "#{ENV.fetch('SLOVENSKO_SK_API_URL')}/api/sktalk/receive_and_save_to_outbox?token=#{eid_token&.api_token}" response = submit_to_sk_api(client, url) if successful_sk_api_submission?(response) diff --git a/spec/models/upvs/submission_spec.rb b/spec/models/upvs/submission_spec.rb index 8b502365..b1059712 100644 --- a/spec/models/upvs/submission_spec.rb +++ b/spec/models/upvs/submission_spec.rb @@ -14,15 +14,29 @@ } end - before do - submission = described_class.new(valid_attributes) - end - it 'is valid' do + submission = described_class.new(valid_attributes) expect(submission).to be_valid expect(submission.save).to be_truthy expect(Upvs::Submission.last.expires_at).to be <= 20.minutes.from_now expect(Upvs::Submission.last.expires_at).to be > 19.minutes.from_now end + + context 'submit' do + let(:submission) { described_class.new(valid_attributes) } + + it 'is valid' do + response_dbl = instance_double('Faraday::Response') + allow(Faraday).to receive(:post) + .with('https://testing.stub.com/') + .and_return(response_dbl) + # stub body method on response object to return a canned response for Paris weather + allow(response_dbl).to receive(:body) + .and_return('{"receive_result":0, "save_to_outbox_result":0}') + + + expect(submission.submit(nil, Faraday, 'https://testing.stub.com/')).to be_truthy + end + end end end From 17c49ae16f34078611d36826eec1be94652393d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 11 Sep 2023 10:08:35 +0200 Subject: [PATCH 4/8] add upvs submission spec --- Gemfile | 2 + Gemfile.lock | 5 + .../upvs/submissions_controller.rb | 2 +- app/models/upvs/submission.rb | 6 +- .../requests/upvs/submissions_request_spec.rb | 140 +++++++++++------- 5 files changed, 100 insertions(+), 55 deletions(-) diff --git a/Gemfile b/Gemfile index aacfd44a..fa9e87fb 100644 --- a/Gemfile +++ b/Gemfile @@ -108,3 +108,5 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'hirb' + +gem "rails-controller-testing", "~> 1.0" diff --git a/Gemfile.lock b/Gemfile.lock index c739a434..2a18bb2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -317,6 +317,10 @@ GEM bundler (>= 1.15.0) railties (= 6.1.7.3) sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -490,6 +494,7 @@ DEPENDENCIES que que-web rails (~> 6.1.7.3) + rails-controller-testing (~> 1.0) rails-i18n recaptcha rollbar diff --git a/app/controllers/upvs/submissions_controller.rb b/app/controllers/upvs/submissions_controller.rb index 4752263e..af6b9232 100644 --- a/app/controllers/upvs/submissions_controller.rb +++ b/app/controllers/upvs/submissions_controller.rb @@ -35,7 +35,7 @@ def switch_account_callback def submit return switch_account_callback unless eid_token&.valid? # If token expires meanwhile - if @upvs_submission.submit + if @upvs_submission.submit(eid_token) if @upvs_submission.callback_url.present? redirect_to @upvs_submission.callback_url else diff --git a/app/models/upvs/submission.rb b/app/models/upvs/submission.rb index bebb2494..eadf849e 100644 --- a/app/models/upvs/submission.rb +++ b/app/models/upvs/submission.rb @@ -71,7 +71,7 @@ def to_param def submit(eid_token, client: Faraday, url: "#{ENV.fetch('SLOVENSKO_SK_API_URL')}/api/sktalk/receive_and_save_to_outbox?token=#{eid_token&.api_token}") return false unless valid? - response = submit_to_sk_api(client, url) + response = submit_to_sk_api(client, url, eid_token) if successful_sk_api_submission?(response) update(expires_at: Time.zone.now) @@ -87,10 +87,10 @@ def validate false unless valid? end - def submit_to_sk_api(client, url) + def submit_to_sk_api(client, url, eid_token) begin headers = { "Content-Type": "application/json" } - data = { message: UpvsSubmissions::SktalkMessageBuilder.new.build_sktalk_message(@upvs_submission, eid_token) }.to_json + data = { message: UpvsSubmissions::SktalkMessageBuilder.new.build_sktalk_message(self, eid_token) }.to_json client.post(url, data, headers) rescue Exception diff --git a/spec/requests/upvs/submissions_request_spec.rb b/spec/requests/upvs/submissions_request_spec.rb index bdacd431..cf958f1e 100644 --- a/spec/requests/upvs/submissions_request_spec.rb +++ b/spec/requests/upvs/submissions_request_spec.rb @@ -1,20 +1,57 @@ require 'rails_helper' RSpec.describe "Upvs::Submissions", type: :request do + let(:valid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: 'foo://bar', + message_subject: 'message_subject', + form: '
9
', + title: 'title' + } + end + + let(:invalid_attributes) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + recipient_uri: '', + message_subject: 'message_subject', + form: '
', + title: 'title' + } + end + + let(:form_template) do + { + posp_id: 'posp_id', + posp_version: 'posp_version', + message_type: 'message_type', + xsd_schema: ' + ', + xslt_transformation: ' + + + + + + + + + + ' + } + end + + before do + Upvs::FormTemplateRelatedDocument.create!(form_template) + end + describe "POST create" do context "with valid params" do - let(:valid_attributes) do - { - posp_id: 'posp_id', - posp_version: 'posp_version', - message_type: 'message_type', - recipient_uri: 'recipient_uri', - message_subject: 'message_subject', - form: '
', - title: 'title' - } - end - it "creates a new Submission" do expect { post upvs_submissions_path, params: { upvs_submission: valid_attributes } @@ -34,18 +71,6 @@ end context 'with empty recipient_uri' do - let(:invalid_attributes) do - { - posp_id: 'posp_id', - posp_version: 'posp_version', - message_type: 'message_type', - recipient_uri: '', - message_subject: 'message_subject', - form: '
', - title: 'title' - } - end - it 'raises ActiveRecord::RecordInvalid' do expect { post upvs_submissions_path, params: { upvs_submission: invalid_attributes } @@ -54,18 +79,6 @@ end context 'with invalid xml form' do - let(:invalid_attributes) do - { - posp_id: 'posp_id', - posp_version: 'posp_version', - message_type: 'message_type', - recipient_uri: 'recipient_uri', - message_subject: 'message_subject', - form: '
', - title: 'title' - } - end - it 'raises ActiveRecord::RecordInvalid' do expect { post upvs_submissions_path, params: { upvs_submission: invalid_attributes } @@ -75,24 +88,49 @@ end describe "GET show" do - let(:valid_attributes) do - { - posp_id: 'posp_id', - posp_version: 'posp_version', - message_type: 'message_type', - recipient_uri: 'recipient_uri', - message_subject: 'message_subject', - form: '
', - title: 'title' - } + context "with existing submission and no token" do + it "renders the show template" do + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + get upvs_submission_path(Upvs::Submission.last) + expect(response).to render_template(:show) + end + end + + context "with existing submission and valid token" do + it "renders the show template" do + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + get upvs_submission_path(Upvs::Submission.last), params: { token: "sadfasd" } + expect(response).to render_template(:show) + end end + end - it "renders the show template" do - post upvs_submissions_path, params: { upvs_submission: valid_attributes } + describe "POST submit" do - expect { - get upvs_submission_path(Upvs::Submission.last) - }.to raise_error(ActionView::Template::Error) + context "with valid params" do + it "redirects to the callback url" do + # stub valid eid_token + allow_any_instance_of(EidToken).to receive(:valid?).and_return(true) + allow_any_instance_of(EidToken).to receive(:api_token).and_return("eid_token") + allow_any_instance_of(EidToken).to receive(:subject_sub).and_return("subject_sub") + allow_any_instance_of(EidToken).to receive(:subject_name).and_return("Test User") + # stub request to sk api + allow_any_instance_of(Faraday::Connection).to receive(:post).and_return(OpenStruct.new(body: { "receive_result" => 0, "save_to_outbox_result" => 0 }.to_json, status: 200)) + + post upvs_submissions_path, params: { upvs_submission: valid_attributes } + get upvs_submission_path(Upvs::Submission.last), params: { token: "token" } + expect(response.body).to include("Prihlásiť sa pomocou slovensko.sk") + + get login_callback_upvs_submissions_path(Upvs::Submission.last), params: { token: "eid_token" } + expect(response).to redirect_to upvs_submission_path(Upvs::Submission.last, token: "token") + expect(session[:eid_encoded_token]).to eq("eid_token") + + get upvs_submission_path(Upvs::Submission.last), params: { token: "token" } + expect(response.body).to include("Odoslať ako Test User") + + post upvs_submission_submit_path(Upvs::Submission.last), params: { :token => "asdfasdf", eid_token: "asdfasdf" } + expect(response.location).to redirect_to upvs_submission_finish_path(Upvs::Submission.last) + end end end end From 682f060a222c7a81e2ad63c19814ebd70af3e931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 11 Sep 2023 10:13:28 +0200 Subject: [PATCH 5/8] rm upvs_submissions factory --- spec/factories/upvs_submissions.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 spec/factories/upvs_submissions.rb diff --git a/spec/factories/upvs_submissions.rb b/spec/factories/upvs_submissions.rb deleted file mode 100644 index b13ea5cd..00000000 --- a/spec/factories/upvs_submissions.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :upvs_submission do - - end -end From 0557ec08e1d0ae719c0b145cc4e7f93daacebc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 11 Sep 2023 10:42:52 +0200 Subject: [PATCH 6/8] add datahub db to tests --- config/database.yml | 1 - db/datahub_structure.sql | 169 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 db/datahub_structure.sql diff --git a/config/database.yml b/config/database.yml index c8d310b0..f97b7d50 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,7 +21,6 @@ test: datahub: <<: *default database: datahub_test - replica: true staging: primary: diff --git a/db/datahub_structure.sql b/db/datahub_structure.sql new file mode 100644 index 00000000..a4ab03df --- /dev/null +++ b/db/datahub_structure.sql @@ -0,0 +1,169 @@ +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: upvs; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA upvs; + + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: public_authority_edesks; Type: TABLE; Schema: upvs; Owner: - +-- + +CREATE TABLE upvs.public_authority_edesks ( + id integer NOT NULL, + cin bigint NOT NULL, + uri character varying NOT NULL, + name character varying NOT NULL, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +-- +-- Name: public_authority_edesks_id_seq; Type: SEQUENCE; Schema: upvs; Owner: - +-- + +CREATE SEQUENCE upvs.public_authority_edesks_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: public_authority_edesks_id_seq; Type: SEQUENCE OWNED BY; Schema: upvs; Owner: - +-- + +ALTER SEQUENCE upvs.public_authority_edesks_id_seq OWNED BY upvs.public_authority_edesks.id; + + +-- +-- Name: services_with_forms; Type: TABLE; Schema: upvs; Owner: - +-- + +CREATE TABLE upvs.services_with_forms ( + id integer NOT NULL, + instance_id integer NOT NULL, + external_code character varying, + meta_is_code character varying, + name character varying, + type character varying, + institution_uri character varying NOT NULL, + institution_name character varying, + valid_from timestamp without time zone, + valid_to timestamp without time zone, + url character varying, + info_url character varying, + schema_url character varying, + changed_at timestamp without time zone, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +-- +-- Name: services_with_forms_id_seq; Type: SEQUENCE; Schema: upvs; Owner: - +-- + +CREATE SEQUENCE upvs.services_with_forms_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: services_with_forms_id_seq; Type: SEQUENCE OWNED BY; Schema: upvs; Owner: - +-- + +ALTER SEQUENCE upvs.services_with_forms_id_seq OWNED BY upvs.services_with_forms.id; + +-- +-- Name: public_authority_edesks id; Type: DEFAULT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.public_authority_edesks ALTER COLUMN id SET DEFAULT nextval('upvs.public_authority_edesks_id_seq'::regclass); + + +-- +-- Name: services_with_forms id; Type: DEFAULT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.services_with_forms ALTER COLUMN id SET DEFAULT nextval('upvs.services_with_forms_id_seq'::regclass); + + +-- +-- Name: public_authority_edesks public_authority_edesks_pkey; Type: CONSTRAINT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.public_authority_edesks + ADD CONSTRAINT public_authority_edesks_pkey PRIMARY KEY (id); + + +-- +-- Name: services_with_forms services_with_forms_pkey; Type: CONSTRAINT; Schema: upvs; Owner: - +-- + +ALTER TABLE ONLY upvs.services_with_forms + ADD CONSTRAINT services_with_forms_pkey PRIMARY KEY (id); + + +-- +-- Name: index_upvs.public_authority_edesks_on_cin; Type: INDEX; Schema: upvs; Owner: - +-- + +CREATE INDEX "index_upvs.public_authority_edesks_on_cin" ON upvs.public_authority_edesks USING btree (cin); + + +-- +-- Name: index_upvs.public_authority_edesks_on_uri; Type: INDEX; Schema: upvs; Owner: - +-- + +CREATE UNIQUE INDEX "index_upvs.public_authority_edesks_on_uri" ON upvs.public_authority_edesks USING btree (uri); + + +-- +-- Name: index_upvs.services_with_forms_on_instance_id; Type: INDEX; Schema: upvs; Owner: - +-- + +CREATE UNIQUE INDEX "index_upvs.services_with_forms_on_instance_id" ON upvs.services_with_forms USING btree (instance_id); + + +-- +-- Name: index_upvs.services_with_forms_on_institution_uri; Type: INDEX; Schema: upvs; Owner: - +-- + +CREATE INDEX "index_upvs.services_with_forms_on_institution_uri" ON upvs.services_with_forms USING btree (institution_uri); + + +-- +-- Name: index_upvs.services_with_forms_on_schema_url; Type: INDEX; Schema: upvs; Owner: - +-- + +CREATE INDEX "index_upvs.services_with_forms_on_schema_url" ON upvs.services_with_forms USING btree (schema_url); + + +-- +-- PostgreSQL database dump complete +-- + +SET search_path TO "$user", public; From 9ed1b2f11ff15dc94a29c166cfb42f24aaa73200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 11 Sep 2023 11:08:48 +0200 Subject: [PATCH 7/8] fix upvs submission model spec --- spec/models/upvs/submission_spec.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/models/upvs/submission_spec.rb b/spec/models/upvs/submission_spec.rb index b1059712..6d518fb2 100644 --- a/spec/models/upvs/submission_spec.rb +++ b/spec/models/upvs/submission_spec.rb @@ -28,14 +28,10 @@ it 'is valid' do response_dbl = instance_double('Faraday::Response') allow(Faraday).to receive(:post) - .with('https://testing.stub.com/') - .and_return(response_dbl) - # stub body method on response object to return a canned response for Paris weather - allow(response_dbl).to receive(:body) - .and_return('{"receive_result":0, "save_to_outbox_result":0}') + .and_return(OpenStruct.new(body: { "receive_result" => 0, "save_to_outbox_result" => 0 }.to_json, status: 200)) - - expect(submission.submit(nil, Faraday, 'https://testing.stub.com/')).to be_truthy + allow_any_instance_of(EidToken).to receive(:subject_sub).and_return("subject_sub") + expect(submission.submit(EidToken.new("eid_token", config: nil), client: Faraday, url: 'https://testing.stub.com/')).to be_truthy end end end From a654391696828f4cfd35476ae9aa5483e73e3f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ce=C4=BEuch?= Date: Mon, 11 Sep 2023 11:16:54 +0200 Subject: [PATCH 8/8] add test env value for sk api url to GH workflow --- .github/workflows/slovensko_digital_ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/slovensko_digital_ci.yml b/.github/workflows/slovensko_digital_ci.yml index 20383352..024d406c 100644 --- a/.github/workflows/slovensko_digital_ci.yml +++ b/.github/workflows/slovensko_digital_ci.yml @@ -1,11 +1,11 @@ name: Slovensko.Digital CI -on: - push: +on: + push: branches: master pull_request: branches: '**' - + jobs: test: runs-on: ubuntu-latest @@ -13,6 +13,7 @@ jobs: env: PGHOST: localhost RAILS_ENV: test + SLOVENSKO_SK_API_URL: https://test.slovensko.digital services: postgres: