2018-12-05 19:51:30 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'email_spec'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Emails::Issues do
|
2018-12-05 19:51:30 -05:00
|
|
|
include EmailSpec::Matchers
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'adds email methods to Notify' do
|
|
|
|
subject.instance_methods.each do |email_method|
|
|
|
|
expect(Notify).to be_respond_to(email_method)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 19:51:30 -05:00
|
|
|
describe "#import_issues_csv_email" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
subject { Notify.import_issues_csv_email(user.id, project.id, @results) }
|
|
|
|
|
|
|
|
it "shows number of successful issues imported" do
|
2019-01-03 00:17:07 -05:00
|
|
|
@results = { success: 165, error_lines: [], parse_error: false }
|
2018-12-05 19:51:30 -05:00
|
|
|
|
|
|
|
expect(subject).to have_body_text "165 issues imported"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows error when file is invalid" do
|
2019-01-03 00:17:07 -05:00
|
|
|
@results = { success: 0, error_lines: [], parse_error: true }
|
2018-12-05 19:51:30 -05:00
|
|
|
|
|
|
|
expect(subject).to have_body_text "Error parsing CSV"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows line numbers with errors" do
|
2019-01-03 00:17:07 -05:00
|
|
|
@results = { success: 0, error_lines: [23, 34, 58], parse_error: false }
|
2018-12-05 19:51:30 -05:00
|
|
|
|
|
|
|
expect(subject).to have_body_text "23, 34, 58"
|
|
|
|
end
|
2019-02-20 10:18:15 -05:00
|
|
|
|
|
|
|
context 'with header and footer' do
|
|
|
|
let(:results) { { success: 165, error_lines: [], parse_error: false } }
|
|
|
|
|
|
|
|
subject { Notify.import_issues_csv_email(user.id, project.id, results) }
|
|
|
|
|
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
|
|
|
end
|
2018-12-05 19:51:30 -05:00
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
describe '#issues_csv_email' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:empty_project) { create(:project, path: 'myproject') }
|
|
|
|
let(:export_status) { { truncated: false, rows_expected: 3, rows_written: 3 } }
|
|
|
|
let(:attachment) { subject.attachments.first }
|
|
|
|
|
|
|
|
subject { Notify.issues_csv_email(user, empty_project, "dummy content", export_status) }
|
|
|
|
|
|
|
|
include_context 'gitlab email notification'
|
|
|
|
|
|
|
|
it 'attachment has csv mime type' do
|
|
|
|
expect(attachment.mime_type).to eq 'text/csv'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates a useful filename' do
|
|
|
|
expect(attachment.filename).to include(Date.today.year.to_s)
|
|
|
|
expect(attachment.filename).to include('issues')
|
|
|
|
expect(attachment.filename).to include('myproject')
|
|
|
|
expect(attachment.filename).to end_with('.csv')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'mentions number of issues and project name' do
|
|
|
|
expect(subject).to have_content '3'
|
|
|
|
expect(subject).to have_content empty_project.name
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't need to mention truncation by default" do
|
|
|
|
expect(subject).not_to have_content 'truncated'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when truncated' do
|
|
|
|
let(:export_status) { { truncated: true, rows_expected: 12, rows_written: 10 } }
|
|
|
|
|
|
|
|
it 'mentions that the csv has been truncated' do
|
|
|
|
expect(subject).to have_content 'truncated'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'mentions the number of issues written and expected' do
|
|
|
|
expect(subject).to have_content '10 of 12 issues'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 19:51:30 -05:00
|
|
|
end
|