Skip to content

Commit 8292721

Browse files
author
Ed Fricker
committed
Ed - when embedding a company in the user update, we should also include any custom attributes for the company
1 parent e550321 commit 8292721

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

intercom-java/src/main/java/io/intercom/api/CompanyUpdateBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ private static CompanyWithStringPlan prepareUpdatableCompany(Company company) {
3838
updatableCompany.setSessionCount(company.getSessionCount());
3939
updatableCompany.setMonthlySpend(company.getMonthlySpend());
4040
updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt());
41+
if(company.getCustomAttributes() != null) {
42+
updatableCompany.getCustomAttributes().putAll(company.getCustomAttributes());
43+
}
4144
if (company.getPlan() != null) {
4245
updatableCompany.setPlan(company.getPlan().getName());
4346
}

intercom-java/src/test/java/io/intercom/api/CompanyUpdateBuilderTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77

88
import java.util.List;
9+
import java.util.Map;
910

1011
import static org.junit.Assert.*;
1112

@@ -60,4 +61,34 @@ public void testRemove() throws Exception {
6061
assertTrue(baconJson.contains("true"));
6162
}
6263

64+
@Test
65+
public void shouldIncludeCustomAttributes() throws Exception {
66+
67+
final Company withCustomAttributes = new Company().setName("Weyland Corp").setCompanyID("2093");
68+
69+
withCustomAttributes.addCustomAttribute(CustomAttribute.newIntegerAttribute("foodstuff-items", 246));
70+
withCustomAttributes.addCustomAttribute(CustomAttribute.newStringAttribute("bestseller", "fruity oaty bar"));
71+
72+
final List<CompanyWithStringPlan> updatedCompanies = CompanyUpdateBuilder.buildUserUpdateCompanies(new CompanyCollection(Lists.newArrayList(withCustomAttributes)), null);
73+
74+
CompanyWithStringPlan weylandCorp = null;
75+
76+
for (CompanyWithStringPlan updatedCompany : updatedCompanies) {
77+
if (updatedCompany.getCompanyID().equals("2093")) {
78+
weylandCorp = updatedCompany;
79+
}
80+
}
81+
82+
assertNotNull(weylandCorp);
83+
assertNotNull(weylandCorp.getCustomAttributes());
84+
Map<String, CustomAttribute> retrievedAttributes = weylandCorp.getCustomAttributes();
85+
86+
assertNotNull(retrievedAttributes.get("foodstuff-items"));
87+
assertTrue(retrievedAttributes.get("foodstuff-items").getValue().equals(246));
88+
assertNotNull(retrievedAttributes.get("bestseller"));
89+
assertTrue(retrievedAttributes.get("bestseller").getValue().equals("fruity oaty bar"));
90+
91+
92+
}
93+
6394
}

0 commit comments

Comments
 (0)