Skip to content

Commit db8a2b2

Browse files
committed
refactor: move date UTC tests to functional test suite
Move tests from github-issues to test/functional/columns/date-utc following maintainer feedback. Improve test descriptions and add explanatory comments
1 parent 880e021 commit db8a2b2

3 files changed

Lines changed: 32 additions & 28 deletions

File tree

test/github-issues/11515/issue-11515.ts renamed to test/functional/columns/date-utc/date-utc.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
import "reflect-metadata"
2+
import { expect } from "chai"
23
import {
3-
createTestingConnections,
44
closeTestingConnections,
5+
createTestingConnections,
56
reloadTestingDatabases,
6-
} from "../../utils/test-utils"
7-
import { DataSource } from "../../../src"
7+
} from "../../../utils/test-utils"
88
import { Event } from "./entity/Event"
9-
import { after, before } from "mocha"
10-
import { expect } from "chai"
9+
import { DataSource } from "../../../../src"
1110

12-
describe("github issues > #11515 DateUtils.mixedDateToDateString should support UTC", () => {
11+
describe("columns > date utc flag", () => {
1312
let originalTZ: string | undefined
1413
let connections: DataSource[]
1514

1615
before(async () => {
1716
originalTZ = process.env.TZ
1817
process.env.TZ = "America/New_York"
1918
connections = await createTestingConnections({
20-
entities: [__dirname + "/entity/*{.js,.ts}"],
19+
entities: [Event],
2120
})
2221
})
2322

2423
after(async () => {
2524
process.env.TZ = originalTZ
2625
await closeTestingConnections(connections)
2726
})
27+
2828
beforeEach(() => reloadTestingDatabases(connections))
2929

30-
it("should save the date column in UTC when the utc flag is true", () =>
30+
it("should save date columns in UTC when utc flag is true and in local timezone when false", () =>
3131
Promise.all(
3232
connections.map(async (connection) => {
3333
const event = new Event()
34-
const utc = new Date(Date.UTC(2025, 5, 1))
34+
const testDate = new Date(Date.UTC(2025, 5, 1)) // 2025-06-01 in UTC
3535

36-
event.localDate = utc
37-
event.utcDate = utc
36+
event.localDate = testDate
37+
event.utcDate = testDate
3838

39-
const saveEvent = await connection.manager.save(event)
39+
const savedEvent = await connection.manager.save(event)
4040
const result = await connection.manager.findOneBy(Event, {
41-
id: saveEvent.id,
41+
id: savedEvent.id,
4242
})
4343

44+
// UTC flag true: should save as 2025-06-01 (UTC date)
4445
expect(result!.utcDate).to.equal("2025-06-01")
46+
// UTC flag false (default): should save as 2025-05-31 (local timezone)
4547
expect(result!.localDate).to.equal("2025-05-31")
4648
}),
4749
))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Entity } from "../../../../../src/decorator/entity/Entity"
2+
import { PrimaryGeneratedColumn } from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"
3+
import { Column } from "../../../../../src/decorator/columns/Column"
4+
5+
@Entity({
6+
name: "event",
7+
})
8+
export class Event {
9+
@PrimaryGeneratedColumn()
10+
id: number
11+
12+
@Column({ type: "date" })
13+
localDate: Date
14+
15+
@Column({ type: "date", utc: true })
16+
utcDate: Date
17+
}

‎test/github-issues/11515/entity/Event.ts‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)