package com.uwetrottmann.trakt.v2.services;

import com.uwetrottmann.trakt.v2.BaseTestCase;
import com.uwetrottmann.trakt.v2.TestData;
import com.uwetrottmann.trakt.v2.entities.Comment;
import com.uwetrottmann.trakt.v2.entities.Episode;
import com.uwetrottmann.trakt.v2.entities.EpisodeIds;
import org.junit.Test;

import static org.fest.assertions.api.Assertions.assertThat;

public class CommentsTest extends BaseTestCase {

    @Test
    public void test_post() {
        Episode episode = new Episode();
        episode.ids= new EpisodeIds();
        episode.ids.tvdb = TestData.EPISODE_TVDB_ID;
        Comment comment = new Comment(episode, "This is toasty!", true, false);

        Comment commentResponse = getTrakt().comments().post(comment);
        assertThat(commentResponse.comment).isEqualTo(comment.comment);
        assertThat(commentResponse.spoiler).isEqualTo(comment.spoiler);
        assertThat(commentResponse.spoiler).isEqualTo(comment.review);
    }

}

@@ -306,16 +306,85 @@
 it.Test;
+%0Aimport retrofit.client.Response;%0A%0Aimport java.net.HttpURLConnection;
 %0A%0Aimport
@@ -529,16 +529,1206 @@
 ost() %7B%0A
+        Comment comment = new Comment(buildTestEpisode(), %22This is toasty!%22, true, false);%0A%0A        Comment commentResponse = getTrakt().comments().post(comment);%0A        assertCommentResponse(comment, commentResponse);%0A    %7D%0A%0A    @Test%0A    public void test_update() throws InterruptedException %7B%0A        // first post a new comment%0A        Comment comment = new Comment(buildTestEpisode(), %22This is toasty!%22, true, false);%0A        Comment commentResponse = getTrakt().comments().post(comment);%0A%0A        // give the server some time to handle the data%0A        Thread.sleep(3000);%0A%0A        // update the new comment%0A        Comment updatedComment = new Comment(%22This is toasty! I was just updated.%22, false, false);%0A        commentResponse = getTrakt().comments().update(commentResponse.id, updatedComment);%0A        assertCommentResponse(updatedComment, commentResponse);%0A    %7D%0A%0A    private void assertCommentResponse(Comment expected, Comment actual) %7B%0A        assertThat(actual.comment).isEqualTo(expected.comment);%0A        assertThat(actual.spoiler).isEqualTo(expected.spoiler);%0A        assertThat(actual.review).isEqualTo(expected.review);%0A    %7D%0A%0A    private Episode buildTestEpisode() %7B%0A
         
@@ -1779,16 +1779,17 @@
 sode.ids
+ 
 = new Ep
@@ -1853,16 +1853,153 @@
 VDB_ID;%0A
+        return episode;%0A    %7D%0A%0A    @Test%0A    public void test_delete() throws InterruptedException %7B%0A        // first post a new comment%0A
         
@@ -2028,23 +2028,34 @@
 Comment(
-e
+buildTestE
 pisode
+()
 , %22This 
@@ -2056,32 +2056,58 @@
 %22This is toasty!
+ I should be deleted soon.
 %22, true, false);
@@ -2099,33 +2099,32 @@
 , true, false);%0A
-%0A
         Comment 
@@ -2174,32 +2174,33 @@
 t(comment);%0A
+%0A
         
 assertThat(c
@@ -2191,80 +2191,93 @@
     
-assertThat(commentResponse.comment).isEqualTo(comment.comment
+// give the server some time to handle the data%0A        Thread.sleep(3000
 );%0A
+%0A
         
 asse
@@ -2276,61 +2276,100 @@
     
-assertThat(commentResponse.spoiler).isEqualTo
+// delete the comment again%0A        Response response = getTrakt().comments().delete
 (comment
 .spo
@@ -2364,24 +2364,27 @@
 (comment
-.spoiler
+Response.id
 );%0A     
@@ -2401,57 +2401,73 @@
 hat(
-commentResponse.spoiler).isEqualTo(comment.review
+response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT
 );%0A 
@@ -2471,11 +2471,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Add tests for updating and deleting a comment.