Skip to content

Commit

Permalink
Merge pull request #45 from tapglue/user-likes
Browse files Browse the repository at this point in the history
add user likes
  • Loading branch information
nilsen340 authored Sep 8, 2016
2 parents bce95a1 + fcc3a4f commit befcb11
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.4'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 07 19:27:33 EDT 2016
#Wed Sep 07 16:51:45 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,40 @@ public void testRetrieveLikesPopulatesUser() throws Exception {

assertThat(likes.get(0).getUser(), equalTo(user1));
}

public void testRetrieveLikesByUser() throws Exception {
user1 = tapglue.loginWithUsername(USER_1, PASSWORD);
Post post = new Post(attachments, Post.Visibility.PUBLIC);
post = tapglue.createPost(post);

Like like = tapglue.createLike(post.getId());

List<Like> likes = tapglue.retrieveLikesByUser(user1.getId());

assertThat(likes, hasItems(like));
}

public void testRetrieveLikesByUserPopulatesUser() throws Exception {
user1 = tapglue.loginWithUsername(USER_1, PASSWORD);
Post post = new Post(attachments, Post.Visibility.PUBLIC);
post = tapglue.createPost(post);

tapglue.createLike(post.getId());

List<Like> likes = tapglue.retrieveLikesByUser(user1.getId());

assertThat(likes.get(0).getUser(), equalTo(user1));
}

