diff --git a/Backend/src/main/java/ca/mcgill/cooperator/dao/CourseOfferingRepository.java b/Backend/src/main/java/ca/mcgill/cooperator/dao/CourseOfferingRepository.java index f788ee634..81a527e04 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/dao/CourseOfferingRepository.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/dao/CourseOfferingRepository.java @@ -2,13 +2,10 @@ import ca.mcgill.cooperator.model.Course; import ca.mcgill.cooperator.model.CourseOffering; - import java.util.List; - import org.springframework.data.repository.CrudRepository; public interface CourseOfferingRepository extends CrudRepository { - - List findByCourse(Course c); - + + List findByCourse(Course c); } diff --git a/Backend/src/main/java/ca/mcgill/cooperator/model/Course.java b/Backend/src/main/java/ca/mcgill/cooperator/model/Course.java index 51ae53404..3816b2245 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/model/Course.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/model/Course.java @@ -42,11 +42,10 @@ public List getCourseOfferings() { } public void setCourseOfferings(List courseOfferings) { - if(this.courseOfferings == null) - this.courseOfferings = courseOfferings; - else { - this.courseOfferings.clear(); - this.courseOfferings.addAll(courseOfferings); - } + if (this.courseOfferings == null) this.courseOfferings = courseOfferings; + else { + this.courseOfferings.clear(); + this.courseOfferings.addAll(courseOfferings); + } } } diff --git a/Backend/src/main/java/ca/mcgill/cooperator/service/CourseOfferingService.java b/Backend/src/main/java/ca/mcgill/cooperator/service/CourseOfferingService.java index 39cf9c37e..add3eb1e5 100644 --- a/Backend/src/main/java/ca/mcgill/cooperator/service/CourseOfferingService.java +++ b/Backend/src/main/java/ca/mcgill/cooperator/service/CourseOfferingService.java @@ -57,9 +57,10 @@ public CourseOffering createCourseOffering(int year, Season season, Course c) { return courseOfferingRepository.save(co); } - + @Transactional - public CourseOffering updateCourseOffering(CourseOffering co, int year, Season season, Course c) { + public CourseOffering updateCourseOffering( + CourseOffering co, int year, Season season, Course c) { StringBuilder error = new StringBuilder(); if (year <= 0) { error.append("Year is invalid! "); @@ -70,13 +71,13 @@ public CourseOffering updateCourseOffering(CourseOffering co, int year, Season s if (c == null) { error.append("Course cannot be null! "); } - if (co == null){ - error.append("Course Offering cannot be null!"); + if (co == null) { + error.append("Course Offering cannot be null!"); } if (error.length() > 0) { throw new IllegalArgumentException(error.toString().trim()); } - + co.setYear(year); co.setSeason(season); co.setCourse(c); @@ -92,42 +93,44 @@ public CourseOffering updateCourseOffering(CourseOffering co, int year, Season s return courseOfferingRepository.save(co); } - + @Transactional public CourseOffering getCourseOfferingById(int id) { - CourseOffering c = courseOfferingRepository.findById(id).orElse(null); - if (c == null) { - throw new IllegalArgumentException("Course Offering with ID " + id + " does not exist!"); + CourseOffering c = courseOfferingRepository.findById(id).orElse(null); + if (c == null) { + throw new IllegalArgumentException( + "Course Offering with ID " + id + " does not exist!"); } - return c; + return c; } - + @Transactional public List getCourseOfferingsByCourse(Course c) { - List co = courseOfferingRepository.findByCourse(c); - if (co == null) { - throw new IllegalArgumentException("There are no course offerings for the course " + c.getName() + "!"); + List co = courseOfferingRepository.findByCourse(c); + if (co == null) { + throw new IllegalArgumentException( + "There are no course offerings for the course " + c.getName() + "!"); } - return co; + return co; } - + @Transactional - public List getAllCourseOfferings(){ - List co = ServiceUtils.toList(courseOfferingRepository.findAll()); - if (co == null) { + public List getAllCourseOfferings() { + List co = ServiceUtils.toList(courseOfferingRepository.findAll()); + if (co == null) { throw new IllegalArgumentException("There are no course offerings!"); } - return co; + return co; } - + @Transactional public CourseOffering deleteCourseOffering(CourseOffering co) { - courseOfferingRepository.delete(co); - Course c = co.getCourse(); - List cos = c.getCourseOfferings(); - cos.remove(co); - c.setCourseOfferings(cos); - courseRepository.save(c); - return co; + courseOfferingRepository.delete(co); + Course c = co.getCourse(); + List cos = c.getCourseOfferings(); + cos.remove(co); + c.setCourseOfferings(cos); + courseRepository.save(c); + return co; } } diff --git a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/AdminApproveCoopIT.java b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/AdminApproveCoopIT.java index 697d17f96..12aafedf4 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/AdminApproveCoopIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/AdminApproveCoopIT.java @@ -2,22 +2,25 @@ import static org.junit.Assert.assertTrue; -import org.springframework.test.context.ActiveProfiles; - import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import org.springframework.test.context.ActiveProfiles; @ActiveProfiles("test") public class AdminApproveCoopIT { - - @When("the Student submits their offer letter") - public void studentSubmitsOfferLetter() { - assertTrue(true); - } - - @Then("the Admin approves the Coop term") - public void adminApprovesCoopTerm() { - assertTrue(true); - } - + + @When("the Student submits their offer letter") + public void studentSubmitsOfferLetter() { + assertTrue(true); + } + + @Then("the Admin approves the Coop term") + public void adminApprovesCoopTerm() { + assertTrue(true); + } + + @Then("the Admin rejects the Coop term") + public void adminRejectsCoopTerm() { + assertTrue(true); + } } diff --git a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/CucumberIT.java b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/CucumberIT.java index dd394e318..f8d38b4e6 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/CucumberIT.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/CucumberIT.java @@ -1,15 +1,12 @@ package ca.mcgill.cooperator.cucumber; -import org.junit.runner.RunWith; - import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; -/** - * Configuration for Cucumber tests - */ +/** Configuration for Cucumber tests */ @RunWith(Cucumber.class) -@CucumberOptions(features = "classpath:features", plugin = {"pretty", "json:target/cucumber-report.json"}) -public class CucumberIT { - -} +@CucumberOptions( + features = "classpath:features", + plugin = {"pretty", "json:target/cucumber-report.json"}) +public class CucumberIT {} diff --git a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentGetCoopInfoIT.java b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentGetCoopInfoIT.java new file mode 100644 index 000000000..ade9e9ee9 --- /dev/null +++ b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentGetCoopInfoIT.java @@ -0,0 +1,27 @@ +package ca.mcgill.cooperator.cucumber; + +import static org.junit.Assert.assertTrue; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +public class StudentGetCoopInfoIT { + + @Given("the Student has at least one current or previous Coop term") + public void studentHasAtLeastOneCoopTerm() { + assertTrue(true); + } + + @When("the Student requests to get their Coop term information") + public void studentRequestsCoopInformation() { + assertTrue(true); + } + + @Then("the system returns the information for all of their Coop terms") + public void getCoopInformationForStudent() { + assertTrue(true); + } +} diff --git a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentSubmitOfferLetterIT.java b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentSubmitOfferLetterIT.java new file mode 100644 index 000000000..ea306adeb --- /dev/null +++ b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentSubmitOfferLetterIT.java @@ -0,0 +1,27 @@ +package ca.mcgill.cooperator.cucumber; + +import static org.junit.Assert.assertTrue; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +public class StudentSubmitOfferLetterIT { + + @When("the Student uploads a copy of their offer letter") + public void studentSubmitsOfferLetter() { + assertTrue(true); + } + + @And("submits the details of their Coop term") + public void studentSubmitsCoopDetails() { + assertTrue(true); + } + + @Then("the offer letter is put up for review by an Admin") + public void offerLetterIsPutUpForReview() { + assertTrue(true); + } +} diff --git a/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentUploadReportIT.java b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentUploadReportIT.java new file mode 100644 index 000000000..1b527943c --- /dev/null +++ b/Backend/src/test/java/ca/mcgill/cooperator/cucumber/StudentUploadReportIT.java @@ -0,0 +1,48 @@ +package ca.mcgill.cooperator.cucumber; + +import static org.junit.Assert.assertTrue; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +public class StudentUploadReportIT { + + @Given("the Student is currently doing a Coop term") + public void studentHasCurrentCoopTerm() { + assertTrue(true); + } + + @And("the Student has a Report due") + public void studentHasReportDue() { + assertTrue(true); + } + + @When("the Student uploads the proper Report") + public void studentUploadsReport() { + assertTrue(true); + } + + @Then("the Report is saved in the system") + public void saveReport() { + assertTrue(true); + } + + @And("the Student has uploaded a Report type previously") + public void studentHasUploadedReportPreviously() { + assertTrue(true); + } + + @When("the Student uploads the same type of Report again") + public void studentUploadsReportAgain() { + assertTrue(true); + } + + @Then("the new Report overwrites the old one in the system") + public void overwriteReport() { + assertTrue(true); + } +} diff --git a/Backend/src/test/java/ca/mcgill/cooperator/service/CooperatorServiceCourseOfferingTests.java b/Backend/src/test/java/ca/mcgill/cooperator/service/CooperatorServiceCourseOfferingTests.java index c2eed9b57..d98b1dd79 100644 --- a/Backend/src/test/java/ca/mcgill/cooperator/service/CooperatorServiceCourseOfferingTests.java +++ b/Backend/src/test/java/ca/mcgill/cooperator/service/CooperatorServiceCourseOfferingTests.java @@ -3,6 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; +import ca.mcgill.cooperator.dao.CourseOfferingRepository; +import ca.mcgill.cooperator.dao.CourseRepository; +import ca.mcgill.cooperator.model.Course; +import ca.mcgill.cooperator.model.CourseOffering; +import ca.mcgill.cooperator.model.Season; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,17 +15,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import ca.mcgill.cooperator.dao.CourseOfferingRepository; -import ca.mcgill.cooperator.dao.CourseRepository; -import ca.mcgill.cooperator.model.Course; -import ca.mcgill.cooperator.model.CourseOffering; -import ca.mcgill.cooperator.model.Season; - @SpringBootTest @ActiveProfiles("test") public class CooperatorServiceCourseOfferingTests { - - @Autowired CourseService courseService; + + @Autowired CourseService courseService; @Autowired CourseOfferingService courseOfferingService; @Autowired CourseRepository courseRepository; @@ -29,19 +28,19 @@ public class CooperatorServiceCourseOfferingTests { @BeforeEach @AfterEach public void clearDatabase() { - courseOfferingRepository.deleteAll(); - courseRepository.deleteAll(); + courseOfferingRepository.deleteAll(); + courseRepository.deleteAll(); } @Test public void testCreateCourseOffering() { - String name = "ECSE321"; - int year = 2020; - Season season = Season.WINTER; + String name = "ECSE321"; + int year = 2020; + Season season = Season.WINTER; Course c = courseService.createCourse(name); - + try { - CourseOffering co = courseOfferingService.createCourseOffering(year, season, c); + CourseOffering co = courseOfferingService.createCourseOffering(year, season, c); } catch (IllegalArgumentException e) { fail(); @@ -56,51 +55,53 @@ public void testCreateCourseOffering() { @Test public void testCreateCourseOfferingNull() { - try { - CourseOffering co = courseOfferingService.createCourseOffering(0, null, null); + try { + CourseOffering co = courseOfferingService.createCourseOffering(0, null, null); } catch (IllegalArgumentException e) { - assertEquals("Year is invalid! Season cannot be null! Course cannot be null!", e.getMessage()); + assertEquals( + "Year is invalid! Season cannot be null! Course cannot be null!", + e.getMessage()); } - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 0); } @Test public void testUpdateCourseOffering() { - String name = "ECSE321"; - int year = 2020; - Season season = Season.WINTER; + String name = "ECSE321"; + int year = 2020; + Season season = Season.WINTER; Course c = courseService.createCourse(name); - + try { - courseOfferingService.createCourseOffering(year, season, c); + courseOfferingService.createCourseOffering(year, season, c); } catch (IllegalArgumentException e) { fail(); } - + CourseOffering co = courseOfferingService.getAllCourseOfferings().get(0); - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 1); assertEquals(co.getSeason(), season); assertEquals(co.getYear(), year); assertEquals(co.getCourse().getId(), c.getId()); - + String name2 = "ECSE223"; - int year2 = 2021; - Season season2 = Season.FALL; + int year2 = 2021; + Season season2 = Season.FALL; Course c2 = courseService.createCourse(name); - + try { - courseOfferingService.updateCourseOffering(co, year2, season2, c2); + courseOfferingService.updateCourseOffering(co, year2, season2, c2); } catch (IllegalArgumentException e) { fail(); } - + co = courseOfferingService.getAllCourseOfferings().get(0); - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 1); assertEquals(co.getSeason(), season2); assertEquals(co.getYear(), year2); @@ -109,39 +110,41 @@ public void testUpdateCourseOffering() { @Test public void testUpdateCourseOfferingInvalid() { - String name = "ECSE321"; - int year = 2020; - Season season = Season.WINTER; + String name = "ECSE321"; + int year = 2020; + Season season = Season.WINTER; Course c = courseService.createCourse(name); - + try { - courseOfferingService.createCourseOffering(year, season, c); + courseOfferingService.createCourseOffering(year, season, c); } catch (IllegalArgumentException e) { fail(); } - + CourseOffering co = courseOfferingService.getAllCourseOfferings().get(0); - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 1); assertEquals(co.getSeason(), season); assertEquals(co.getYear(), year); assertEquals(co.getCourse().getId(), c.getId()); - + String name2 = null; - int year2 = -1; - Season season2 = null; + int year2 = -1; + Season season2 = null; Course c2 = null; - + try { - courseOfferingService.updateCourseOffering(co, year2, season2, c2); + courseOfferingService.updateCourseOffering(co, year2, season2, c2); } catch (IllegalArgumentException e) { - assertEquals("Year is invalid! Season cannot be null! Course cannot be null!", e.getMessage()); + assertEquals( + "Year is invalid! Season cannot be null! Course cannot be null!", + e.getMessage()); } - + co = courseOfferingService.getAllCourseOfferings().get(0); - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 1); assertEquals(co.getSeason(), season); assertEquals(co.getYear(), year); @@ -150,28 +153,28 @@ public void testUpdateCourseOfferingInvalid() { @Test public void testDeleteCourseOffering() { - String name = "ECSE321"; - int year = 2020; - Season season = Season.WINTER; + String name = "ECSE321"; + int year = 2020; + Season season = Season.WINTER; Course c = courseService.createCourse(name); - + try { - courseOfferingService.createCourseOffering(year, season, c); + courseOfferingService.createCourseOffering(year, season, c); } catch (IllegalArgumentException e) { fail(); } - + CourseOffering co = courseOfferingService.getAllCourseOfferings().get(0); assertEquals(courseOfferingService.getAllCourseOfferings().size(), 1); - + try { - courseOfferingService.deleteCourseOffering(co); + courseOfferingService.deleteCourseOffering(co); } catch (IllegalArgumentException e) { fail(); } - + assertEquals(courseOfferingService.getAllCourseOfferings().size(), 0); } } diff --git a/Backend/src/test/resources/features/admin/admin_approve_coop.feature b/Backend/src/test/resources/features/admin/admin_approve_coop.feature new file mode 100644 index 000000000..e4ff9f60c --- /dev/null +++ b/Backend/src/test/resources/features/admin/admin_approve_coop.feature @@ -0,0 +1,12 @@ +Feature: the Admin can approve or deny a Student's Coop term + + This feature covers the Admin's ability to approve or deny a Student's + Coop term. + + Scenario: Admin approves Coop term + When the Student submits their offer letter + Then the Admin approves the Coop term + + Scenario: Admin denies Coop term + When the Student submits their offer letter + Then the Admin rejects the Coop term diff --git a/Backend/src/test/resources/features/admin_approve_coop.feature b/Backend/src/test/resources/features/admin_approve_coop.feature deleted file mode 100644 index dc9769bd3..000000000 --- a/Backend/src/test/resources/features/admin_approve_coop.feature +++ /dev/null @@ -1,4 +0,0 @@ -Feature: the Admin can approve or deny a Student's Coop term - Scenario: Admin approves Coop term - When the Student submits their offer letter - Then the Admin approves the Coop term \ No newline at end of file diff --git a/Backend/src/test/resources/features/student/student_get_coop_info.feature b/Backend/src/test/resources/features/student/student_get_coop_info.feature new file mode 100644 index 000000000..9e85416ef --- /dev/null +++ b/Backend/src/test/resources/features/student/student_get_coop_info.feature @@ -0,0 +1,9 @@ +Feature: the Student can get the information for their Coop terms + + This feature covers the functionality of the backend which returns + the Coop information for a particular Student. + + Scenario: Student gets information for their Coop term(s) + Given the Student has at least one current or previous Coop term + When the Student requests to get their Coop term information + Then the system returns the information for all of their Coop terms \ No newline at end of file diff --git a/Backend/src/test/resources/features/student/student_submit_offer_letter.feature b/Backend/src/test/resources/features/student/student_submit_offer_letter.feature new file mode 100644 index 000000000..223f14e86 --- /dev/null +++ b/Backend/src/test/resources/features/student/student_submit_offer_letter.feature @@ -0,0 +1,9 @@ +Feature: the Student can submit their offer letter for a new Coop term + + This feature covers a Student's ability to submit an offer letter, + which is how the Student applies for a new Coop term. + + Scenario: the Student submits their offer letter + When the Student uploads a copy of their offer letter + And submits the details of their Coop term + Then the offer letter is put up for review by an Admin diff --git a/Backend/src/test/resources/features/student/student_upload_report.feature b/Backend/src/test/resources/features/student/student_upload_report.feature new file mode 100644 index 000000000..495c88daa --- /dev/null +++ b/Backend/src/test/resources/features/student/student_upload_report.feature @@ -0,0 +1,16 @@ +Feature: the Student can upload a required Report for their Coop term + + This features covers the various scenarios that a Student can be + in when they upload a required Report. + + Scenario: Student uploads Report + Given the Student is currently doing a Coop term + And the Student has a Report due + When the Student uploads the proper Report + Then the Report is saved in the system + + Scenario: Student overwrites previous Report upload + Given the Student is currently doing a Coop term + And the Student has uploaded a Report type previously + When the Student uploads the same type of Report again + Then the new Report overwrites the old one in the system \ No newline at end of file