Skip to content

Commit

Permalink
Add test of getFilteredCars
Browse files Browse the repository at this point in the history
  • Loading branch information
ludmilka-k committed Dec 12, 2023
1 parent 2fca9e7 commit 191b9b5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/constants/getFilteredCars.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {getFilteredCars} from './getFilteredCars';

test("Passes a car successfully", () => {
const payload = [{mileage: 10, rentalPrice: "20$"}];
const filter = {minMileage: 5, maxMileage: 15, price: 40};
expect(getFilteredCars(payload, filter))
.toEqual(payload);
});

test("Handle undefined mileage as no limit", () => {
const payload = [{mileage: 10, rentalPrice: "20$"}];
const filter = {price: 40};
expect(getFilteredCars(payload, filter))
.toEqual(payload);
});

test("Handle null mileage as no limit", () => {
const payload = [{mileage: 10, rentalPrice: "20$"}];
const filter = {minMileage: null, maxMileage: null, price: 40};
expect(getFilteredCars(payload, filter))
.toEqual(payload);
});

test("Divert a car with non-conforming mileage", () => {
const payload = [{mileage: 10, rentalPrice: "20$"}];
const filter = {minMileage: 15, maxMileage: 40, price: 40};
expect(getFilteredCars(payload, filter))
.toEqual([]);
});

0 comments on commit 191b9b5

Please # to comment.