package com.auth0.json.mgmt.tickets;

import com.auth0.json.JsonMatcher;
import com.auth0.json.JsonTest;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

public class PasswordChangeTicketTest extends JsonTest<PasswordChangeTicket> {

    private static final String readOnlyJson = "{\"ticket\":\"https://page.auth0.com/tickets/123\"}";

    @Test
    public void shouldSerialize() throws Exception {
        PasswordChangeTicket ticket = new PasswordChangeTicket("usr123");
        ticket.setResultUrl("https://page.auth0.com/result");
        ticket.setTTLSeconds(36000);
        ticket.setConnectionId("12");
        ticket.setEmail("me@auth0.com");
        ticket.setNewPassword("pass123");

        String serialized = toJSON(ticket);
        assertThat(serialized, is(notNullValue()));
        assertThat(serialized, JsonMatcher.hasEntry("user_id", "usr123"));
        assertThat(serialized, JsonMatcher.hasEntry("result_url", "https://page.auth0.com/result"));
        assertThat(serialized, JsonMatcher.hasEntry("ttl_sec", 36000));
        assertThat(serialized, JsonMatcher.hasEntry("new_password", "pass123"));
        assertThat(serialized, JsonMatcher.hasEntry("connection_id", "12"));
        assertThat(serialized, JsonMatcher.hasEntry("email", "me@auth0.com"));
    }

    @Test
    public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception {
        PasswordChangeTicket ticket = fromJSON(readOnlyJson, PasswordChangeTicket.class);
        assertThat(ticket, is(notNullValue()));

        assertThat(ticket.getTicket(), is("https://page.auth0.com/tickets/123"));
    }

}
@@ -1395,16 +1395,1029 @@
 %0A    %7D%0A%0A
+    %0A    @Test%0A    public void shouldSerializeWithCustomizedConnection() throws Exception %7B%0A        PasswordChangeTicket ticket = new PasswordChangeTicket(%22user@emailprovider.com%22, %22connid123%22);%0A        ticket.setResultUrl(%22https://page.auth0.com/result%22);%0A        ticket.setTTLSeconds(36000);%0A        ticket.setEmail(%22me@auth0.com%22);%0A        ticket.setNewPassword(%22pass123%22);%0A        ticket.setUserId(%22usr123%22);%0A%0A        String serialized = toJSON(ticket);%0A        assertThat(serialized, is(notNullValue()));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22user_id%22, %22usr123%22));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22result_url%22, %22https://page.auth0.com/result%22));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22ttl_sec%22, 36000));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22new_password%22, %22pass123%22));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22connection_id%22, %22connid123%22));%0A        assertThat(serialized, JsonMatcher.hasEntry(%22email%22, %22me@auth0.com%22));%0A    %7D%0A    %0A
     @Tes
@@ -2725,8 +2725,9 @@
     %7D%0A%0A%7D
+%0A

Add test case for PasswordChangeTicket with Email