1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

Fixes #6346 - issue with date parsing, adding in some testing around it.

This commit is contained in:
mike12345567 2023-06-13 16:11:22 +01:00
parent 6158b4ac65
commit 60d58034dd
2 changed files with 26 additions and 3 deletions

View file

@ -91,7 +91,7 @@ const SCHEMA: Integration = {
},
}
function bindingTypeCoerce(bindings: any[]) {
export function bindingTypeCoerce(bindings: any[]) {
for (let i = 0; i < bindings.length; i++) {
const binding = bindings[i]
if (typeof binding !== "string") {
@ -109,7 +109,12 @@ function bindingTypeCoerce(bindings: any[]) {
dayjs(binding).isValid() &&
!binding.includes(",")
) {
bindings[i] = dayjs(binding).toDate()
let value: any
value = new Date(binding)
if (isNaN(value)) {
value = binding
}
bindings[i] = value
}
}
return bindings

View file

@ -1,4 +1,4 @@
import { default as MySQLIntegration } from "../mysql"
import { default as MySQLIntegration, bindingTypeCoerce } from "../mysql"
jest.mock("mysql2")
class TestConfiguration {
@ -131,3 +131,21 @@ describe("MySQL Integration", () => {
})
})
})
describe("bindingTypeCoercion", () => {
it("shouldn't coerce something that looks like a date", () => {
const response = bindingTypeCoerce(["202205-1500"])
expect(response[0]).toBe("202205-1500")
})
it("should coerce an actual date", () => {
const date = new Date("2023-06-13T14:24:22.620Z")
const response = bindingTypeCoerce(["2023-06-13T14:24:22.620Z"])
expect(response[0]).toEqual(date)
})
it("should coerce numbers", () => {
const response = bindingTypeCoerce(["0"])
expect(response[0]).toEqual(0)
})
})