|
2 | 2 |
|
3 | 3 | namespace Tests\Feature\Search;
|
4 | 4 |
|
| 5 | +use Carbon\Carbon; |
5 | 6 | use Tests\TestCase;
|
6 | 7 | use App\Models\Service;
|
7 | 8 | use App\Models\Taxonomy;
|
@@ -1452,4 +1453,68 @@ public function test_service_scores_are_secondary_to_distance(): void
|
1452 | 1453 | $this->assertEquals($service0->id, $data[0]['id']);
|
1453 | 1454 | $this->assertEquals($service5->id, $data[1]['id']);
|
1454 | 1455 | }
|
| 1456 | + |
| 1457 | + /** |
| 1458 | + * @test |
| 1459 | + */ |
| 1460 | + public function freshnessOfServiceDoesNotAffectSearchResult() |
| 1461 | + { |
| 1462 | + $organisation = \App\Models\Organisation::factory()->create(); |
| 1463 | + $serviceParams = [ |
| 1464 | + 'organisation_id' => $organisation->id, |
| 1465 | + 'name' => 'Royal Organs Hike', |
| 1466 | + ]; |
| 1467 | + $service5 = Service::factory()->create(array_merge($serviceParams, [ |
| 1468 | + 'score' => 5, |
| 1469 | + 'created_at' => Carbon::now()->subMonths(24), |
| 1470 | + 'updated_at' => Carbon::now()->subMonths(24), |
| 1471 | + 'last_modified_at' => Carbon::now()->subMonths(24), |
| 1472 | + ])); |
| 1473 | + $service4 = Service::factory()->create(array_merge($serviceParams, [ |
| 1474 | + 'score' => 4, |
| 1475 | + 'created_at' => Carbon::now()->subMonths(12), |
| 1476 | + 'updated_at' => Carbon::now()->subMonths(12), |
| 1477 | + 'last_modified_at' => Carbon::now()->subMonths(12), |
| 1478 | + ])); |
| 1479 | + $service3 = Service::factory()->create(array_merge($serviceParams, [ |
| 1480 | + 'score' => 3, |
| 1481 | + 'created_at' => Carbon::now()->subMonths(6), |
| 1482 | + 'updated_at' => Carbon::now()->subMonths(6), |
| 1483 | + 'last_modified_at' => Carbon::now()->subMonths(6), |
| 1484 | + ])); |
| 1485 | + $service2 = Service::factory()->create(array_merge($serviceParams, [ |
| 1486 | + 'score' => 2, |
| 1487 | + 'created_at' => Carbon::now()->subMonths(3), |
| 1488 | + 'updated_at' => Carbon::now()->subMonths(3), |
| 1489 | + 'last_modified_at' => Carbon::now()->subMonths(3), |
| 1490 | + ])); |
| 1491 | + $service1 = Service::factory()->create(array_merge($serviceParams, [ |
| 1492 | + 'score' => 1, |
| 1493 | + 'created_at' => Carbon::now()->subMonths(1), |
| 1494 | + 'updated_at' => Carbon::now()->subMonths(1), |
| 1495 | + 'last_modified_at' => Carbon::now()->subMonths(1), |
| 1496 | + ])); |
| 1497 | + $service0 = Service::factory()->create(array_merge($serviceParams, [ |
| 1498 | + 'score' => 0, |
| 1499 | + 'created_at' => Carbon::now(), |
| 1500 | + 'updated_at' => Carbon::now(), |
| 1501 | + 'last_modified_at' => Carbon::now(), |
| 1502 | + ])); |
| 1503 | + |
| 1504 | + sleep(1); |
| 1505 | + |
| 1506 | + $response = $this->json('POST', '/core/v1/search', [ |
| 1507 | + 'query' => 'royal organs hike', |
| 1508 | + ]); |
| 1509 | + |
| 1510 | + $response->assertStatus(Response::HTTP_OK); |
| 1511 | + $data = $this->getResponseContent($response)['data']; |
| 1512 | + |
| 1513 | + $this->assertEquals($service5->id, $data[0]['id']); |
| 1514 | + $this->assertEquals($service4->id, $data[1]['id']); |
| 1515 | + $this->assertEquals($service3->id, $data[2]['id']); |
| 1516 | + $this->assertEquals($service2->id, $data[3]['id']); |
| 1517 | + $this->assertEquals($service1->id, $data[4]['id']); |
| 1518 | + $this->assertEquals($service0->id, $data[5]['id']); |
| 1519 | + } |
1455 | 1520 | }
|
0 commit comments