Skip to content

Commit

Permalink
✅ Add more tests #97
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Apr 21, 2024
1 parent 1507f99 commit 3e40d54
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import swiss.fihlon.apus.configuration.Configuration;
import swiss.fihlon.apus.social.Post;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

@SpringBootTest
Expand Down Expand Up @@ -100,6 +103,29 @@ void blockProfile() {
assertEquals(5, postsAfter.size());
}

@Test
void loadHiddenPosts() throws IOException {
final var filePath = getConfigDir().resolve("hiddenPosts");
Files.writeString(filePath, "P5\nP6");

final SocialService socialService = new SocialService(new NoOpTaskScheduler(), configuration, new TestSocialPlugin());
final List<Post> posts = socialService.getPosts(0);
final List<String> ids = posts.stream().map(Post::id).distinct().toList();
assertFalse(ids.contains("P5"));
assertFalse(ids.contains("P6"));
}

@Test
void loadBlockedProfiles() throws IOException {
final var filePath = getConfigDir().resolve("blockedProfiles");
Files.writeString(filePath, "profile1@localhost");

final SocialService socialService = new SocialService(new NoOpTaskScheduler(), configuration, new TestSocialPlugin());
final List<Post> posts = socialService.getPosts(0);
final List<String> profiles = posts.stream().map(Post::profile).distinct().toList();
assertFalse(profiles.contains("profile1@localhost"));
}

private static final class TestSocialPlugin implements SocialPlugin {

@Override
Expand Down

0 comments on commit 3e40d54

Please sign in to comment.