feat(services-counter): store each company's interest list
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
4c853c428e
commit
b75d636886
8 files changed
+598
-1
No files matched your search
+82
@@ -0,0 +1,82 @@
|
||||
package com.solvway.services.counter.controller;
|
||||
|
||||
import com.solvway.services.counter.dto.InterestFindByIdsRequest;
|
||||
import com.solvway.services.counter.model.Interest;
|
||||
import com.solvway.services.counter.service.InterestService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* InterestController delegates to service and returns results.
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InterestControllerTest {
|
||||
|
||||
private static final long COMPANY_A = 1L;
|
||||
|
||||
@Mock
|
||||
private InterestService interestService;
|
||||
|
||||
private InterestController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
controller = new InterestController(interestService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findByCompanyDelegatesToService() {
|
||||
Interest row = makeInterest(1L, COMPANY_A, "tech", true, 0);
|
||||
when(interestService.findByCompany(COMPANY_A)).thenReturn(List.of(row));
|
||||
|
||||
List<Interest> result = controller.findByCompany(COMPANY_A);
|
||||
|
||||
assertThat(result).hasSize(1).first().isSameAs(row);
|
||||
verify(interestService).findByCompany(COMPANY_A);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveDelegatesToService() {
|
||||
Interest input = makeInterest(null, COMPANY_A, "tech", true, 0);
|
||||
Interest saved = makeInterest(99L, COMPANY_A, "tech", true, 0);
|
||||
when(interestService.save(input)).thenReturn(saved);
|
||||
|
||||
Interest result = controller.save(input);
|
||||
|
||||
assertThat(result.getId()).isEqualTo(99L);
|
||||
verify(interestService).save(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findByIdsDelegatesToService() {
|
||||
Interest row = makeInterest(5L, COMPANY_A, "filter", true, 0);
|
||||
InterestFindByIdsRequest body = new InterestFindByIdsRequest(COMPANY_A, List.of(5L));
|
||||
when(interestService.findByIds(COMPANY_A, List.of(5L))).thenReturn(List.of(row));
|
||||
|
||||
List<Interest> result = controller.findByIds(body);
|
||||
|
||||
assertThat(result).hasSize(1).first().isSameAs(row);
|
||||
verify(interestService).findByIds(COMPANY_A, List.of(5L));
|
||||
}
|
||||
|
||||
private static Interest makeInterest(Long id, long companyId, String name, boolean active, int sortOrder) {
|
||||
Interest i = new Interest();
|
||||
if (id != null) {
|
||||
i.setId(id);
|
||||
}
|
||||
i.setCompanyId(companyId);
|
||||
i.setName(name);
|
||||
i.setActive(active);
|
||||
i.setSortOrder(sortOrder);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user