diff --git a/config/locales/en.yml b/config/locales/en.yml index e5d85f20fd..1f48a75b2f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2870,6 +2870,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using report_filters: Report Filters report_print: Print Report report_render_options: Rendering Options + report_header_ofn_uid: OFN UID report_header_order_cycle: Order Cycle report_header_user: User report_header_email: Email diff --git a/lib/reporting/reports/users_and_enterprises/base.rb b/lib/reporting/reports/users_and_enterprises/base.rb index 12ab4183a0..44a71aedf1 100644 --- a/lib/reporting/reports/users_and_enterprises/base.rb +++ b/lib/reporting/reports/users_and_enterprises/base.rb @@ -16,7 +16,8 @@ module Reporting is_producer: proc { |x| x.is_primary_producer }, sells: proc { |x| x.sells }, visible: proc { |x| x.visible }, - confirmation_date: proc { |x| x.created_at } + confirmation_date: proc { |x| x.created_at }, + ofn_uid: proc { |x| x.ofn_uid } } end @@ -46,7 +47,8 @@ module Reporting def query_helper(query, email_user, relationship_type) query.order("enterprises.created_at DESC") - .select(["enterprises.name", + .select(["enterprises.id AS ofn_uid", + "enterprises.name", "enterprises.sells", "enterprises.visible", "enterprises.is_primary_producer", diff --git a/spec/system/admin/reports/users_and_enterprises_spec.rb b/spec/system/admin/reports/users_and_enterprises_spec.rb new file mode 100644 index 0000000000..b9f8f0c0dc --- /dev/null +++ b/spec/system/admin/reports/users_and_enterprises_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'system_helper' + +describe "Users & Enterprises reports" do + include AuthenticationHelper + + let!(:enterprise) { create(:supplier_enterprise) } + + before do + login_as_admin + visit main_app.admin_report_path(report_type: 'users_and_enterprises') + end + + it "displays the report" do + find("[type='submit']").click + + expect(page.find("table.report__table thead tr").text).to have_content([ + "USER", + "RELATIONSHIP", + "ENTERPRISE", + "PRODUCER?", + "SELLS", + "VISIBLE", + "CONFIRMATION DATE", + "OFN UID" + ].join(" ")) + + row_i, row_ii = page.all("table.report__table tbody tr").map(&:text) + + expect(row_i).to have_content([ + enterprise.owner.email, + "owns", + enterprise.name, + "Yes", + "none", + "public", + enterprise.created_at.strftime("%Y-%m-%d %H:%M"), + enterprise.id + ].compact.join(" ")) + + expect(row_ii).to have_content([ + enterprise.owner.email, + "manages", + enterprise.name, + "Yes", + "none", + "public", + enterprise.created_at.strftime("%Y-%m-%d %H:%M"), + enterprise.id + ].compact.join(" ")) + end +end