Skip to content

Commit

Permalink
chore: avoid http requests from test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Mar 6, 2025
1 parent d516450 commit 9c04a65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void createMessage(String webhookUrl, boolean sendImage, @NonNull Notific
.filter(StringUtils::isNotBlank)
.map(HttpUrl::parse)
.filter(Objects::nonNull)
.filter(url -> !"example.com".equalsIgnoreCase(url.host()))
.collect(Collectors.toList());
if (urlList.isEmpty()) return;

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/dinkplugin/notifiers/ExternalPluginNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ protected void setUp() {
@Test
void testNotify() {
// fire event
plugin.onPluginMessage(new PluginMessage("dink", "notify", samplePayload("https://example.com/")));
plugin.onPluginMessage(new PluginMessage("dink", "notify", samplePayload(null)));

// verify notification
verifyCreateMessage(
"https://example.com/",
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand All @@ -71,14 +71,14 @@ void testNotify() {
@Test
void testNoReplacements() {
// fire event
var payload = samplePayload("https://example.com/");
var payload = samplePayload(null);
payload.remove("replacements");
payload.put("text", "text with no replacements");
plugin.onPluginMessage(new PluginMessage("dink", "notify", payload));

// verify notification
verifyCreateMessage(
"https://example.com/",
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand All @@ -98,14 +98,14 @@ void testNoReplacements() {
@Test
void testMissingReplacement() {
// fire event
var payload = samplePayload("https://example.com/");
var payload = samplePayload(null);
payload.remove("replacements");
payload.put("text", "text with no custom replacement %USERNAME%");
plugin.onPluginMessage(new PluginMessage("dink", "notify", payload));

// verify notification
verifyCreateMessage(
"https://example.com/",
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand All @@ -126,14 +126,14 @@ void testMissingReplacement() {
@Test
void testPatternWithoutReplacement() {
// fire event
var payload = samplePayload("https://example.com/");
var payload = samplePayload(null);
payload.remove("replacements");
payload.put("text", "text with no custom replacement %XD%");
plugin.onPluginMessage(new PluginMessage("dink", "notify", payload));

// verify notification
verifyCreateMessage(
"https://example.com/",
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand All @@ -154,7 +154,7 @@ void testPatternWithoutReplacement() {
@Test
void testFallbackUrl() {
// update config mocks
String url = "https://discord.com/example";
String url = "https://example.com/";
when(config.externalWebhook()).thenReturn(url);

// fire event
Expand Down Expand Up @@ -191,7 +191,7 @@ void testImage() {

// verify notification
verifyCreateMessage(
null,
PRIMARY_WEBHOOK_URL,
true,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand Down Expand Up @@ -221,7 +221,7 @@ void testRequestImage() {

// verify notification
verifyCreateMessage(
null,
PRIMARY_WEBHOOK_URL,
true,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand Down Expand Up @@ -254,7 +254,7 @@ void testRequestImageDenied() {

// verify notification
verifyCreateMessage(
null,
PRIMARY_WEBHOOK_URL,
false,
NotificationBody.builder()
.type(NotificationType.EXTERNAL_PLUGIN)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void verifyCreateMessage(String url, boolean image, NotificationBody<?
Mockito.verify(messageHandler).createMessage(url, image, body);

// wait for http calls to complete
if (url != null && !url.isEmpty()) {
if (url != null && !url.isEmpty() && !"https://example.com/".equals(url)) {
Dispatcher dispatcher = httpClient.dispatcher();
while (dispatcher.queuedCallsCount() > 0 || dispatcher.runningCallsCount() > 0) {
// noinspection BusyWait - comply with discord's undocumented 30/60s ratelimit
Expand Down

0 comments on commit 9c04a65

Please sign in to comment.