Skip to content

Integration tests for EmojiRequest #145

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

Merged
merged 1 commit into from
May 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Emoji.class, new CreateEmojiRequest(guildId, name, image, roles)
);
}

public AsyncResponse<Emoji> deleteEmoji(long emojiId) {
return responseParser.callAndParse(Emoji.class, new DeleteEmojiRequest(guildId, emojiId));
public AsyncResponse<Void> deleteEmoji(long emojiId) {
return responseParser.callAndParse(Void.class, new DeleteEmojiRequest(guildId, emojiId));
}

public AsyncResponse<Emoji> getEmoji(long emojiId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.javadiscord.jdi.core.api;

import com.javadiscord.jdi.core.Guild;
import com.javadiscord.jdi.core.api.utils.DiscordImageUtil;
import com.javadiscord.jdi.core.models.emoji.Emoji;
import helpers.LiveDiscordHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.jupiter.api.Assertions.*;

class EmojiRequestTest {
private static Guild guild;

@BeforeAll
public static void setup() throws InterruptedException {
guild = new LiveDiscordHelper().getGuild();
}

@Test
void testCreateEmoji() throws InterruptedException, URISyntaxException, IOException {
CountDownLatch latch = new CountDownLatch(1);

URL url = EmojiRequestTest.class.getResource("/blep.png");

if (url == null) {
fail("/blep.png not found");
return;
}

Path path = Paths.get(url.toURI());

AsyncResponse<Emoji> asyncResponse = guild.emoji().createEmoji(
"test",
DiscordImageUtil.toDiscordString(path),
List.of());

asyncResponse.onSuccess(res -> {
assertEquals("test", res.name());
assertTrue(res.available());
assertFalse(res.animated());
latch.countDown();
});

asyncResponse.onError(Assertions::fail);

assertTrue(latch.await(30, TimeUnit.SECONDS));
}
@Test
void testDeleteEmoji() throws InterruptedException, URISyntaxException, IOException {
AtomicReference<Long> emojiId = new AtomicReference<>();

{
CountDownLatch latch = new CountDownLatch(1);

URL url = EmojiRequestTest.class.getResource("/blep.png");

if (url == null) {
fail("/blep.png not found");
return;
}

Path path = Paths.get(url.toURI());

AsyncResponse<Emoji> asyncResponse = guild.emoji().createEmoji(
"toDelete",
DiscordImageUtil.toDiscordString(path),
List.of());

asyncResponse.onSuccess(res -> {
assertEquals("toDelete", res.name());
assertTrue(res.available());
assertFalse(res.animated());
emojiId.set(res.id());
latch.countDown();
});

asyncResponse.onError(Assertions::fail);

assertTrue(latch.await(30, TimeUnit.SECONDS));
}

{
CountDownLatch latch = new CountDownLatch(1);

AsyncResponse<Void> asyncResponse = guild.emoji().deleteEmoji(emojiId.get());
asyncResponse.onSuccess(res -> latch.countDown());
asyncResponse.onError(Assertions::fail);

assertTrue(latch.await(30, TimeUnit.SECONDS));
}
}


}
Binary file added api/src/test/resources/blep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading