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);
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);
// We compare the ID instead of the project themselves
return Objects.equals(

View File

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

View File

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