Fix posting task tests for Facebook credential flow

This commit is contained in:
Codex
2026-04-12 21:54:57 +05:00
parent 484663c670
commit 3abdc34e60
@@ -124,17 +124,17 @@ class PostingTaskServiceTest {
@Test
void createTasksFromStrategyShouldThrowWhenCredentialsAreMissing() {
MarketingStrategy strategy = completedStrategy("user-1", List.of(
calendarItem("facebook", LocalDateTime.now().plusDays(1), "Post", List.of("#marketing"))));
calendarItem("telegram", LocalDateTime.now().plusDays(1), "Post", List.of("#marketing"))));
when(strategyRepository.findById("strategy-1")).thenReturn(Optional.of(strategy));
when(credentialsService.hasCredentials("user-1", "facebook")).thenReturn(false);
when(credentialsService.hasCredentials("user-1", "telegram")).thenReturn(false);
IllegalStateException exception = assertThrows(
IllegalStateException.class,
() -> postingTaskService.createTasksFromStrategy("strategy-1"));
assertEquals(
"Credentials not found for platform: facebook. Please configure credentials first.",
"Credentials not found for platform: telegram. Please configure credentials first.",
exception.getMessage());
verify(taskRepository, never()).saveAll(anyList());
}
@@ -146,7 +146,6 @@ class PostingTaskServiceTest {
List<PostingTask> existingTasks = List.of(task("task-1", "user-1", "facebook", "pending"));
when(strategyRepository.findById("strategy-1")).thenReturn(Optional.of(strategy));
when(credentialsService.hasCredentials("user-1", "facebook")).thenReturn(true);
when(taskRepository.findByStrategyId("strategy-1")).thenReturn(existingTasks);
List<PostingTask> result = postingTaskService.createTasksFromStrategy("strategy-1");
@@ -174,7 +173,6 @@ class PostingTaskServiceTest {
MarketingStrategy strategy = completedStrategy("user-1", List.of(pastItem, futureItem));
when(strategyRepository.findById("strategy-1")).thenReturn(Optional.of(strategy));
when(credentialsService.hasCredentials("user-1", "facebook")).thenReturn(true);
when(credentialsService.hasCredentials("user-1", "telegram")).thenReturn(true);
when(taskRepository.findByStrategyId("strategy-1")).thenReturn(List.of());
when(taskRepository.saveAll(anyList())).thenAnswer(invocation -> {