forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformed-json-column-update-compute.ts
53 lines (41 loc) · 1.68 KB
/
transformed-json-column-update-compute.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import "reflect-metadata";
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Connection } from "../../../src/connection/Connection";
import { expect } from "chai";
import { DummyJSONEntity } from "./entity/json-entity";
import { DummyJSONBEntity } from "./entity/jsonb-entity";
describe("other issues > correctly compute change for transformed json / jsonb columns", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchema: true,
enabledDrivers: ["postgres"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should not update entity if transformed JSON column did not change", () => Promise.all(connections.map(async connection => {
const repository = connection.getRepository(DummyJSONEntity);
const dummy = repository.create({
value: {
secretProperty: "hello"
},
});
await repository.save(dummy);
await repository.save(dummy);
const dummyEntity = await repository.findOneOrFail(dummy.id);
expect(dummyEntity.version).to.equal(1);
})));
it("should not update entity if transformed JSONB column did not change", () => Promise.all(connections.map(async connection => {
const repository = connection.getRepository(DummyJSONBEntity);
const dummy = repository.create({
value: {
secretProperty: "hello"
},
});
await repository.save(dummy);
await repository.save(dummy);
const dummyEntity = await repository.findOneOrFail(dummy.id);
expect(dummyEntity.version).to.equal(1);
})));
});