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

SRCH-2243 change bulk upload email error message order #758

Merged
merged 5 commits into from
Aug 3, 2021
Merged

SRCH-2243 change bulk upload email error message order #758

merged 5 commits into from
Aug 3, 2021

Conversation

jmax-fearless
Copy link
Contributor

SRCH-2243 change bulk upload email error message order.

Make 'Url already taken' errors appear after all other errors.

@MothOnMars
Copy link
Contributor

@jmax-fearless , please squash the commits into a single commit that includes the Jira ticket # in the commit message.

Made 'Url already taken' messages show last in the email
Comment on lines +80 to +87
it 'shows the urls with error "url already taken" after all the other errors' do
first_error_message_position = mail_body.index(first_error_message)
second_error_message_position = mail_body.index(second_error_message)
already_taken_error_message_position = mail_body.index(already_taken_error_message)

expect(already_taken_error_message_position).to be > first_error_message_position
expect(already_taken_error_message_position).to be > second_error_message_position
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmax-fearless , this is not a valid spec, because it passes without any of the changes in spec/services/bulk_url_uploader_spec.rb. The before block sets the errors in the correct order, so the spec is testing errors that are already in the expected order:

      before do
        results.add_error(first_error_message, first_bad_url)
        results.add_error(second_error_message, second_bad_url)
        results.add_error(already_taken_error_message, duplicate_url)
      end

Please add a valid spec using TDD. As the results are being ordered in BulkUrlUploader::Results, you could add a unit test for that class, rather than testing this via the mailer.

Copy link
Contributor Author

@jmax-fearless jmax-fearless Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not comfortable removing the mailer spec, but I agree that a unit test for this would be a fine thing. So I added one, and also re-arranged the order of add_error calls per your comment. Both tests fail if you remove the changes to #error_messages

app/services/bulk_url_uploader.rb Show resolved Hide resolved
Moved the new spec for BulkUrlUploader::Results out to its own file,
per CodeClimate's wishes.
errors = @errors.keys
errors.reject(&already_taken) + errors.select(&already_taken)

# @errors.keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove debugging line

subject(:results) { described_class.new('test bulk uploader') }

describe '#errors' do
context 'when there are "url not found" errors' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This context should be when there are "Url has already been taken" errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Comment on lines 9 to 10
results.add_error('Validation failed: Url has already been taken', 'junk')
results.add_error('Validation failed: SearchgovDomain is not a valid SearchgovDomain', 'junk')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change junk to a URL, i.e. https://alreadytaken.gov/https://invaliddomain.gov. That will help document the behavior of the code, whereas a future developer looking at this spec would not know what 'junk' might be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Changed name of context and made url names more verbose.
Copy link
Contributor

@MothOnMars MothOnMars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jmax-fearless jmax-fearless merged commit 83ba83a into GSA:master Aug 3, 2021
@MyNameIsMissing MyNameIsMissing mentioned this pull request Aug 9, 2021
MyNameIsMissing added a commit that referenced this pull request Aug 9, 2021
SRCH-2300 Handle non-ASCII characters in URLs (#752) …
SRCH-2243 change bulk upload email error message order (#758) …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants