Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ConversationPart.getAttachments() #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/Conversation.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ private static boolean isAdminQuery(Map<String, String> params) {
@JsonProperty("updated_at")
private long updatedAt;

@JsonProperty("customers")
private List<Customer> customers;

@JsonProperty("waiting_since")
private long waitingSince;

Expand Down Expand Up @@ -314,6 +317,8 @@ public long getUpdatedAt() {
return updatedAt;
}

public List<Customer> getCustomers() { return customers; }

public long getWaitingSince() {
return waitingSince;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConversationPart extends TypedData {
Expand All @@ -25,6 +27,9 @@ public class ConversationPart extends TypedData {
@JsonProperty("assigned_to")
private Admin assignedTo;

@JsonProperty("attachments")
private List<Attachment> attachments;

@JsonProperty("created_at")
private long createdAt;

Expand Down Expand Up @@ -61,6 +66,8 @@ public Admin getAssignedTo() {
return assignedTo;
}

public List<Attachment> getAttachments() { return attachments; }

public long getCreatedAt() {
return createdAt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.intercom.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.io.IOException;
import java.util.List;

import static io.intercom.api.TestSupport.load;

import static org.junit.Assert.*;


@RunWith(PowerMockRunner.class)
@PrepareForTest( { Conversation.class })
public class ConversationPartTest {

private static ObjectMapper objectMapper;

@BeforeClass
public static void beforeClass() {
objectMapper = MapperSupport.objectMapper();
}

@Test
public void testGetConversationPartDetailsFromConversationNoAttachments() throws IOException {
PowerMockito.mockStatic(Conversation.class);

String json = load("conversation_no_attachments.json");
final Conversation conversation = objectMapper.readValue(json, Conversation.class);
final List<ConversationPart> parts = conversation.getConversationPartCollection().getPage();

assertEquals(2, parts.size());

final ConversationPart part = parts.get(0);

assertEquals("142533411", part.getId());
assertEquals("comment", part.getPartType());
assertEquals("<p>dm-9187dba8-fb3b-cb99-da05-37a932d3d678</p>", part.getBody());
assertEquals(1468031160, part.getCreatedAt());
assertEquals(1468031160, part.getUpdatedAt());
assertEquals(1468031160, part.getNotifiedAt());
assertEquals(null, part.getAssignedTo());
assertEquals("576c1a139d0baad1010001111", part.getAuthor().getId());
assertEquals("user", part.getAuthor().getType());
assertEquals(0, part.getAttachments().size());

PowerMockito.verifyStatic(Mockito.never());
Conversation.find(conversation.getId());
}

@Test
public void testGetAttachmentsFromConversationPart() throws IOException {
String json = load("conversation_part_with_attachments.json");
final ConversationPart part = objectMapper.readValue(json, ConversationPart.class);

final List<Attachment> attachments = part.getAttachments();
assertEquals(2, attachments.size());

final Attachment attachment = attachments.get(0);

assertEquals("upload", attachment.getType());
assertEquals("Attachment.pdf", attachment.getName());
assertEquals("https://api.example.com/uploads/111222333", attachment.getUrl());
assertEquals("application/pdf", attachment.getContentType());
assertEquals(8388608, attachment.getFilesize());
assertEquals(1024, attachment.getWidth());
assertEquals(8192, attachment.getHeight());
}
}
13 changes: 13 additions & 0 deletions intercom-java/src/test/java/io/intercom/api/ConversationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ public void testGetEmptyTagFromTagCollection() throws IOException {
PowerMockito.verifyStatic(Mockito.times(1));
Conversation.find(conversation.getId());
}

@Test
public void testGetCustomersFromConversation() throws IOException {
PowerMockito.mockStatic(Conversation.class);

String json = load("conversation.json");
final Conversation conversation = objectMapper.readValue(json, Conversation.class);
assertEquals(2, conversation.getCustomers().size());

PowerMockito.verifyStatic(Mockito.never());
Conversation.find(conversation.getId());
}

private Map<String, String> buildRequestParameters(String html) {
Map<String, String> params2 = Maps.newHashMap();
params2.put("type", "admin");
Expand Down
10 changes: 10 additions & 0 deletions intercom-java/src/test/resources/conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
],
"total_count": 2
},
"customers": [
{
"id": "cce765411111",
"type": "lead"
},
{
"id": "ee88370001110101",
"type": "user"
}
],
"open": true,
"read": false,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"type": "conversation_part",
"id": "142533411",
"part_type": "comment",
"body": "<p>dm-9187dba8-fb3b-cb99-da05-37a932d3d678</p>",
"created_at": 1468031160,
"updated_at": 1468031160,
"notified_at": 1468031160,
"assigned_to": null,
"author": {
"type": "user",
"id": "576c1a139d0baad1010001111"
},
"attachments": [
{
"type": "upload",
"name": "Attachment.pdf",
"url": "https://api.example.com/uploads/111222333",
"content_type": "application/pdf",
"filesize": 8388608,
"width": 1024,
"height": 8192
},
{
"type": "upload",
"name": "Attachment.txt",
"url": "https://api.example.com/uploads/222333444",
"content_type": "text/plain",
"filesize": 16000,
"width": 40,
"height": 400
}
],
"external_id": null
}