Skip to content

Commit 5717ff3

Browse files
committed
Merge branch 'master' into bug/remove-length-constraint-lookup-organization-by-externalid
2 parents 8c179e6 + 0355786 commit 5717ff3

File tree

7 files changed

+211
-10
lines changed

7 files changed

+211
-10
lines changed

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
# Drafts your next Release notes as Pull Requests are merged into "master"
14-
- uses: release-drafter/release-drafter@v5.23.0
14+
- uses: release-drafter/release-drafter@v5.24.0
1515
env:
1616
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<dependency>
9999
<groupId>com.fasterxml.jackson</groupId>
100100
<artifactId>jackson-bom</artifactId>
101-
<version>2.15.0</version>
101+
<version>2.15.2</version>
102102
<type>pom</type>
103103
<scope>import</scope>
104104
</dependency>

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.zendesk.client.v2.model.TicketImport;
5252
import org.zendesk.client.v2.model.TicketPage;
5353
import org.zendesk.client.v2.model.TicketResult;
54+
import org.zendesk.client.v2.model.TimeZone;
5455
import org.zendesk.client.v2.model.Topic;
5556
import org.zendesk.client.v2.model.Trigger;
5657
import org.zendesk.client.v2.model.TwitterMonitor;
@@ -2588,6 +2589,11 @@ private Uri buildContentTagsSearchUrl(int pageSize, String namePrefixFilter, Str
25882589
return cnst(uriBuilder.toString());
25892590
}
25902591

2592+
public List<TimeZone> getTimeZones(){
2593+
return complete(submit(req("GET", cnst("/time_zones.json")), handleList(TimeZone.class,
2594+
"time_zones")));
2595+
}
2596+
25912597
//////////////////////////////////////////////////////////////////////
25922598
// Helper methods
25932599
//////////////////////////////////////////////////////////////////////
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Objects;
6+
7+
/**
8+
* @author nkharabaruk
9+
* @since 22/06/2023 22:00
10+
*/
11+
public class TimeZone {
12+
13+
private String translatedName;
14+
private String name;
15+
private String ianaName;
16+
private int offset;
17+
private String formattedOffset;
18+
19+
@JsonProperty("translated_name")
20+
public String getTranslatedName() {
21+
return translatedName;
22+
}
23+
24+
public void setTranslatedName(String translatedName) {
25+
this.translatedName = translatedName;
26+
}
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
36+
@JsonProperty("iana_name")
37+
public String getIanaName() {
38+
return ianaName;
39+
}
40+
41+
public void setIanaName(String ianaName) {
42+
this.ianaName = ianaName;
43+
}
44+
45+
public int getOffset() {
46+
return offset;
47+
}
48+
49+
public void setOffset(int offset) {
50+
this.offset = offset;
51+
}
52+
53+
@JsonProperty("formatted_offset")
54+
public String getFormattedOffset() {
55+
return formattedOffset;
56+
}
57+
58+
public void setFormattedOffset(String formattedOffset) {
59+
this.formattedOffset = formattedOffset;
60+
}
61+
62+
@Override
63+
public boolean equals(Object o) {
64+
if (this == o) return true;
65+
if (o == null || getClass() != o.getClass()) return false;
66+
TimeZone timeZone = (TimeZone) o;
67+
return offset == timeZone.offset && Objects.equals(translatedName, timeZone.translatedName) &&
68+
Objects.equals(name, timeZone.name) && Objects.equals(ianaName, timeZone.ianaName) &&
69+
Objects.equals(formattedOffset, timeZone.formattedOffset);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
return Objects.hash(translatedName, name, ianaName, offset, formattedOffset);
75+
}
76+
}

src/main/java/org/zendesk/client/v2/model/User.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class User extends Collaborator implements SearchResultEntity, Serializab
3030
private Long localeId;
3131
private String locale;
3232
private String timeZone;
33+
private String ianaTimeZone;
3334
private Date lastLoginAt;
3435
private String phone;
3536
private Boolean restrictedAgent;
@@ -291,6 +292,15 @@ public void setTimeZone(String timeZone) {
291292
this.timeZone = timeZone;
292293
}
293294

