package com.scopely.integration.leanplum;

import com.scopely.integration.leanplum.model.SendMessage;
import com.scopely.integration.leanplum.model.SendMessageResponse;
import org.junit.Test;
import rx.observers.TestSubscriber;

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

public class SendMessageTest extends ProductionApiClientTest {
    @Test
    public void testSendMessage_noRecipient() throws Exception {
        TestSubscriber<LeanplumActionResponse> testSubscriber = send(new SendMessage(6033514340810752l));
        testSubscriber.assertNoErrors();
        assertThat(testSubscriber.getOnNextEvents()).hasSize(1);
        assertThat(testSubscriber.getOnNextEvents().get(0)).isInstanceOf(SendMessageResponse.class);
        SendMessageResponse response = (SendMessageResponse) testSubscriber.getOnNextEvents().get(0);
        // Recipient is not a match
        assertThat(response.messagesSent).isEqualTo(0);
    }

    @Test
    public void testSendMessage_realRecipient() throws Exception {
        TestSubscriber<LeanplumActionResponse> testSubscriber = awaitAndTransform(apiForDevice("d926b3ba-8e45-4545-a220-f449f1b24679").sendMessage(new SendMessage(4976713210003456l)));
        testSubscriber.assertNoErrors();
        assertThat(testSubscriber.getOnNextEvents()).hasSize(1);
        assertThat(testSubscriber.getOnNextEvents().get(0)).isInstanceOf(SendMessageResponse.class);
        SendMessageResponse response = (SendMessageResponse) testSubscriber.getOnNextEvents().get(0);
        // Recipient is a match
        assertThat(response.messagesSent).isEqualTo(1);
    }

    private TestSubscriber<LeanplumActionResponse> send(SendMessage sendMessage) {
        return awaitAndTransform(leanplumApi.sendMessage(sendMessage));
    }
}

@@ -36,16 +36,76 @@
 nplum;%0A%0A
+import com.scopely.integration.leanplum.model.ActionParams;%0A
 import c
@@ -1240,25 +1240,774 @@
 age(
-4976713210003456l
+6219785998696448l)));%0A        testSubscriber.assertNoErrors();%0A        assertThat(testSubscriber.getOnNextEvents()).hasSize(1);%0A        assertThat(testSubscriber.getOnNextEvents().get(0)).isInstanceOf(SendMessageResponse.class);%0A        SendMessageResponse response = (SendMessageResponse) testSubscriber.getOnNextEvents().get(0);%0A        // Recipient is a match%0A        assertThat(response.messagesSent).isEqualTo(1);%0A    %7D%0A%0A    @Test%0A    public void testSendMessage_realRecipient_withParams() throws Exception %7B%0A        TestSubscriber%3CLeanplumActionResponse%3E testSubscriber = awaitAndTransform(apiForDevice(%22d926b3ba-8e45-4545-a220-f449f1b24679%22).sendMessage(new SendMessage(6219785998696448l,%0A                ActionParams.of(%22name%22, %22Jane User%22, %22numMessages%22, 2)
 )));

Add tests of message sending