Skip to content

Commit

Permalink
Allow for fuzziness in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
appsol committed Dec 11, 2023
1 parent 2718fe8 commit 829b1b1
Showing 1 changed file with 36 additions and 47 deletions.
83 changes: 36 additions & 47 deletions tests/Feature/Search/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,10 @@ public function test_guest_can_search(): void

public function test_query_matches_service_name(): void
{
$service1 = Service::factory()->create([
$service = Service::factory()->create([
'name' => 'hunt remind voice',
]);
Service::factory()->create([
'name' => 'bend simple orange',
]);
Service::factory()->create([
'name' => 'pigs sake wooden',
]);
Service::factory()->create([
'name' => 'exam punt pencil',
]);
Service::factory()->create([
'name' => 'shadow relay kinks',
]);
Service::factory()->count(5)->create();

sleep(1);

Expand All @@ -126,27 +115,27 @@ public function test_query_matches_service_name(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy match
$response = $this->json('POST', '/core/v1/search', [
'query' => 'voice hunted',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_matches_service_description(): void
{
$service1 = Service::factory()->create(['description' => $this->textContainingPhrases(['rods game sleeps'], 500)]);
$service2 = Service::factory()->create();
$service = Service::factory()->create(['description' => $this->textContainingPhrases(['rods game sleeps'], 500)]);
Service::factory()->count(5)->create();

sleep(1);

Expand All @@ -155,21 +144,21 @@ public function test_query_matches_service_description(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy match
$response = $this->json('POST', '/core/v1/search', [
'query' => 'sleep games',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_matches_taxonomy_name(): void
Expand Down Expand Up @@ -199,17 +188,17 @@ public function test_query_matches_taxonomy_name(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$this->assertEquals($service1->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy
$response = $this->json('POST', '/core/v1/search', [
'query' => 'bring a song',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$this->assertEquals($service1->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_matches_partial_taxonomy_name(): void
Expand Down Expand Up @@ -239,25 +228,25 @@ public function test_query_matches_partial_taxonomy_name(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$this->assertEquals($service1->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy
$response = $this->json('POST', '/core/v1/search', [
'query' => 'block',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$this->assertEquals($service1->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_matches_organisation_name(): void
{
$organisation1 = Organisation::factory()->create(['name' => 'Riches Resist Envy']);
$organisation2 = Organisation::factory()->create();
$service1 = Service::factory()->create(['organisation_id' => $organisation1->id]);
$service2 = Service::factory()->create(['organisation_id' => $organisation2->id]);
$service = Service::factory()->create(['organisation_id' => $organisation1->id]);
Service::factory()->count(5)->create(['organisation_id' => $organisation2->id]);

sleep(1);

Expand All @@ -266,19 +255,19 @@ public function test_query_matches_organisation_name(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy
$response = $this->json('POST', '/core/v1/search', [
'query' => 'envy rich',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$response->assertJsonFragment(['id' => $service->id]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_ranks_service_name_equivalent_to_organisation_name(): void
Expand Down Expand Up @@ -352,11 +341,11 @@ public function test_query_ranks_perfect_match_above_fuzzy_match(): void

public function test_query_matches_service_intro(): void
{
$service1 = Service::factory()->create([
$service = Service::factory()->create([
'intro' => $this->textContainingPhrases(['glaze mild chats']),
]);

$service2 = Service::factory()->create();
Service::factory()->count(5)->create();

sleep(1);

Expand All @@ -365,21 +354,21 @@ public function test_query_matches_service_intro(): void
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy
$response = $this->json('POST', '/core/v1/search', [
'query' => 'chat mild',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment([
'id' => $service1->id,
'id' => $service->id,
]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_query_matches_single_word_from_service_description(): void
Expand All @@ -400,11 +389,11 @@ public function test_query_matches_single_word_from_service_description(): void

public function test_query_matches_multiple_words_from_service_description(): void
{
$service1 = Service::factory()->create([
$service = Service::factory()->create([
'description' => $this->textContainingPhrases(['hurls star humans']),
]);

$service2 = Service::factory()->create();
Service::factory()->create();

sleep(1);

Expand All @@ -413,17 +402,17 @@ public function test_query_matches_multiple_words_from_service_description(): vo
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$response->assertJsonFragment(['id' => $service->id]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);

// Fuzzy
$response = $this->json('POST', '/core/v1/search', [
'query' => 'human stars',
]);

$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(1, 'data');
$response->assertJsonFragment(['id' => $service1->id]);
$response->assertJsonFragment(['id' => $service->id]);
$this->assertEquals($service->id, $this->getResponseContent($response)['data'][0]['id']);
}

public function test_filter_by_wait_time_works(): void
Expand Down Expand Up @@ -1302,8 +1291,8 @@ public function test_ranking_for_eligibility_higher_for_single_matching_eligibil
$this->assertEquals(4, count($data));

$this->assertTrue(in_array($serviceA->id, [$data[0]['id'], $data[1]['id']]));
$this->assertTrue(in_array($serviceB->id, [$data[1]['id'], $data[2]['id']]));
$this->assertTrue(in_array($serviceC->id, [$data[1]['id'], $data[2]['id']]));
$this->assertTrue(in_array($serviceB->id, [$data[0]['id'], $data[1]['id'], $data[2]['id']]));
$this->assertTrue(in_array($serviceC->id, [$data[1]['id'], $data[2]['id'], $data[3]['id']]));
$this->assertTrue(in_array($serviceD->id, [$data[2]['id'], $data[3]['id']]));
}

Expand Down

0 comments on commit 829b1b1

Please sign in to comment.