Skip to content

Commit

Permalink
test: add tests to handler
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Jan 16, 2023
1 parent a6359a3 commit 2b85da9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/unit/rentals-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,64 @@ describe("when getting rental listings", () => {
})
})

describe("and the process is done with the minPricePerDay parameter set", () => {
const minPricePerDay = "1"
beforeEach(() => {
url = new URL(`http://localhost/v1/rental-listing?minPricePerDay=${minPricePerDay}`)
})

it("should have retrieved the rental listings with the given target", async () => {
await getRentalsListingsHandler({ components, url })
expect(getRentalsListingsMock).toHaveBeenCalledWith(
expect.objectContaining({ filterBy: expect.objectContaining({ minPricePerDay }) }),
false
)
})
})

describe("and the process is done with the minPricePerDay parameter unset", () => {
beforeEach(() => {
url = new URL(`http://localhost/v1/rental-listing`)
})

it("should have retrieved the rental listings with the given target", async () => {
await getRentalsListingsHandler({ components, url })
expect(getRentalsListingsMock).toHaveBeenCalledWith(
expect.objectContaining({ filterBy: expect.not.objectContaining({ minPricePerDay: expect.anything() }) }),
false
)
})
})

describe("and the process is done with the maxPricePerDay parameter set", () => {
const maxPricePerDay = "100"
beforeEach(() => {
url = new URL(`http://localhost/v1/rental-listing?maxPricePerDay=${maxPricePerDay}`)
})

it("should have retrieved the rental listings with the given target", async () => {
await getRentalsListingsHandler({ components, url })
expect(getRentalsListingsMock).toHaveBeenCalledWith(
expect.objectContaining({ filterBy: expect.objectContaining({ maxPricePerDay }) }),
false
)
})
})

describe("and the process is done with the maxPricePerDay parameter unset", () => {
beforeEach(() => {
url = new URL(`http://localhost/v1/rental-listing`)
})

it("should have retrieved the rental listings with the given target", async () => {
await getRentalsListingsHandler({ components, url })
expect(getRentalsListingsMock).toHaveBeenCalledWith(
expect.objectContaining({ filterBy: expect.not.objectContaining({ maxPricePerDay: expect.anything() }) }),
false
)
})
})

describe("and the process is done with the target parameter set", () => {
const target = "0x1"
beforeEach(() => {
Expand Down

0 comments on commit 2b85da9

Please sign in to comment.