-
-
Notifications
You must be signed in to change notification settings - Fork 572
Add ability to see cancelled requests #5543
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
Open
stefannibrasil
wants to merge
8
commits into
rubyforgood:main
Choose a base branch
from
hexdevs:cancelled-requests-5325
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1d62c3d
Fix typo
stefannibrasil 0a5c85c
Add ability to see cancelled requests
stefannibrasil 7deaa4d
Cancelled requests actions update
stefannibrasil fdb6575
Ensure cancelled requests cannot have their status changed
stefannibrasil f8b0959
Create factories only when necessary
stefannibrasil 75337d2
Move system tests to requests
stefannibrasil 9d87f0d
Merge branch 'main' into cancelled-requests-5325
stefannibrasil 5db69e7
Move more system tests to request specs
stefannibrasil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,6 @@ | |
| response | ||
| end | ||
|
|
||
| before do | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't being used at all. |
||
| create(:request) | ||
| end | ||
|
|
||
| context "html" do | ||
| let(:response_format) { 'html' } | ||
|
|
||
|
|
@@ -25,35 +21,103 @@ | |
| let(:response_format) { 'csv' } | ||
|
|
||
| it { is_expected.to be_successful } | ||
|
|
||
| context 'when exporting as CSV' do | ||
| it "exports only the cancelled requests CSV when 'Include Cancelled' is checked and 'Filter by Status' is 'Cancelled'" do | ||
| create(:request, :started) | ||
| create(:request, :cancelled) | ||
|
|
||
| get requests_path(format: :csv, params: {include_cancelled: "1", filters: { by_status: :cancelled}}) | ||
|
|
||
| csv = CSV.parse(response.body, headers: true) | ||
|
|
||
| expect(csv.count).to eq(1) | ||
| expect(csv.first["Status"]).to eq("Cancelled") | ||
| end | ||
|
|
||
| it "exports the requests CSV including cancelled requests when 'Include Cancelled' is checked" do | ||
| create(:request, :started) | ||
| create(:request, :cancelled) | ||
|
|
||
| get requests_path(format: :csv, params: {include_cancelled: "1"}) | ||
|
|
||
| csv = CSV.parse(response.body, headers: true) | ||
|
|
||
| expect(csv.count).to eq(2) | ||
| expect(csv[0]["Status"]).to eq("Started") | ||
| expect(csv[1]["Status"]).to eq("Cancelled") | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context "when there are pending or started requests" do | ||
| it "shows print unfulfilled picklists button with correct quantity" do | ||
| Request.delete_all | ||
|
|
||
| it "shows print unfulfilled picklists button with correct quantity, excluding cancelled requests by default" do | ||
| create(:request, :pending) | ||
| create(:request, :started) | ||
| create(:request, :fulfilled) | ||
| create(:request, :discarded) | ||
| create(:request, :cancelled) | ||
|
|
||
| get requests_path | ||
|
|
||
| expect(response.body).to include('Print Unfulfilled Picklists (2)') | ||
| expect(response.body).not_to match(%r{<span class="badge badge-danger bg-danger">\s*Cancelled\s*</span>}) | ||
| end | ||
| end | ||
|
|
||
| context "when 'include_cancelled' param is present" do | ||
| it 'does not display the Cancel button for cancelled requests' do | ||
| pending_request = create(:request, :pending) | ||
| cancelled_request = create(:request, :cancelled) | ||
|
|
||
| get requests_path, params: {include_cancelled: "1"} | ||
|
|
||
| page = Nokogiri::HTML(response.body) | ||
|
|
||
| cancelled_request_cancel_button = page.at_css("form[action='/requests/#{cancelled_request.id}/cancelation/new']") | ||
| expect(cancelled_request_cancel_button).to be_nil | ||
|
|
||
| pending_request_cancel_button = page.at_css("a[href='/requests/#{pending_request.id}/cancelation/new']") | ||
| expect(pending_request_cancel_button).to be_present | ||
| end | ||
|
|
||
| it "shows print unfulfilled picklists button with correct quantity including cancelled requests" do | ||
| create(:request, :pending) | ||
| create(:request, :started) | ||
| create(:request, :cancelled) | ||
|
|
||
| get requests_path, params: {include_cancelled: "1"} | ||
|
|
||
| expect(response.body).to include('Print Unfulfilled Picklists (2)') | ||
| expect(response.body).to match(%r{<span class="badge badge-danger bg-danger">\s*Cancelled\s*</span>}) | ||
| end | ||
| end | ||
|
|
||
| context "when 'Include Cancelled?' is checked and filter by Cancelled" do | ||
| it "constrains the list for cancelled requests only" do | ||
| create(:request, :started, comments: "Need more supplies") | ||
| create(:request, :pending, comments: "Awaiting for confirmation") | ||
| create(:request, :cancelled, comments: 'Not necessary anymore') | ||
|
|
||
| get requests_path, params: {include_cancelled: "1", filters: { by_status: :cancelled}} | ||
|
|
||
| expect(response.body).to include("Not necessary anymore") | ||
| expect(response.body).not_to include("Need more supplies") | ||
| expect(response.body).not_to include("Awaiting for confirmation") | ||
| end | ||
| end | ||
|
|
||
| context "when there is a filter applied" do | ||
| it "shows only filtered requests, print unfulfilled picklists button with correct quantity" do | ||
| Request.delete_all | ||
|
|
||
| create(:request, :started, comments: "Started request - should appear") | ||
| create(:request, :pending, comments: "Pending request - should not appear") | ||
| create(:request, :cancelled, comments: 'Cancelled request - a comment') | ||
|
|
||
| get requests_path({ filters: { by_status: :started} }) | ||
|
|
||
| expect(response.body).to include("Print Unfulfilled Picklists (1)") | ||
| expect(response.body).to include("Started request - should appear") | ||
| expect(response.body).not_to include("Pending request - should not appear") | ||
| expect(response.body).not_to include("Cancelled request - a comment") | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -156,6 +220,24 @@ | |
| expect(response.body).not_to include('Units (if applicable)') | ||
| end | ||
| end | ||
|
|
||
| context 'when the request has a cancelled status' do | ||
| it 'does not display the Cancel and Fulfill request buttons' do | ||
| cancelled_request = create(:request, :cancelled, organization:) | ||
|
|
||
| get request_path(cancelled_request) | ||
|
|
||
| page = Nokogiri::HTML(response.body) | ||
|
|
||
| cancel_button = page.at_css("form[action='/requests/#{cancelled_request.id}/cancelation/new']") | ||
| fulfill_button = page.at_css("form[action='/requests/#{cancelled_request.id}/start']") | ||
| expect(cancel_button).to be_nil | ||
| expect(fulfill_button).to be_nil | ||
|
|
||
| print_link = page.at_css("a[href='/requests/#{cancelled_request.id}/print_picklist']") | ||
| expect(print_link).to be_present | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'POST #start' do | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can create an issue to refactor this controller so we don't have all these variables here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue for this: #5557