|
38 | 38 |
|
39 | 39 | expect($result)
|
40 | 40 | ->toBeInstanceOf(Book::class)
|
41 |
| - ->and($result->price)->toEqual($this->doFindFixture['oeuvre']['article'][0]['prix'] * 100); |
| 41 | + ->id->toEqual($this->doFindFixture['oeuvre']['article'][0]['gencod']); |
| 42 | +}); |
| 43 | + |
| 44 | +it('doesn’t find a book on an unconfigured code_support', function () { |
| 45 | + $client = new TiteLiveClient( 'find.example', 'login.example', '[email protected]', 'pwd'); |
| 46 | + |
| 47 | + expect($client |
| 48 | + ->setParam(BookDirectoryClient::GENCOD, '123') |
| 49 | + ->doFind() |
| 50 | + )->toBeInstanceOf(Book::class); |
| 51 | + |
| 52 | + config()->set('titelive-client.book_directory.api.params.code_support', 'PS,BL'); |
| 53 | + |
| 54 | + expect($client |
| 55 | + ->setParam(BookDirectoryClient::GENCOD, '123') |
| 56 | + ->doFind() |
| 57 | + )->toBeNull(); |
| 58 | + |
| 59 | + config()->set('titelive-client.book_directory.api.params.code_support', 'PS,BL,T'); |
| 60 | + |
| 61 | + expect($client |
| 62 | + ->setParam(BookDirectoryClient::GENCOD, '123') |
| 63 | + ->doFind() |
| 64 | + )->toBeInstanceOf(Book::class); |
42 | 65 | });
|
43 | 66 |
|
44 | 67 | it('lists books of a category', function () {
|
|
73 | 96 | ->setParam(BookDirectoryClient::SEARCH_PAGE, 1)
|
74 | 97 | ->setParam(BookDirectoryClient::SEARCH_TOTAL_COUNT, 10)
|
75 | 98 | ->setParam(BookDirectoryClient::SEARCH_QUERY, 'my search')
|
76 |
| - ->doSearch(true); |
| 99 | + ->doSearch(groupEditions: true); |
77 | 100 |
|
78 | 101 | Http::assertSent(function (Request $request) {
|
79 | 102 | return $request->hasHeader('User-Agent', 'qdb/v1.0')
|
|
91 | 114 | // Check that the first book has all its editions gencod in ->editions
|
92 | 115 | $this->assertEqualsCanonicalizing(
|
93 | 116 | collect($this->doSearchFixture['result'][0]['article'])
|
94 |
| - ->filter(fn ($edition) => in_array($edition['codesupport'], ['T', 'P']) |
95 |
| - && $edition['gencod'] != $this->doSearchFixture['result'][0]['gencod'] |
96 |
| - ) |
| 117 | +// ->filter(fn ($edition) => in_array($edition['codesupport'], ['T', 'P']) |
| 118 | +// && $edition['gencod'] != $this->doSearchFixture['result'][0]['gencod'] |
| 119 | +// ) |
| 120 | + ->filter(fn ($edition) => $edition['gencod'] != $this->doSearchFixture['result'][0]['gencod']) |
97 | 121 | ->pluck('gencod')
|
98 | 122 | ->values()
|
99 | 123 | ->toArray(),
|
|
107 | 131 | $searchResults = $client
|
108 | 132 | ->setParam(BookDirectoryClient::SEARCH_AVAILABILITY, 'all')
|
109 | 133 | ->setParam(BookDirectoryClient::SEARCH_PAGE, 1)
|
110 |
| - ->setParam(BookDirectoryClient::SEARCH_TOTAL_COUNT, 100) |
| 134 | + ->setParam(BookDirectoryClient::SEARCH_TOTAL_COUNT, 150) |
| 135 | + ->setParam(BookDirectoryClient::SEARCH_QUERY, 'my search') |
| 136 | + ->doSearch(); |
| 137 | + |
| 138 | + $editionCount = collect($this->doSearchFixture['result']) |
| 139 | + ->sum(fn ($book) => collect($book['article'])->count()); |
| 140 | + |
| 141 | + expect($searchResults) |
| 142 | + ->toBeInstanceOf(Collection::class) |
| 143 | + ->count()->toEqual($editionCount); |
| 144 | + |
| 145 | + collect($this->doSearchFixture['result'][0]['article']) |
| 146 | + ->pluck('gencod') |
| 147 | + ->values() |
| 148 | + ->each(fn ($gencod, $index) => expect($searchResults[$index]->id)->toEqual($gencod)); |
| 149 | +}); |
| 150 | + |
| 151 | +it('filters search results on code_support when configured', function () { |
| 152 | + $client = new TiteLiveClient( 'search.example', 'login.example', '[email protected]', 'pwd'); |
| 153 | + |
| 154 | + config()->set('titelive-client.book_directory.api.params.code_support', 'T,P'); |
| 155 | + |
| 156 | + $searchResults = $client |
| 157 | + ->setParam(BookDirectoryClient::SEARCH_AVAILABILITY, 'all') |
| 158 | + ->setParam(BookDirectoryClient::SEARCH_PAGE, 1) |
| 159 | + ->setParam(BookDirectoryClient::SEARCH_TOTAL_COUNT, 150) |
111 | 160 | ->setParam(BookDirectoryClient::SEARCH_QUERY, 'my search')
|
112 | 161 | ->doSearch();
|
113 | 162 |
|
114 | 163 | $editionCount = collect($this->doSearchFixture['result'])
|
115 | 164 | ->sum(function ($book) {
|
116 | 165 | return collect($book['article'])
|
117 |
| - ->filter(function ($edition) { |
118 |
| - return in_array($edition['codesupport'], ['T', 'P']); |
119 |
| - }) |
| 166 | + ->filter(fn ($edition) => in_array($edition['codesupport'], ['T', 'P'])) |
120 | 167 | ->count();
|
121 | 168 | });
|
122 | 169 |
|
123 | 170 | expect($searchResults)
|
124 | 171 | ->toBeInstanceOf(Collection::class)
|
125 |
| - ->and($searchResults->count())->toEqual($editionCount); |
| 172 | + ->count()->toEqual($editionCount); |
126 | 173 |
|
127 | 174 | collect($this->doSearchFixture['result'][0]['article'])
|
128 | 175 | ->filter(fn ($edition) => in_array($edition['codesupport'], ['T', 'P']))
|
|
0 commit comments