From c8d0cc91b6a5866d996a0fa3616efff8855392c9 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:33:24 +0200 Subject: [PATCH] Fixed react bundle getting exported when export is disabled Caused by missing checks before react export. Affects issues: - #3384 --- .../plan/delivery/export/Exporter.java | 6 ++++ .../delivery/export/ReactExporterTest.java | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java index daf9222f7..4ff277c4b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java @@ -166,6 +166,12 @@ public class Exporter extends FileExporter { } public void exportReact() throws ExportException { + if (config.isFalse(ExportSettings.PLAYER_PAGES) + && config.isFalse(ExportSettings.SERVER_PAGE) + && config.isFalse(ExportSettings.PLAYERS_PAGE)) { + return; + } + Path toDirectory = config.getPageExportPath(); try { diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ReactExporterTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ReactExporterTest.java index dd57ccf47..e05f0f3e2 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ReactExporterTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ReactExporterTest.java @@ -19,6 +19,7 @@ package com.djrapitops.plan.delivery.export; import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.exceptions.ExportException; import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.ExportSettings; import extension.FullSystemExtension; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,12 +29,12 @@ import org.junit.jupiter.api.function.Executable; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @ExtendWith(FullSystemExtension.class) class ReactExporterTest { @@ -50,6 +51,7 @@ class ReactExporterTest { @Test void allReactFilesAreExported(PlanConfig config, Exporter exporter) throws ExportException, IOException { + config.set(ExportSettings.SERVER_PAGE, true); Path exportPath = config.getPageExportPath(); exporter.exportReact(); @@ -65,4 +67,26 @@ class ReactExporterTest { .map(path -> (Executable) () -> assertTrue(filesExported.contains(path))) .toList()); } + + @Test + void noReactFilesAreExported(PlanConfig config, Exporter exporter) throws ExportException, IOException { + config.set(ExportSettings.PLAYER_PAGES, false); + config.set(ExportSettings.SERVER_PAGE, false); + config.set(ExportSettings.PLAYERS_PAGE, false); + Path exportPath = config.getPageExportPath(); + Files.deleteIfExists(exportPath); + + exporter.exportReact(); + + assertFalse(Files.exists(exportPath), () -> { + try { + return "Some files got exported: " + Files.list(exportPath) + .map(path -> path.relativize(exportPath)) + .map(s -> s + "\n") + .toList(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + }); + } } \ No newline at end of file