Fixed react bundle getting exported when export is disabled

Caused by missing checks before react export.

Affects issues:
- #3384
This commit is contained in:
Aurora Lahtela 2024-01-21 19:33:24 +02:00
parent ae85f39871
commit c8d0cc91b6
2 changed files with 32 additions and 2 deletions

View File

@ -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 {

View File

@ -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);
}
});
}
}