Skip to content

Commit

Permalink
test: add test for 3426
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Jul 9, 2021
1 parent 3150760 commit 401cb10
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
12 changes: 12 additions & 0 deletions test/github-issues/2286/entity/Example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
import {Column} from "../../../../src/decorator/columns/Column";

@Entity()
export class Example {
@PrimaryColumn()
id: Date;

@Column()
text: string
}
31 changes: 28 additions & 3 deletions test/github-issues/2286/issue-2286.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { createTestingConnections, closeTestingConnections, reloadTestingDatabas
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";
import { Post } from "./entity/Post";
import { Example } from "./entity/Example";
import { Between } from "../../../src";

describe("github issues > #2286 find operators like MoreThan and LessThan doesn't work properly for date fields", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
entities: [ Post, Example ],
schemaCreate: true,
dropSchema: true,
/* Test not eligible for better-sql where binding Dates is impossible */
enabledDrivers: ["sqlite"]
}));
beforeEach(() => reloadTestingDatabases(connections));

after(() => closeTestingConnections(connections));

it("should find a record by its datetime value with find options", () => Promise.all(connections.map(async connection => {
Expand Down Expand Up @@ -52,4 +53,28 @@ describe("github issues > #2286 find operators like MoreThan and LessThan doesn'
.getOne();
expect(postByDateEquals).to.not.be.undefined;
})));
});

it("should save, update, and load with a date PK", () => Promise.all(connections.map(async connection => {
const start = new Date("2000-01-01");
const middle = new Date("2000-06-30");
const end = new Date("2001-01-01");

await connection.manager.save(Example, { id: start, text: "start" });
await connection.manager.save(Example, { id: middle, text: "middle" });
await connection.manager.save(Example, { id: end, text: "end" });

const repo = connection.manager.getRepository(Example);

let example = await repo.findOneOrFail({ id: middle });

expect(example.text).to.be.equal("middle");

example.text = "in between";

await repo.save(example);

example = await repo.findOneOrFail({ id: middle });

expect(example.text).to.be.equal("in between");
})));
});

0 comments on commit 401cb10

Please sign in to comment.