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

Add tests for reports #6177

Merged
merged 6 commits into from
Jul 7, 2021
Merged

Add tests for reports #6177

merged 6 commits into from
Jul 7, 2021

Conversation

1pretz1
Copy link
Contributor

@1pretz1 1pretz1 commented Jun 29, 2021

This PR adds tests for some (of the many) rake tasks. I focused mainly on the Publishing API rake tasks as they were the least tested and high value. There has also been some refactoring to try make navigating and adding new publishing api tasks a bit easier.


Trello:
https://trello.com/c/LCR0Am73/2541-5-enable-continuous-deployment-for-whitehall

1pretz1 added a commit to alphagov/publishing-e2e-tests that referenced this pull request Jun 29, 2021
This was refactored two years ago and doesn't actually run due to [line
13][1] as the `delete` call throws an `ArgumentError` for the `PathName`
instance. This hasn't been fixed / noticed in all that time so assume
this report is no longer needed.

[1]: https://github.com/alphagov/whitehall/blob/7c2c8919a6fc1a4432d7c3caef3c4b1b737779cc/lib/reports/draft_publications_report.rb#L13
Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

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

Really good job bringing the test coverage up, Peter 👍 I have a few questions and suggestions below.

test/unit/reports/organisation_attachments_report_test.rb Outdated Show resolved Hide resolved
test/unit/reports/published_attachments_report_test.rb Outdated Show resolved Hide resolved
app/models/redirect_route.rb Show resolved Hide resolved
lib/tasks/publishing_api.rake Show resolved Hide resolved
test/unit/tasks/publishing_api_test.rb Outdated Show resolved Hide resolved
test/unit/tasks/publishing_api_test.rb Outdated Show resolved Hide resolved
test/unit/tasks/publishing_api_test.rb Outdated Show resolved Hide resolved
test/unit/tasks/publishing_api_test.rb Outdated Show resolved Hide resolved
lib/tasks/publishing_api.rake Show resolved Hide resolved
@1pretz1 1pretz1 force-pushed the add-tests-for-reports branch 2 times, most recently from 363a057 to 555f951 Compare July 2, 2021 17:12
This commit also standardises them by:

* creating constants to store CSV headers
* using the apps tmp directory as it feels more appropriate than the
global tmp directory
@1pretz1 1pretz1 force-pushed the add-tests-for-reports branch 2 times, most recently from 57d9a0e to 68d1598 Compare July 2, 2021 17:26
@1pretz1
Copy link
Contributor Author

1pretz1 commented Jul 2, 2021

Thanks for the review @ChrisBAshton! Think I've addressed everything.

I was getting some strange behaviour when I was running the rake tests locally (tasks running twice, when only invoked once) and have narrowed it down to the tasks themselves being initialised more than once. I've updated this in the last commit.

Previously this rake file was quite disorganised with inconsistencies
like tasks being in the wrong name space.

This commit:

* Moves tasks to the correct namespace

* Renames some tasks to try and gain some naming consistency

* Moves redirect routes and special routes to their own model which will
help with testing in the next commit
Adds tests to all (non-dry run) rake tasks.

This commit also adds a factory attribute to file attachments which
makes them more realistic (accesible = `false` instead of `nil`)
This task is needed to satisfy the e2e tests setup. We can remove it
once this is merged, and the e2e tests PR is merged [1].

[1]: alphagov/publishing-e2e-tests#422
Not checking if there are any pre-loaded rake tasks was causing tasks to
be initialized twice, resulting in them running twice for every single
invocation.
Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

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

Great work, @1pretz1 👏

@1pretz1 1pretz1 merged commit 17063ca into main Jul 7, 2021
@1pretz1 1pretz1 deleted the add-tests-for-reports branch July 7, 2021 08:43
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.

2 participants