Skip to content

Commit

Permalink
Merge pull request #61 from HE-Arc/add_genres_to_comparison
Browse files Browse the repository at this point in the history
return genre from sent song
  • Loading branch information
maelys-buhler authored Nov 22, 2023
2 parents d670ec2 + 783727f commit c79d8a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/Models/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function getComparisonArray(Song $answerSong): array
$commonPoints['artist_name'] = $this->artist->name;
$commonPoints['album_name'] = $this->album->name;
$commonPoints['nb_genres'] = $answerSong->artist->genres->count();
$commonPoints['artist_genres'] = $this->getSongGenres();

return $commonPoints;
}
Expand All @@ -115,6 +116,16 @@ private function compare($a, $b): int|float
return $a < $b ? 1 : -1;
}

private function getSongGenres(): array
{
$genres = [];
foreach ($this->artist->genres as $genre) {
array_push($genres, ['genre_id' => $genre->id, 'genre_name' => $genre->name]);
}

return $genres;
}

private function getCommonArtistsGenres($artist1, $artist2): array
{
$commonGenres = [];
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/GameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,21 @@ public function testAjaxHasGameStarted(): void
$this->assertNotFalse($response->getContent());
$response->assertStatus(200);
}

public function testComparisonFull(): void
{
$response = $this->post('/start_game');
$response->assertStatus(200);

$response = $this->post('/comparison_with_answer_song', [
'song_id' => 1,
]);
$response->assertStatus(200);

self::assertNotNull($response->json('isSame'));
self::assertNotNull($response->json('artist_genres'));
self::assertNotFalse(count($response->json('artist_genres')) > 0);

$response = $this->post('/end_game');
}
}
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
input: [
'resources/js/app.js',
'resources/js/pages/game.js',
'resources/js/pages/test.js',
// 'resources/js/pages/test.js',

'resources/css/app.scss',
'resources/css/variables.scss',
Expand Down

0 comments on commit c79d8a6

Please sign in to comment.