docbrown/spec/requests/admin/users/users_export_spec.rb
Ridhwana aff29406ac
First version of exporting the Users to a CSV (#17217)
* feat: add the export route

* feat: base export csv

* refactor: move the svg into its own file

* feat: add the export partial

* feat: export teh correct fields etc. for the csv

* user status helper

* feat: ensure that we format the time

* feat: add a spec for the CSV

* remove space

* remove puts

* chore: remove blank space

* feat: update traits

* Update app/views/admin/users/export.csv.erb

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

* Update spec/requests/admin/users/users_export_spec.rb

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

* Update spec/requests/admin/users/users_export_spec.rb

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

* fix: export should not error for unregistered users

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
2022-04-12 15:24:32 +02:00

41 lines
1.4 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/users/export", type: :request do
let(:admin) do
create(:user, :super_admin,
name: "Admin1", username: "admin1", email: "admin1@gmail.com",
registered_at: "2020-05-06T13:09:47+0000")
end
let!(:user) do
create(:user, :org_member,
name: "John Doe", username: "john_doe", email: "john_doe@gmail.com",
registered_at: "2020-06-08T13:09:47+0000")
end
before do
sign_in(admin)
get "#{export_admin_users_path}.csv"
end
it "renders successfully" do
expect(response).to have_http_status :ok
end
it "renders the headers" do
expect(response.body).to include("Name,Username,Email address,Status,Joining date,Last activity,Organizations")
end
it "shows the correct number of total rows" do
# This takes into account empty lines after each row
expect(response.body.lines.count).to eq(3)
end
it "shows the correct fields", :aggregate_failures do
expect(response.body).to include('Admin1,admin1,admin1@gmail.com,Good Standing,"06 May, 2020","06 May, 2020",[]')
# rubocop:disable Style/PercentLiteralDelimiters, Layout/LineLength
expect(response.body).to include(
%{John Doe,john_doe,john_doe@gmail.com,Good Standing,"08 Jun, 2020","08 Jun, 2020","[""#{user.organizations.first.name}""]"},
)
# rubocop:enable Style/PercentLiteralDelimiters, Layout/LineLength
end
end