Bug 22688

Summary: TT plugin for pickup locations code wrong
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Hold requestsAssignee: Kyle M Hall (khall) <kyle>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: agustinmoyano, gmcharlt, lucas, martin.renvoize, nick, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
19.05.00, 18.11.05
Circulation function:
Bug Depends on: 7614    
Bug Blocks: 22284    
Attachments: Bug 22688: Unit tests
Bug 22688: TT plugin for pickup locations code wrong
Bug 22688: Unit tests
Bug 22688: Unit tests
Bug 22688: TT plugin for pickup locations code wrong
Bug 22688: Unit tests
Bug 22688: Unit tests
Bug 22688: (follow-up) Unit tests
Bug 22688: TT plugin for pickup locations code wrong
Bug 22688: (QA follow-up) Use search_params as all() does
Bug 22688: Unit tests
Bug 22688: Unit tests
Bug 22688: (follow-up) Unit tests
Bug 22688: TT plugin for pickup locations code wrong
Bug 22688: (QA follow-up) Use search_params as all() does

Description Tomás Cohen Arazi (tcohen) 2019-04-11 11:11:33 UTC
I haven't spent the time to determine the consequences, but bug 7614 got wrong at some point on rebasing and this code looks plain wrong, looking at the patches history in bugzilla it seems that the lines prefixed with minus sign need to be removed:

sub pickup_locations {
    my ( $self, $params ) = @_;
-    $params->{search_params} ||= {};
-    $params->{search_params}->{pickup_location} = 1;
-    return $self->all($params);

    my $selected  = $params->{selected};
    my $libraries = Koha::Libraries->pickup_locations($params);
    for my $l (@$libraries) {
        if ( defined $selected and $l->{branchcode} eq $selected
            or not defined $selected
            and C4::Context->userenv
            and $l->{branchcode} eq C4::Context->userenv->{branch} )
        {
            $l->{selected} = 1;
        }
    }

    return $libraries;
}
Comment 1 Kyle M Hall (khall) 2019-04-11 13:54:32 UTC
Created attachment 87764 [details] [review]
Bug 22688: Unit tests
Comment 2 Kyle M Hall (khall) 2019-04-11 13:54:44 UTC
Created attachment 87765 [details] [review]
Bug 22688: TT plugin for pickup locations code wrong

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Libraries.t
Comment 3 Kyle M Hall (khall) 2019-04-11 14:14:15 UTC
Created attachment 87766 [details] [review]
Bug 22688: Unit tests
Comment 4 Kyle M Hall (khall) 2019-04-11 14:18:58 UTC
Created attachment 87768 [details] [review]
Bug 22688: Unit tests
Comment 5 Agustín Moyano 2019-04-11 14:34:49 UTC
Created attachment 87772 [details] [review]
Bug 22688: TT plugin for pickup locations code wrong

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Libraries.t

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Comment 6 Agustín Moyano 2019-04-11 14:34:52 UTC
Created attachment 87773 [details] [review]
Bug 22688: Unit tests

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Comment 7 Tomás Cohen Arazi (tcohen) 2019-04-11 20:18:10 UTC
Kyle, it seems to me that the test case you picked is the one that doesn't test pickup limitations (compared to all()).

I think we should test:
- Passing a selected => branchcode, then if selected => 1 is added to the hashref
- Using mock_userenv({ branchcode => $library->branchcode }) to test the case in which C4::Context->userenv is used to pick the 'selected' library.

I confess I spend a good amount of time today trying to implement a fully mocked test, only to learn that there's a problem with the 'selected' param because it would be passed all the way down to Koha::Libraries->search...

This got into a rabbit hole (writing this tests).
Comment 8 Tomás Cohen Arazi (tcohen) 2019-04-11 20:19:41 UTC
Created attachment 87817 [details] [review]
Bug 22688: Unit tests

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 9 Tomás Cohen Arazi (tcohen) 2019-04-11 20:19:45 UTC
Created attachment 87818 [details] [review]
Bug 22688: (follow-up) Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 10 Tomás Cohen Arazi (tcohen) 2019-04-11 20:19:48 UTC
Created attachment 87819 [details] [review]
Bug 22688: TT plugin for pickup locations code wrong

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Libraries.t

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 11 Tomás Cohen Arazi (tcohen) 2019-04-11 20:19:52 UTC
Created attachment 87820 [details] [review]
Bug 22688: (QA follow-up) Use search_params as all() does

It looks like selected would be passed all the way down to
Koha::Libraries->search and this would fail all the time.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 12 Tomás Cohen Arazi (tcohen) 2019-04-11 20:20:37 UTC
I decided to submit what I had done. But it needs your review, Kyle, and maybe the mocked tests are not enough.
Comment 13 Tomás Cohen Arazi (tcohen) 2019-04-11 20:21:05 UTC
It is such a tiny thing, used in a single place...
Comment 14 Kyle M Hall (khall) 2019-04-12 12:12:22 UTC
Created attachment 87884 [details] [review]
Bug 22688: Unit tests

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 15 Kyle M Hall (khall) 2019-04-12 12:15:01 UTC
Created attachment 87885 [details] [review]
Bug 22688: Unit tests

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 16 Kyle M Hall (khall) 2019-04-12 12:15:21 UTC
Created attachment 87886 [details] [review]
Bug 22688: (follow-up) Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Kyle M Hall (khall) 2019-04-12 12:15:24 UTC
Created attachment 87887 [details] [review]
Bug 22688: TT plugin for pickup locations code wrong

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Libraries.t

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 18 Kyle M Hall (khall) 2019-04-12 12:15:27 UTC
Created attachment 87888 [details] [review]
Bug 22688: (QA follow-up) Use search_params as all() does

It looks like selected would be passed all the way down to
Koha::Libraries->search and this would fail all the time.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 19 Nick Clemens (kidclamp) 2019-04-16 13:27:21 UTC
Awesome work all!

Pushed to master for 19.05
Comment 20 Martin Renvoize (ashimema) 2019-04-25 13:31:12 UTC
Pushed to 18.11.x for 18.11.05
Comment 21 Lucas Gass (lukeg) 2019-04-26 16:00:51 UTC
missing dependencies for 18.05.x, not backporting