Skip to content

Commit

Permalink
Refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
masoudarvishian committed May 10, 2024
1 parent 88715d9 commit 7887d9d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface JobService {
Job createJob(UUID companyId, LocalDate startDate, LocalDate endDate);
void cancelJob(UUID companyId, UUID jobId) throws NotFoundException;
Optional<Job> getJob(UUID id);
void clearAllJobs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface ShiftService {
void cancelShift(UUID companyId, UUID shiftId) throws NotFoundException;
Optional<Shift> getShift(UUID id);
void cancelShiftForTalent(UUID companyId, UUID talentId);
void clearAllShifts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public Optional<Job> getJob(UUID id) {
return jobRepository.findById(id);
}

@Override
public void clearAllJobs() {
jobRepository.deleteAll();
}

private static Job buildJob(UUID companyId, LocalDate startDate, LocalDate endDate) {
return Job.builder()
.id(UUID.randomUUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public void cancelShiftForTalent(UUID companyId, UUID talentId) {
});
}

@Override
public void clearAllShifts() {
shiftRepository.deleteAll();
}

private List<Shift> getShiftsByTalentIdAndCompanyId(UUID talentId, UUID companyId) {
List<Shift> shifts = shiftRepository.findAllByTalentId(talentId);
return shifts.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.zenjob.challenge.domain.entity.Shift;
import com.zenjob.challenge.application.interfaces.JobService;
import javassist.NotFoundException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.Duration;
Expand All @@ -28,6 +30,12 @@ public class JobServiceTests {
@Autowired
private ShiftService shiftService;

@AfterEach
public void cleanUpDatabase() {
shiftService.clearAllShifts();
jobService.clearAllJobs();
}

@Test
public void job_should_have_at_least_one_shift() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.zenjob.challenge.domain.entity.Shift;
import com.zenjob.challenge.domain.exceptions.InvalidActionException;
import javassist.NotFoundException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
Expand All @@ -24,6 +26,12 @@ public class ShiftServiceTests {
@Autowired
private ShiftService shiftService;

@AfterEach
public void cleanUpDatabase() {
shiftService.clearAllShifts();
jobService.clearAllJobs();
}

@Test
public void cancel_a_single_shift_by_company() throws NotFoundException {
// given
Expand Down

0 comments on commit 7887d9d

Please sign in to comment.