From 079318379dd9878d6cb7a1803cac24be3d5dfa45 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 20 May 2024 12:23:03 +0100 Subject: [PATCH] Fix date math problem in search tests. --- .../src/api/routes/tests/search.spec.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 87d0aa72c7..93cd9fdfcd 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -21,9 +21,6 @@ import _ from "lodash" import tk from "timekeeper" import { encodeJSBinding } from "@budibase/string-templates" -const serverTime = new Date("2024-05-06T00:00:00.000Z") -tk.freeze(serverTime) - describe.each([ ["lucene", undefined], ["sqs", undefined], @@ -251,6 +248,8 @@ describe.each([ describe("bindings", () => { let globalUsers: any = [] + const serverTime = new Date() + serverTime.setMilliseconds(0) const future = new Date(serverTime.getTime()) future.setDate(future.getDate() + 30) @@ -358,20 +357,22 @@ describe.each([ }) it("should parse the date binding and return all rows after the resolved value", async () => { - await expectQuery({ - range: { - appointment: { - low: "{{ [now] }}", - high: "9999-00-00T00:00:00.000Z", + await tk.withFreeze(serverTime, async () => { + await expectQuery({ + range: { + appointment: { + low: "{{ [now] }}", + high: "9999-00-00T00:00:00.000Z", + }, }, - }, - }).toContainExactly([ - { - name: config.getUser().firstName, - appointment: future.toISOString(), - }, - { name: "serverDate", appointment: serverTime.toISOString() }, - ]) + }).toContainExactly([ + { + name: config.getUser().firstName, + appointment: future.toISOString(), + }, + { name: "serverDate", appointment: serverTime.toISOString() }, + ]) + }) }) it("should parse the date binding and return all rows before the resolved value", async () => {