Skip to content

Commit 016e1f0

Browse files
authored
Add EmojiRequest tests (#145)
1 parent adfd89b commit 016e1f0

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

api/src/main/java/com/javadiscord/jdi/core/api/EmojiRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Emoji.class, new CreateEmojiRequest(guildId, name, image, roles)
2121
);
2222
}
2323

24-
public AsyncResponse<Emoji> deleteEmoji(long emojiId) {
25-
return responseParser.callAndParse(Emoji.class, new DeleteEmojiRequest(guildId, emojiId));
24+
public AsyncResponse<Void> deleteEmoji(long emojiId) {
25+
return responseParser.callAndParse(Void.class, new DeleteEmojiRequest(guildId, emojiId));
2626
}
2727

2828
public AsyncResponse<Emoji> getEmoji(long emojiId) {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.javadiscord.jdi.core.api;
2+
3+
import com.javadiscord.jdi.core.Guild;
4+
import com.javadiscord.jdi.core.api.utils.DiscordImageUtil;
5+
import com.javadiscord.jdi.core.models.emoji.Emoji;
6+
import helpers.LiveDiscordHelper;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.io.IOException;
12+
import java.net.URISyntaxException;
13+
import java.net.URL;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
16+
import java.util.List;
17+
import java.util.concurrent.CountDownLatch;
18+
import java.util.concurrent.TimeUnit;
19+
import java.util.concurrent.atomic.AtomicReference;
20+
21+
import static org.junit.jupiter.api.Assertions.*;
22+
23+
class EmojiRequestTest {
24+
private static Guild guild;
25+
26+
@BeforeAll
27+
public static void setup() throws InterruptedException {
28+
guild = new LiveDiscordHelper().getGuild();
29+
}
30+
31+
@Test
32+
void testCreateEmoji() throws InterruptedException, URISyntaxException, IOException {
33+
CountDownLatch latch = new CountDownLatch(1);
34+
35+
URL url = EmojiRequestTest.class.getResource("/blep.png");
36+
37+
if (url == null) {
38+
fail("/blep.png not found");
39+
return;
40+
}
41+
42+
Path path = Paths.get(url.toURI());
43+
44+
AsyncResponse<Emoji> asyncResponse = guild.emoji().createEmoji(
45+
"test",
46+
DiscordImageUtil.toDiscordString(path),
47+
List.of());
48+
49+
asyncResponse.onSuccess(res -> {
50+
assertEquals("test", res.name());
51+
assertTrue(res.available());
52+
assertFalse(res.animated());
53+
latch.countDown();
54+
});
55+
56+
asyncResponse.onError(Assertions::fail);
57+
58+
assertTrue(latch.await(30, TimeUnit.SECONDS));
59+
}
60+
@Test
61+
void testDeleteEmoji() throws InterruptedException, URISyntaxException, IOException {
62+
AtomicReference<Long> emojiId = new AtomicReference<>();
63+
64+
{
65+
CountDownLatch latch = new CountDownLatch(1);
66+
67+
URL url = EmojiRequestTest.class.getResource("/blep.png");
68+
69+
if (url == null) {
70+
fail("/blep.png not found");
71+
return;
72+
}
73+
74+
Path path = Paths.get(url.toURI());
75+
76+
AsyncResponse<Emoji> asyncResponse = guild.emoji().createEmoji(
77+
"toDelete",
78+
DiscordImageUtil.toDiscordString(path),
79+
List.of());
80+
81+
asyncResponse.onSuccess(res -> {
82+
assertEquals("toDelete", res.name());
83+
assertTrue(res.available());
84+
assertFalse(res.animated());
85+
emojiId.set(res.id());
86+
latch.countDown();
87+
});
88+
89+
asyncResponse.onError(Assertions::fail);
90+
91+
assertTrue(latch.await(30, TimeUnit.SECONDS));
92+
}
93+
94+
{
95+
CountDownLatch latch = new CountDownLatch(1);
96+
97+
AsyncResponse<Void> asyncResponse = guild.emoji().deleteEmoji(emojiId.get());
98+
asyncResponse.onSuccess(res -> latch.countDown());
99+
asyncResponse.onError(Assertions::fail);
100+
101+
assertTrue(latch.await(30, TimeUnit.SECONDS));
102+
}
103+
}
104+
105+
106+
}

api/src/test/resources/blep.png

157 KB
Loading

0 commit comments

Comments
 (0)