fix: name coherence + test logic
This commit is contained in:
parent
9e1f568ea4
commit
b672dd200c
@ -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(
|
||||||
|
@ -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) {
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user