fix : tests
Some checks failed
CI / build (push) Waiting to run
Format / formatting (push) Successful in 5s
Build / build (push) Has been cancelled

This commit is contained in:
Théo Le Lez 2025-04-16 11:26:25 +02:00
parent 6029457735
commit 7df2c768c8
3 changed files with 94 additions and 92 deletions

View File

@ -112,9 +112,17 @@ public class EntrepreneurApiService {
mail,
sectionCellId,
this.sectionCellService.getProjectId(sectionCellId));
SectionCell removedSectionCell = new SectionCell(null, -1L, "", LocalDateTime.now(), null);
removedSectionCell.setIdReference(editSectionCell.getIdReference());
SectionCell removedSectionCell =
new SectionCell(
null,
-1L,
"",
LocalDateTime.now(),
this.projectService.getProjectById(
editSectionCell.getProjectSectionCell().getIdProject()));
sectionCellService.addNewSectionCell(removedSectionCell);
this.sectionCellService.updateSectionCellReferenceId(
removedSectionCell.getIdSectionCell(), editSectionCell.getIdReference());
projectService.updateProjectListSectionCell(
sectionCellService.getProjectId(sectionCellId), removedSectionCell);
// sectionCellService.removeSectionCellById(sectionCellId);
@ -132,19 +140,19 @@ public class EntrepreneurApiService {
HttpStatus.BAD_REQUEST, "La cellule de section fournie n'est pas valide");
}
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
mail, sectionCell.getProjectSectionCell().getIdProject())) {
logger.warn(
"User {} tried to add a section cell to the project {} but is not allowed to.",
mail,
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
sectionCell.getProjectSectionCell().getIdProject());
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} added a new section cell {} to the project with id {}",
"User {} added a new section cell {} to the project {}",
mail,
sectionCell.getIdSectionCell(),
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
sectionCell.getProjectSectionCell().getIdProject());
SectionCell newSectionCell =
sectionCellService.addNewSectionCell(
sectionCell); // if here, logger fails cause id is null (not added yet)
@ -173,11 +181,18 @@ public class EntrepreneurApiService {
project.setEntrepreneurProposed((Entrepreneur) this.userService.getUserByEmail(mail));
projectService.addNewProject(project);
project.getProjectAdministrator().updateListProject(project);
project.getEntrepreneurProposed().setProjectProposed(project);
this.entrepreneurService.updateEntrepreneurProjectProposed(
this.userService.getUserByEmail(mail).getIdUser(), project);
project.getListEntrepreneurParticipation()
.forEach(entrepreneur -> entrepreneur.setProjectParticipation(project));
.forEach(
entrepreneur ->
this.entrepreneurService.updateEntrepreneurProjectParticipation(
entrepreneur.getIdUser(), project));
project.getListSectionCell()
.forEach(sectionCell -> sectionCell.setProjectSectionCell(project));
.forEach(
sectionCell ->
this.sectionCellService.updateSectionCellProject(
sectionCell.getIdSectionCell(), project));
}
public void createAccount(Entrepreneur e) {

View File

@ -146,8 +146,10 @@ public class EntrepreneurApiServiceTest {
null, 2L, "contenu temporaire", LocalDateTime.now(), project));
assertEquals(
2, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
assertDoesNotThrow(
() ->
entrepreneurApiService.removeSectionCell(
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr");
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr"));
assertEquals(
tmpCell.getIdReference(),
IterableToList(sectionCellService.getSectionCellsByProject(project, -1L))
@ -181,14 +183,8 @@ public class EntrepreneurApiServiceTest {
@Test
void addSectionCellInvalidAccess() {
System.out.println(
"content : "
+ IterableToList(sectionCellService.getSectionCellsByProject(project, 2L))
.getLast()
.getContentSectionCell());
SectionCell added =
sectionCellService.addNewSectionCell(
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project));
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project);
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.addSectionCell(added, "fauxentrepreneur@mail.fr"));
@ -208,4 +204,7 @@ public class EntrepreneurApiServiceTest {
ResponseStatusException.class,
() -> entrepreneurApiService.addSectionCell(added, "entrepreneur@mail.fr"));
}
@Test
void requestValidProject() {}
}

View File

@ -3,28 +3,22 @@ package enseirb.myinpulse;
import static enseirb.myinpulse.model.ProjectDecisionValue.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.endsWith;
import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Appointment;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.Appointment;
import enseirb.myinpulse.service.SharedApiService;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import org.aspectj.lang.annotation.After;
import org.checkerframework.checker.units.qual.kmPERh;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDate;
import java.time.LocalTime;
@ -45,18 +39,13 @@ public class SharedApiServiceTest {
private static Entrepreneur functional_entrepreneur;
private static Project functional_project;
static private Entrepreneur empty_entrepreneur;
static private Administrator empty_administrator;
static private Project empty_Project;
private static Entrepreneur empty_entrepreneur;
private static Administrator empty_administrator;
private static Project empty_Project;
private static Administrator getTestAdmin(String name) {
return new Administrator(
name,
name,
name+"@example.com",
"seconday@example.com",
"0123456789");
name, name, name + "@example.com", "seconday@example.com", "0123456789");
}
private static Entrepreneur getTestEntrpreneur(String name) {
@ -75,10 +64,7 @@ public class SharedApiServiceTest {
return new Project(name, null, LocalDate.now(), ACTIVE, admin);
}
static
@BeforeAll
private void setup(
static @BeforeAll private void setup(
@Autowired AdministratorService administratorService,
@Autowired ProjectService projectService,
@Autowired EntrepreneurService entrepreneurService) {
@ -87,16 +73,18 @@ public class SharedApiServiceTest {
empty_administrator = administratorService.addAdministrator(null);
empty_Project = projectService.addNewProject(new Project());
functional_administrator = administratorService.addAdministrator(getTestAdmin("functional_administrator"));
functional_entrepreneur = entrepreneurService.addEntrepreneur(getTestEntrpreneur("functional_entrepreneur"));
functional_project = projectService.addNewProject(getTestProject("functional_project", functional_administrator));
functional_administrator =
administratorService.addAdministrator(getTestAdmin("functional_administrator"));
functional_entrepreneur =
entrepreneurService.addEntrepreneur(getTestEntrpreneur("functional_entrepreneur"));
functional_project =
projectService.addNewProject(
getTestProject("functional_project", functional_administrator));
functional_project.updateListEntrepreneurParticipation(functional_entrepreneur);
}
@AfterAll
private void cleanup() {
}
private void cleanup() {}
private <T> List<T> IterableToList(Iterable<T> iterable) {
List<T> l = new ArrayList<>();
@ -121,11 +109,9 @@ public class SharedApiServiceTest {
throw new IllegalArgumentException("Unsupported type for comparison");
}
private <T, K> void TestIfInIterable(Iterable<T> iterable, K expected) {
List<T> l = IterableToList(iterable);
Boolean exists = l.stream()
.anyMatch(e -> matchesIgnoringId(expected, e));
Boolean exists = l.stream().anyMatch(e -> matchesIgnoringId(expected, e));
assertTrue(exists, "");
}
@ -143,22 +129,25 @@ public class SharedApiServiceTest {
LocalTime time = LocalTime.parse("10:20:00");
String appointmentPlace = "salleInpulse";
String appointmentSubject = "Titanic";
Appointment appointment = new Appointment( new Long(0), date, time, duration, appointmentPlace, appointmentSubject);
sharedApiService.createAppointmentRequest(appointment, "functional_entrepreneur@example.com");
Appointment appointment =
new Appointment(
new Long(0), date, time, duration, appointmentPlace, appointmentSubject);
sharedApiService.createAppointmentRequest(
appointment, "functional_entrepreneur@example.com");
/*
* fetching the values and testing them
*/
Iterable<Appointment> appointments = sharedApiService.getAppointmentsByProjectId(functional_project.getIdProject(), "functional_entrepreneur@example.com");
Iterable<Appointment> appointments =
sharedApiService.getAppointmentsByProjectId(
functional_project.getIdProject(), "functional_entrepreneur@example.com");
List<Appointment> appointment_list = IterableToList(appointments);
assertEquals(date, date);
assertEquals(time, time);
assertEquals(appointmentPlace, appointmentPlace);
assertEquals(appointmentSubject, appointmentSubject);
}
/*
* Tests the edge cases:
* - an appointement made by a user but has no participants.
@ -170,7 +159,6 @@ public class SharedApiServiceTest {
assertEquals(0, 0);
}
/*
* Tests if an admin and entrepreneur with no prior appointments
* have no appointments.