295+
@JsonProperty("iana_time_zone")
296+
public String getIanaTimeZone() {
297+
return ianaTimeZone;
298+
}
299+
300+
public void setIanaTimeZone(String ianaTimeZone) {
301+
this.ianaTimeZone = ianaTimeZone;
302+
}
303+
294304
@JsonProperty("updated_at")
295305
public Date getUpdatedAt() {
296306
return updatedAt;
@@ -408,12 +418,12 @@ public boolean equals(Object o) {
408418
Objects.equals(active, user.active) && Objects.equals(verified, user.verified) &&
409419
Objects.equals(shared, user.shared) && Objects.equals(localeId, user.localeId) &&
410420
Objects.equals(locale, user.locale) && Objects.equals(timeZone, user.timeZone) &&
411-
Objects.equals(lastLoginAt, user.lastLoginAt) && Objects.equals(phone, user.phone) &&
412-
Objects.equals(restrictedAgent, user.restrictedAgent) && Objects.equals(signature, user.signature) &&
413-
Objects.equals(details, user.details) && Objects.equals(notes, user.notes) &&
414-
Objects.equals(organizationId, user.organizationId) && role == user.role &&
415-
Objects.equals(customRoleId, user.customRoleId) && Objects.equals(moderator, user.moderator) &&
416-
ticketRestriction == user.ticketRestriction &&
421+
Objects.equals(ianaTimeZone, user.ianaTimeZone) && Objects.equals(lastLoginAt, user.lastLoginAt) &&
422+
Objects.equals(phone, user.phone) && Objects.equals(restrictedAgent, user.restrictedAgent) &&
423+
Objects.equals(signature, user.signature) && Objects.equals(details, user.details) &&
424+
Objects.equals(notes, user.notes) && Objects.equals(organizationId, user.organizationId)
425+
&& role == user.role && Objects.equals(customRoleId, user.customRoleId)
426+
&& Objects.equals(moderator, user.moderator) && ticketRestriction == user.ticketRestriction &&
417427
Objects.equals(onlyPrivateComments, user.onlyPrivateComments) &&
418428
Objects.equals(tags, user.tags) && Objects.equals(suspended, user.suspended) &&
419429
Objects.equals(photo, user.photo) && Objects.equals(identities, user.identities) &&
@@ -427,7 +437,7 @@ public boolean equals(Object o) {
427437
@Override
428438
public int hashCode() {
429439
return Objects.hash(id, url, externalId, alias, createdAt, updatedAt, active, verified, shared, localeId,
430-
locale, timeZone, lastLoginAt, phone, restrictedAgent, signature, details, notes, organizationId,
440+
locale, timeZone, ianaTimeZone, lastLoginAt, phone, restrictedAgent, signature, details, notes, organizationId,
431441
role, customRoleId, moderator, ticketRestriction, onlyPrivateComments, tags, suspended, photo,
432442
identities, remotePhotoUrl, userFields, chatOnly, sharedPhoneNumber, defaultGroupId, roleType,
433443
twoFactorAuthEnabled, reportCsv);

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,22 @@ public void createUsers() throws Exception {
911911
}
912912
}
913913

914+
@Test
915+
public void createUser() throws Exception {
916+
// given
917+
createClientWithTokenOrPassword();
918+
final User userToCreate = newTestUser();
919+
userToCreate.setTimeZone("Pacific Time (US & Canada)");
920+
921+
// when
922+
User createdUser = instance.createUser(userToCreate);
923+
924+
// then
925+
assertThat("A unique ID must be set", createdUser.getId(), notNullValue());
926+
assertEquals("Time Zone must be set", userToCreate.getTimeZone(), createdUser.getTimeZone());
927+
assertEquals("Iana Time Zone must be automatically set", "America/Los_Angeles", createdUser.getIanaTimeZone());
928+
}
929+
914930
@Test
915931
public void updateUsers() throws Exception {
916932
createClientWithTokenOrPassword();
@@ -1266,7 +1282,7 @@ public void getUsersById() throws Exception {
12661282
assertThat(user.getName(), notNullValue());
12671283
}
12681284
}
1269-
1285+
12701286
@Test
12711287
public void getUsersIncrementally() throws Exception {
12721288
createClientWithTokenOrPassword();
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
6+
import org.apache.commons.text.RandomStringGenerator;
7+
import org.junit.*;
8+
import org.zendesk.client.v2.Zendesk;
9+
10+
import java.util.Arrays;
11+
import java.util.Collections;
12+
import java.util.List;
13+
14+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
15+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
public class TimeZoneTest {
19+
20+
private static final String MOCK_URL_FORMATTED_STRING = "http://localhost:%d";
21+
public static final RandomStringGenerator RANDOM_STRING_GENERATOR =
22+
new RandomStringGenerator.Builder().withinRange('a', 'z').build();
23+
private static final String MOCK_API_TOKEN = RANDOM_STRING_GENERATOR.generate(15);
24+
private static final String MOCK_USERNAME = RANDOM_STRING_GENERATOR.generate(10).toLowerCase() + "@cloudbees.com";
25+
26+
@ClassRule
27+
public static WireMockClassRule zendeskApiClass = new WireMockClassRule(options()
28+
.dynamicPort()
29+
.dynamicHttpsPort()
30+
.usingFilesUnderClasspath("wiremock")
31+
);
32+
33+
@Rule
34+
public WireMockClassRule zendeskApiMock = zendeskApiClass;
35+
36+
private Zendesk client;
37+
private final ObjectMapper objectMapper = Zendesk.createMapper();
38+
39+
@Before
40+
public void setUp() {
41+
int ephemeralPort = zendeskApiMock.port();
42+
String hostname = String.format(MOCK_URL_FORMATTED_STRING, ephemeralPort);
43+
client = new Zendesk.Builder(hostname)
44+
.setUsername(MOCK_USERNAME)
45+
.setToken(MOCK_API_TOKEN)
46+
.build();
47+
}
48+
49+
@After
50+
public void closeClient() {
51+
if (client != null) {
52+
client.close();
53+
}
54+
client = null;
55+
}
56+
57+
@Test
58+
public void getTimeZones() throws JsonProcessingException {
59+
60+
TimeZone timeZone1 = new TimeZone();
61+
timeZone1.setTranslatedName("Pacific Time (US & Canada)");
62+
timeZone1.setName("Pacific Time (US & Canada)");
63+
timeZone1.setIanaName("America/Los_Angeles");
64+
timeZone1.setOffset(-420);
65+
timeZone1.setFormattedOffset("GMT-07:00");
66+
67+
TimeZone timeZone2 = new TimeZone();
68+
timeZone1.setTranslatedName("Kyiv");
69+
timeZone1.setName("Kyiv");
70+
timeZone1.setIanaName("Europe/Kiev");
71+
timeZone1.setOffset(180);
72+
timeZone1.setFormattedOffset("GMT+03:00");
73+
74+
String expectedJsonResponse = objectMapper.writeValueAsString(
75+
Collections.singletonMap("time_zones", Arrays.asList(timeZone1, timeZone2)));
76+
77+
zendeskApiMock.stubFor(
78+
get(
79+
urlPathEqualTo("/api/v2/time_zones.json"))
80+
.willReturn(ok()
81+
.withBody(expectedJsonResponse)
82+
)
83+
);
84+
85+
List<TimeZone> timeZones = client.getTimeZones();
86+
87+
zendeskApiMock.verify(getRequestedFor(
88+
urlPathEqualTo("/api/v2/time_zones.json"))
89+
);
90+
91+
assertThat(timeZones).containsExactly(timeZone1, timeZone2);
92+
}
93+
}

0 commit comments

Comments
 (0)