Skip to content

Commit

Permalink
Merge pull request #141 from arnaugarcia/fix/user-liked-tracks
Browse files Browse the repository at this point in the history
Fix/user liked tracks
  • Loading branch information
arnaugarcia authored Mar 4, 2020
2 parents fae941d + 7855b6a commit f47fb15
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sallefy",
"version": "0.1.20-BETA",
"version": "0.1.21-BETA",
"description": "Description for Sallefy",
"private": true,
"license": "UNLICENSED",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.sallefy</groupId>
<artifactId>sallefy</artifactId>
<version>0.1.20-BETA</version>
<version>0.1.21-BETA</version>
<packaging>jar</packaging>
<name>Sallefy</name>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sallefy/repository/TrackRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface TrackRepository extends JpaRepository<Track, Long>, JpaSpecific
@Query("select track from Track track left join fetch track.genres where track.id =:id")
Optional<Track> findOneWithEagerRelationships(@Param("id") Long id);

@Query("select track from Track track inner join track.likeTracks where track.user.login = ?#{principal.username}")
@Query("select track from Track track inner join fetch track.likeTracks liketracks where liketracks.user.login = ?#{principal.username}")
List<Track> findAllLikedTracksByCurrentUser();

@Query("select track from Track track where track.user.login = :login")
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/com/sallefy/web/rest/MeResourceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void get_all_tracks_of_current_user() throws Exception {
@Test
@Transactional
@WithMockUser("basic-liked-track-user")
public void get_all_liked_tracks() throws Exception {
public void get_all_liked_tracks_by_current_user() throws Exception {

// Initialize the database
User user = UserResourceIT.createBasicUserWithUsername("basic-liked-track-user");
Expand Down Expand Up @@ -217,6 +217,40 @@ public void get_all_liked_tracks() throws Exception {
.andExpect(jsonPath("$", hasSize(1)));
}

@Test
@Transactional
@WithMockUser("basic-liked-track-non-owner")
public void get_all_liked_tracks_non_owner() throws Exception {

// Initialize the database
User owner = UserResourceIT.createEntity();
userRepository.save(owner);

User externalUser = UserResourceIT.createBasicUserWithUsername("basic-liked-track-non-owner");
userRepository.save(externalUser);

// Tracks for track owner
Track track1 = TrackResourceIT.createEntity();
track1.setUser(owner);
Track track = trackRepository.save(track1);

// Get all the trackList
restMeMockMvc.perform(get("/api/me/tracks/liked"))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$", hasSize(0)));

restTrackMockMvc.perform(put("/api/tracks/{id}/like", track.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$.liked").value(true));

restMeMockMvc.perform(get("/api/me/tracks/liked"))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$", hasSize(1)));
}

@Test
@Transactional
@WithMockUser("basic-user")
Expand Down

0 comments on commit f47fb15

Please sign in to comment.