feat: finsihed tests for EntrepreneurApiService
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 40s
CI / build (push) Successful in 13s

This commit is contained in:
Théo Le Lez
2025-04-23 11:54:18 +02:00
parent e7739af80b
commit bee47473d5
3 changed files with 175 additions and 33 deletions

View File

@ -4,13 +4,9 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.*;
import static org.junit.jupiter.api.Assertions.*;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.EntrepreneurApiService;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.SectionCellService;
import enseirb.myinpulse.service.database.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -21,6 +17,7 @@ import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
@ -35,6 +32,8 @@ public class EntrepreneurApiServiceTest {
@Autowired private EntrepreneurService entrepreneurService;
@Autowired private ProjectService projectService;
@Autowired private SectionCellService sectionCellService;
@Autowired private AnnotationService annotationService;
@Autowired private AppointmentService appointmentService;
@BeforeAll
static void setup(
@ -97,10 +96,23 @@ public class EntrepreneurApiServiceTest {
@Test
void editValidSectionCell() {
System.out.println("editValidSectionCell : ");
SectionCell modified = IterableToList(sectionCells2).getLast();
this.sectionCellService.updateSectionCellListAnnotation(
modified.getIdSectionCell(),
annotationService.addNewAnnotation(new Annotation(null, "oui j'annote encore")));
this.sectionCellService.updateSectionCellListAppointment(
modified.getIdSectionCell(),
appointmentService.addNewAppointment(
new Appointment(
null,
LocalDate.now(),
LocalTime.now(),
LocalTime.of(2, 5),
"TD14",
"clément s'est plaint")));
entrepreneurApiService.editSectionCell(
IterableToList(sectionCells2).getLast().getIdSectionCell(),
"modified content",
"entrepreneur@mail.fr");
modified.getIdSectionCell(), "modified content", "entrepreneur@mail.fr");
// We get the data from the database again.
SectionCell s =
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
@ -111,6 +123,7 @@ public class EntrepreneurApiServiceTest {
@Test
void editInvalidSectionCell() {
System.out.println("editInvalidSectionCell : ");
assertThrows(
ResponseStatusException.class,
() ->
@ -125,6 +138,7 @@ public class EntrepreneurApiServiceTest {
@Test
void editSectionCellInvalidAccess() {
System.out.println("editSectionCellInvalidAccess : ");
assertThrows(
ResponseStatusException.class,
() ->
@ -138,8 +152,19 @@ public class EntrepreneurApiServiceTest {
assertEquals("contenu très intéressant", s.getContentSectionCell());
}
@Test
void editNullSectionCell() {
System.out.println("editNullSectionCell : ");
assertThrows(
ResponseStatusException.class,
() ->
entrepreneurApiService.editSectionCell(
null, "modified content", "entrepreneur@mail.fr"));
}
@Test
void removeValidSectionCell() {
System.out.println("removeValidSectionCell : ");
SectionCell tmpCell =
sectionCellService.addNewSectionCell(
new SectionCell(
@ -159,6 +184,7 @@ public class EntrepreneurApiServiceTest {
@Test
void removeInvalidSectionCell() {
System.out.println("removeInvalidSectionCell : ");
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.removeSectionCell(-1L, "entrepreneur@mail.fr"));
@ -168,11 +194,31 @@ public class EntrepreneurApiServiceTest {
assertEquals("contenu très intéressant", s.getContentSectionCell());
}
@Test
void removeNullSectionCell() {
System.out.println("removeNullSectionCell : ");
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.removeSectionCell(null, "entrepreneur@mail.fr"));
}
@Test
void addValidSectionCell() {
System.out.println("addValidSectionCell : ");
SectionCell added =
sectionCellService.addNewSectionCell(
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project));
added.updateListAnnotation(
annotationService.addNewAnnotation(new Annotation(null, "oui j'annote")));
added.updateAppointmentSectionCell(
appointmentService.addNewAppointment(
new Appointment(
null,
LocalDate.now(),
LocalTime.now(),
LocalTime.of(2, 5),
"TD15",
"clément qui se plaint")));
entrepreneurApiService.addSectionCell(added, "entrepreneur@mail.fr");
SectionCell s =
IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).getLast();
@ -183,6 +229,7 @@ public class EntrepreneurApiServiceTest {
@Test
void addSectionCellInvalidAccess() {
System.out.println("addSectionCellInvalidAccess : ");
SectionCell added =
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project);
assertThrows(
@ -197,6 +244,7 @@ public class EntrepreneurApiServiceTest {
@Test
void addInvalidSectionCell() {
System.out.println("addInvalidSectionCell : ");
SectionCell added =
sectionCellService.addNewSectionCell(
new SectionCell(null, -1L, "contenu ajouté", LocalDateTime.now(), project));
@ -206,5 +254,71 @@ public class EntrepreneurApiServiceTest {
}
@Test
void requestValidProject() {}
void addNullSectionCell() {
System.out.println("addNullSectionCell : ");
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.addSectionCell(null, "entrepreneur@mail.fr"));
}
@Test
void requestValidProject() {
System.out.println("requestValidProject : ");
int nb_project = IterableToList(this.projectService.getAllProjects()).size();
Project validProject =
new Project("validProject", null, LocalDate.now(), ACTIVE, null, entrepreneur);
validProject.updateListEntrepreneurParticipation(
IterableToList(entrepreneurService.getAllEntrepreneurs()).getLast());
validProject.updateListSectionCell((IterableToList(sectionCells2).getFirst()));
entrepreneurApiService.requestNewProject(validProject, "entrepreneur@mail.fr");
assertEquals(PENDING, validProject.getProjectStatus());
assertEquals((nb_project + 1), IterableToList(this.projectService.getAllProjects()).size());
assertEquals(
IterableToList(entrepreneurService.getAllEntrepreneurs()).getLast(),
validProject.getListEntrepreneurParticipation().getLast());
assertEquals(
IterableToList(sectionCells2).getFirst().getIdSectionCell(),
validProject.getListSectionCell().getFirst().getIdSectionCell());
}
@Test
void requestNullProject() {
System.out.println("requestNullProject : ");
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.requestNewProject(null, "entrepreneur@mail.fr"));
}
@Test
void createNewValidAccount() {
System.out.println("createNewValidAccount : ");
int nb_entrepreneur = IterableToList(this.entrepreneurService.getAllEntrepreneurs()).size();
Entrepreneur newEntrepreneur =
new Entrepreneur(
"New",
"Test",
"mailtest@test.fr",
"mailtest2@test.fr",
"0888888888",
"ENSEIRB",
"ELEC",
false,
true);
assertDoesNotThrow(() -> entrepreneurApiService.createAccount(newEntrepreneur));
assertEquals(
(nb_entrepreneur + 1),
IterableToList(this.entrepreneurService.getAllEntrepreneurs()).size());
}
@Test
void createExistingAccount() {
System.out.println("createExistingAccount : ");
int nb_entrepreneur = IterableToList(this.entrepreneurService.getAllEntrepreneurs()).size();
assertThrows(
ResponseStatusException.class,
() -> entrepreneurApiService.createAccount(entrepreneur));
assertEquals(
nb_entrepreneur,
IterableToList(this.entrepreneurService.getAllEntrepreneurs()).size());
}
}