public void testRetrieveLikesByUserPopulatesPost() throws Exception {
user1 = tapglue.loginWithUsername(USER_1, PASSWORD);
Post post = new Post(attachments, Post.Visibility.PUBLIC);
post = tapglue.createPost(post);

tapglue.createLike(post.getId());

List<Like> likes = tapglue.retrieveLikesByUser(user1.getId());

assertThat(likes.get(0).getPost(), equalTo(post));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ public Observable<List<Like>> retrieveLikesForPost(String postId) {
return network.retrieveLikesForPost(postId);
}

public Observable<List<Like>> retrieveLikesByUser(String userId) {
return network.retrieveLikesByUser(userId);
}

/**
* @param postId id of the post to be commented.
* @param comment {@link com.tapglue.android.entities.Comment comment}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ public List<Like> retrieveLikesForPost(String postId) throws IOException {
return new RxWrapper<List<Like>>().unwrap(rxTapglue.retrieveLikesForPost(postId));
}

public List<Like> retrieveLikesByUser(String userId) throws IOException {
return new RxWrapper<List<Like>>().unwrap(rxTapglue.retrieveLikesByUser(userId));
}

/**
* Retrieve current users post feed.
* @return list of {@link com.tapglue.android.entities.Post posts}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Like {
private String createdAt;
private String updatedAt;
private User user;
private Post post;

public void setUser(User user) {
this.user = user;
Expand All @@ -24,6 +25,18 @@ public String getUserId() {
return userId;
}

public String getPostId() {
return postId;
}

public void setPost(Post post) {
this.post = post;
}

public Post getPost() {
return post;
}

public String getCreatedAt() {
return createdAt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.tapglue.android.http;

import com.google.gson.annotations.SerializedName;

import com.tapglue.android.entities.Like;
import com.tapglue.android.entities.Post;
import com.tapglue.android.entities.User;

import java.util.List;
Expand All @@ -25,4 +28,6 @@
class LikesFeed {
List<Like> likes;
Map<String, User> users;
@SerializedName("post_map")
Map<String, Post> posts;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public List<Like> call(LikesFeed feed) {
}
for(Like like: feed.likes) {
like.setUser(feed.users.get(like.getUserId()));
like.setPost(feed.posts.get(like.getPostId()));
}
return feed.likes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public Observable<List<Like>> retrieveLikesForPost(String id) {
return service.retrieveLikesForPost(id).map(new LikesFeedToList());
}

public Observable<List<Like>> retrieveLikesByUser(String userId) {
return service.retrieveLikesByUser(userId).map(new LikesFeedToList());
}

public Observable<Comment> createComment(String postId, Comment comment) {
return service.createComment(postId, comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ Observable<UsersFeed> searchUsersBySocialIds(@Path("platform") String platform,
@GET("/0.4/posts/{id}/likes")
Observable<LikesFeed> retrieveLikesForPost(@Path("id") String postId);

@GET("/0.4/users/{id}/likes")
Observable<LikesFeed> retrieveLikesByUser(@Path("id") String userId);

@POST("/0.4/posts/{id}/comments")
Observable<Comment> createComment(@Path("id") String postId,
@Body Comment comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,18 @@ public void retrieveLikesForPostCallsNetwork() {
assertThat(ts.getOnNextEvents(), hasItems(likes));
}

@Test
public void retrieveLikesByUserCallsNetwork() {
String id = "userId";
List<Like> likes = mock(List.class);
when(network.retrieveLikesByUser(id)).thenReturn(Observable.just(likes));
TestSubscriber<List<Like>> ts = new TestSubscriber<>();

tapglue.retrieveLikesByUser(id).subscribe(ts);

assertThat(ts.getOnNextEvents(), hasItems(likes));
}

@Test
public void createCommentCallsNetwork() {
String id = "postId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ public void retrieveLikesForPost() throws Exception {
assertThat(tapglue.retrieveLikesForPost(id), equalTo(likes));
}

@Test
public void retrieveLikesByUser() throws Exception {
String id = "postId";
List<Like> likes = mock(List.class);
when(rxTapglue.retrieveLikesByUser(id)).thenReturn(Observable.just(likes));

assertThat(tapglue.retrieveLikesByUser(id), equalTo(likes));
}

@Test
public void createComment() throws Exception {
String id = "postId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.tapglue.android.http;

import com.tapglue.android.entities.Like;
import com.tapglue.android.entities.Post;
import com.tapglue.android.entities.User;

import org.junit.Test;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void returnsLikes() {
LikesFeed feed = new LikesFeed();
feed.likes = likes;
feed.users = users;
feed.posts = new HashMap<>();

assertThat(converter.call(feed), equalTo(likes));
}
Expand All @@ -68,10 +70,32 @@ public void populatesUsersToLikes() {
LikesFeed feed = new LikesFeed();
feed.likes = likes;
feed.users = userMap;
feed.posts = new HashMap<>();

converter.call(feed);

verify(like).setUser(user);
}

@Test
public void populatesPostsToLikes() {
LikesFeedToList converter = new LikesFeedToList();
String id = "someId";
Like like = mock(Like.class);
List<Like> likes = Arrays.asList(like);
Map<String, Post> postMap = new HashMap<>();
Post post = mock(Post.class);
postMap.put(id, post);

when(like.getPostId()).thenReturn(id);

LikesFeed feed = new LikesFeed();
feed.likes = likes;
feed.users = new HashMap<>();
feed.posts = postMap;

converter.call(feed);

verify(like).setPost(post);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,22 @@ public void retrieveLikesForPostRetrievesFromService() throws Exception {
assertThat(ts.getOnNextEvents(), hasItems(list));
}

@Test
public void retrieveLikesByUserRetrievesFromService() throws Exception {
String id = "userId";
LikesFeed feed = mock(LikesFeed.class);
List<Like> list = mock(List.class);
LikesFeedToList converter = mock(LikesFeedToList.class);
when(service.retrieveLikesByUser(id)).thenReturn(Observable.just(feed));
whenNew(LikesFeedToList.class).withNoArguments().thenReturn(converter);
when(converter.call(feed)).thenReturn(list);
TestSubscriber<List<Like>> ts = new TestSubscriber<>();

network.retrieveLikesByUser(id).subscribe(ts);

assertThat(ts.getOnNextEvents(), hasItems(list));
}

@Test
public void createCommentPostsToService() {
String id = "postId";
Expand Down
2 changes: 1 addition & 1 deletion v1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.3'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
Expand Down

0 comments on commit befcb11

Please sign in to comment.