Fixes #6346 - issue with date parsing, adding in some testing around it.
This commit is contained in:
parent
6158b4ac65
commit
60d58034dd
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue