Skip to content

Commit

Permalink
fix: test date not being reused (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed Mar 15, 2023
1 parent e2f0643 commit 45859d5
Showing 1 changed file with 71 additions and 49 deletions.
120 changes: 71 additions & 49 deletions test/unit/rentals-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,7 @@ describe("when getting rental listings", () => {
})
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock.mock.calls[0][0].text).toEqual(
expect.stringContaining("AND rentals.status = ANY($1)")
)
expect(dbQueryMock.mock.calls[0][0].text).toEqual(expect.stringContaining("AND rentals.status = ANY($1)"))
expect(dbQueryMock.mock.calls[0][0].values).toEqual([[RentalStatus.EXECUTED, RentalStatus.CLAIMED], 10, 0])
})
})
Expand Down Expand Up @@ -1114,7 +1112,7 @@ describe("when getting rental listings", () => {
},
})
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
expect.objectContaining({
strings: expect.arrayContaining([expect.stringContaining("AND metadata.estate_size >= ")]),
Expand All @@ -1137,7 +1135,7 @@ describe("when getting rental listings", () => {
},
})
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
expect.objectContaining({
strings: expect.arrayContaining([expect.not.stringContaining("AND metadata.estate_size >= ")]),
Expand Down Expand Up @@ -1173,7 +1171,7 @@ describe("when getting rental listings", () => {
values: [10, 10, 0],
})
)
})
})
})

describe("and the adjacentToRoad filter is set", () => {
Expand Down Expand Up @@ -1222,7 +1220,7 @@ describe("when getting rental listings", () => {
values: [false, 10, 0],
})
)
})
})
})

describe("and getHistoricData flag is on", () => {
Expand All @@ -1233,13 +1231,16 @@ describe("when getting rental listings", () => {

it("should only retrieve one rental for each nft (metadata_id)", async () => {
await expect(
rentalsComponent.getRentalsListings({
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: {},
}, true)
rentalsComponent.getRentalsListings(
{
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: {},
},
true
)
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
Expand All @@ -1259,13 +1260,16 @@ describe("when getting rental listings", () => {

it("should only retrieve one rental for each nft (metadata_id)", async () => {
await expect(
rentalsComponent.getRentalsListings({
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: {},
}, false)
rentalsComponent.getRentalsListings(
{
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: {},
},
false
)
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
Expand All @@ -1286,48 +1290,54 @@ describe("when getting rental listings", () => {
describe("when there is only one day", () => {
it("should join rental days select", async () => {
await expect(
rentalsComponent.getRentalsListings({
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: { rentalDays: [1] },
}, false)
rentalsComponent.getRentalsListings(
{
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: { rentalDays: [1] },
},
false
)
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
expect.objectContaining({
strings: expect.arrayContaining([
expect.stringContaining("SELECT DISTINCT rental_id FROM periods WHERE (min_days <= "),
expect.stringContaining("AND max_days >= "),
expect.stringContaining("AND rental_days_periods.rental_id = rentals.id")
expect.stringContaining("AND rental_days_periods.rental_id = rentals.id"),
]),
values: [1, 1, 10, 0],
})
)
})
})

describe("when there is more than one day", () => {
it("should join rental days select", async () => {
await expect(
rentalsComponent.getRentalsListings({
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: { rentalDays: [1, 7] },
}, false)
rentalsComponent.getRentalsListings(
{
offset: 0,
limit: 10,
sortBy: null,
sortDirection: null,
filterBy: { rentalDays: [1, 7] },
},
false
)
).resolves.toEqual(dbGetRentalListings)

expect(dbQueryMock).toHaveBeenCalledWith(
expect.objectContaining({
strings: expect.arrayContaining([
expect.stringContaining("SELECT DISTINCT rental_id FROM periods WHERE (min_days <= "),
expect.stringContaining("AND max_days >= "),
expect.stringContaining("OR (min_days <= "),
expect.stringContaining("AND max_days >= "),
expect.stringContaining("AND rental_days_periods.rental_id = rentals.id")
expect.stringContaining("AND rental_days_periods.rental_id = rentals.id"),
]),
values: [1, 1, 7, 7, 10, 0],
})
Expand Down Expand Up @@ -1492,7 +1502,7 @@ describe("when refreshing rental listings", () => {
rowCount: 1,
})
})

it("should update the metadata in the database and return the rental", async () => {
await expect(rentalsComponent.refreshRentalListing("an id", true)).resolves.toEqual(result)
expect(dbQueryMock.mock.calls[1][0].text).toEqual(expect.stringContaining("UPDATE metadata SET"))
Expand Down Expand Up @@ -2003,9 +2013,13 @@ describe("when updating the metadata", () => {
config = createConfigComponent({ CHAIN_NAME: "Goerli", MAX_CONCURRENT_RENTAL_UPDATES: "5" })
lessor = "0x705C1a693cB6a63578451D52E182a02Bc8cB2dEB"
rentalsComponent = await createRentalsComponent({ database, marketplaceSubgraph, rentalsSubgraph, logs, config })
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: new Date() }] })
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: startDate }] })
dbClientQueryMock.mockResolvedValueOnce(undefined)
jest.spyOn(Date, "now").mockReturnValueOnce(startDate.getTime())
jest.useFakeTimers().setSystemTime(startDate)
})

afterEach(() => {
jest.useRealTimers()
})

describe("and there are no updated NFTs", () => {
Expand Down Expand Up @@ -2041,7 +2055,7 @@ describe("when updating the metadata", () => {
updatedAt: "200000",
searchIsLand: true,
searchAdjacentToRoad: true,
searchDistanceToPlaza: 3
searchDistanceToPlaza: 3,
}
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: new Date() }] })
marketplaceSubgraphQueryMock.mockResolvedValueOnce({
Expand Down Expand Up @@ -2348,9 +2362,13 @@ describe("when updating the rental listings", () => {
config = createConfigComponent({ CHAIN_NAME: "Goerli", MAX_CONCURRENT_RENTAL_UPDATES: "5" })
lessor = "0x705C1a693cB6a63578451D52E182a02Bc8cB2dEB"
rentalsComponent = await createRentalsComponent({ database, marketplaceSubgraph, rentalsSubgraph, logs, config })
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: new Date() }] })
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: startDate }] })
dbClientQueryMock.mockResolvedValueOnce(undefined)
jest.spyOn(Date, "now").mockReturnValueOnce(startDate.getTime())
jest.useFakeTimers().setSystemTime(startDate)
})

afterEach(() => {
jest.useRealTimers()
})

describe("and there are no updated rentals", () => {
Expand Down Expand Up @@ -2551,7 +2569,7 @@ describe("when updating the rental listings", () => {
updatedAt: "200000",
searchIsLand: true,
searchAdjacentToRoad: true,
searchDistanceToPlaza: 3
searchDistanceToPlaza: 3,
}
newRentalId = "aNewRentalId"
rentalsSubgraphQueryMock.mockResolvedValueOnce({ rentals: [rentalFromIndexer] })
Expand Down Expand Up @@ -2769,8 +2787,12 @@ describe("when cancelling the rental listings", () => {
logs = createTestConsoleLogComponent()
config = createConfigComponent({ CHAIN_NAME: "Goerli", MAX_CONCURRENT_RENTAL_UPDATES: "5" })
rentalsComponent = await createRentalsComponent({ database, marketplaceSubgraph, rentalsSubgraph, logs, config })
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: new Date() }] })
jest.spyOn(Date, "now").mockReturnValueOnce(startDate.getTime())
dbQueryMock.mockResolvedValueOnce({ rows: [{ updated_at: startDate }] })
jest.useFakeTimers().setSystemTime(startDate)
})

afterEach(() => {
jest.useRealTimers();
})

describe("and there are no updated nonces since the latest job", () => {
Expand Down

0 comments on commit 45859d5

Please sign in to comment.