diff --git a/src/main/java/app/fyreplace/api/data/dev/DataSeeder.java b/src/main/java/app/fyreplace/api/data/dev/DataSeeder.java index f23be18..04f3a32 100644 --- a/src/main/java/app/fyreplace/api/data/dev/DataSeeder.java +++ b/src/main/java/app/fyreplace/api/data/dev/DataSeeder.java @@ -1,5 +1,6 @@ package app.fyreplace.api.data.dev; +import static java.util.Objects.requireNonNull; import static java.util.stream.IntStream.range; import app.fyreplace.api.data.Block; @@ -19,6 +20,7 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; import jakarta.transaction.Transactional; +import java.io.IOException; import org.eclipse.microprofile.config.inject.ConfigProperty; @SuppressWarnings({"UnusedReturnValue", "unused"}) @@ -44,8 +46,8 @@ public void onShutdown(@Observes final ShutdownEvent event) { @Transactional public void insertData() { - range(0, 20).forEach(i -> createUser("user_" + i, true)); - range(0, 10).forEach(i -> createUser("user_inactive_" + i, false)); + range(0, 20).forEach(i -> createUser("user_" + i, true, i % 2 == 0)); + range(0, 10).forEach(i -> createUser("user_inactive_" + i, false, false)); final var user = User.findByUsername("user_0"); range(0, 20).forEach(i -> createPost(user, "Post " + i, true, false)); range(0, 20).forEach(i -> createPost(user, "Draft " + i, false, false)); @@ -74,12 +76,24 @@ public void deleteData() { } @Transactional(Transactional.TxType.REQUIRES_NEW) - public User createUser(final String username, final boolean active) { + public User createUser(final String username, final boolean active, final boolean hasAvatar) { final var user = new User(); user.username = username; user.active = active; user.persist(); + if (hasAvatar) { + try (final var stream = getClass().getResourceAsStream("/META-INF/resources/images/logo-maskable.png")) { + final var storedFile = new StoredFile( + "avatars", user.username, requireNonNull(stream).readAllBytes()); + storedFile.persist(); + user.avatar = storedFile; + user.persist(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } + final var email = new Email(); email.user = user; email.email = username + "@example.org"; diff --git a/src/test/java/app/fyreplace/api/testing/UserTestsBase.java b/src/test/java/app/fyreplace/api/testing/UserTestsBase.java index a530ae2..9cfa11c 100644 --- a/src/test/java/app/fyreplace/api/testing/UserTestsBase.java +++ b/src/test/java/app/fyreplace/api/testing/UserTestsBase.java @@ -11,8 +11,8 @@ public class UserTestsBase extends TransactionalTestsBase { @Override public void beforeEach() { super.beforeEach(); - range(0, getActiveUserCount()).forEach(i -> dataSeeder.createUser("user_" + i, true)); - range(0, getInactiveUserCount()).forEach(i -> dataSeeder.createUser("user_inactive_" + i, false)); + range(0, getActiveUserCount()).forEach(i -> dataSeeder.createUser("user_" + i, true, false)); + range(0, getInactiveUserCount()).forEach(i -> dataSeeder.createUser("user_inactive_" + i, false, false)); } public int getActiveUserCount() {