package it.com.atlassian.stash.rest.commit;

import com.atlassian.bitbucket.test.RepositoryTestHelper;
import com.atlassian.bitbucket.test.rest.RestAuthentication;
import com.atlassian.bitbucket.test.rest.commit.RestCommitHelper;
import com.atlassian.bitbucket.permission.Permission;
import it.com.atlassian.stash.BaseRestTest;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;

import static javax.ws.rs.core.Response.Status.NO_CONTENT;

public class CommitWatchResourceTest extends BaseRestTest {

    private static final String CS_ID = "d6edcbf924697ab811a867421dab60d954ccad99";
    private static final String CS_WATCH_TEST = "cswatchtest";
    private static final String CS_WATCHER = CS_WATCH_TEST + "_watcher";

    private static RestCommitHelper commit;

    @BeforeClass
    public static void setUpContext() throws Exception {
        getClassTestContext().project(CS_WATCH_TEST)
                .repository(CS_WATCH_TEST, CS_WATCH_TEST, new ClassPathResource(RepositoryTestHelper.DEFAULT_REPOSITORY))
                .user(CS_WATCHER)
                .projectPermission(CS_WATCH_TEST, CS_WATCHER, Permission.PROJECT_READ);

        commit = new RestCommitHelper(RestAuthentication.authenticated(CS_WATCHER, CS_WATCHER),
                CS_WATCH_TEST, CS_WATCH_TEST, CS_ID);
    }

    @Test
    public void testWatchPullRequest() {
        commit.request()
                .expect()
                .statusCode(NO_CONTENT.getStatusCode())
                .log().ifError()
                .post(commit.getWatchUrl());
    }

    @Test
    public void testUnwatchPullRequest() {
        commit.request()
                .expect()
                .statusCode(NO_CONTENT.getStatusCode())
                .log().ifError()
                .delete(commit.getWatchUrl());
    }
}
