fix: name coherence + test logic
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 43s
CI / build (push) Successful in 13s

This commit is contained in:
Pierre Tellier 2025-04-06 20:30:29 +02:00
parent 9e1f568ea4
commit b672dd200c
3 changed files with 40 additions and 19 deletions

View File

@ -46,6 +46,14 @@ public class UtilsService {
} }
User user = this.userService.getUserByEmail(mail); User user = this.userService.getUserByEmail(mail);
Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser());
if (entrepreneur == null) {
logger.debug("testing access with an unknown Entrepreneur");
return false;
}
if (entrepreneur.getProjectParticipation() == null) {
logger.debug("testing access with an user with no project participation");
return false;
}
Project project = this.projectService.getProjectById(projectId); Project project = this.projectService.getProjectById(projectId);
// We compare the ID instead of the project themselves // We compare the ID instead of the project themselves
return Objects.equals( return Objects.equals(

View File

@ -106,9 +106,8 @@ public class SectionCellService {
return this.sectionCellRepository.save(sectionCell.get()); return this.sectionCellRepository.save(sectionCell.get());
} }
public Iterable<SectionCell> getSectionCellsByProject(Project project, Long idSectionCell) { public Iterable<SectionCell> getSectionCellsByProject(Project project, Long sectionId) {
return this.sectionCellRepository.findByProjectSectionCellAndSectionId( return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId);
project, idSectionCell);
} }
public Long getProjectId(Long sectionCellId) { public Long getProjectId(Long sectionCellId) {

View File

@ -29,7 +29,8 @@ import java.util.List;
public class EntrepreneurApiServiceTest { public class EntrepreneurApiServiceTest {
private static Entrepreneur entrepreneur; private static Entrepreneur entrepreneur;
private static Project project; private static Project project;
private static Iterable<SectionCell> sectionCells; private static Iterable<SectionCell> sectionCells2;
private static Iterable<SectionCell> sectionCells3;
@Autowired private EntrepreneurApiService entrepreneurApiService; @Autowired private EntrepreneurApiService entrepreneurApiService;
@Autowired private EntrepreneurService entrepreneurService; @Autowired private EntrepreneurService entrepreneurService;
@Autowired private ProjectService projectService; @Autowired private ProjectService projectService;
@ -73,10 +74,25 @@ public class EntrepreneurApiServiceTest {
System.out.println(entrepreneur); System.out.println(entrepreneur);
// System.out.println(entrepreneur.getProjectProposed()); // System.out.println(entrepreneur.getProjectProposed());
// System.out.println(entrepreneur.getProjectParticipation()); // System.out.println(entrepreneur.getProjectParticipation());
sectionCellService.addNewSectionCell( SectionCell s1 =
new SectionCell( sectionCellService.addNewSectionCell(
null, 2L, "contenu très intéressant", LocalDateTime.now(), project)); new SectionCell(
sectionCells = sectionCellService.getSectionCellsByProject(project, 2L); null,
2L,
"contenu très intéressant",
LocalDateTime.now(),
project));
SectionCell s2 =
sectionCellService.addNewSectionCell(
new SectionCell(
null,
3L,
"contenu très intéressant",
LocalDateTime.now(),
project));
sectionCells2 = sectionCellService.getSectionCellsByProject(project, 2L);
sectionCells3 = sectionCellService.getSectionCellsByProject(project, 3L);
} }
private <T> List<T> IterableToList(Iterable<T> iterable) { private <T> List<T> IterableToList(Iterable<T> iterable) {
@ -87,17 +103,14 @@ public class EntrepreneurApiServiceTest {
@Test @Test
void editValidSectionCell() { void editValidSectionCell() {
System.out.println("START\n\n\n");
entrepreneurApiService.editSectionCell( entrepreneurApiService.editSectionCell(
IterableToList(sectionCells).getFirst().getIdSectionCell(), IterableToList(sectionCells2).getFirst().getIdSectionCell(),
"modified content", "modified content",
"entrepreneur@mail.fr"); "entrepreneur@mail.fr");
// We get the data from the database again. // We get the data from the database again.
sectionCells = sectionCellService.getSectionCellsByProject(project, 2L); SectionCell s =
assertEquals( IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getFirst();
"modified content", assertEquals("modified content", s.getContentSectionCell());
IterableToList(sectionCells).getFirst().getContentSectionCell());
System.out.println("END\n\n\n");
} }
@Test @Test
@ -115,12 +128,13 @@ public class EntrepreneurApiServiceTest {
ResponseStatusException.class, ResponseStatusException.class,
() -> () ->
entrepreneurApiService.editSectionCell( entrepreneurApiService.editSectionCell(
IterableToList(sectionCells).getFirst().getIdSectionCell(), IterableToList(sectionCells3).getFirst().getIdSectionCell(),
"should not be modified", "should not be modified",
"testentrepreneur@mail.fr")); "testentrepreneur@mail.fr"));
assertEquals( SectionCell s =
"contenu très intéressant", IterableToList(sectionCellService.getSectionCellsByProject(project, 3L)).getFirst();
IterableToList(sectionCells).getFirst().getContentSectionCell());
assertEquals("contenu très intéressant", s.getContentSectionCell());
} }
@Test @Test