-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
issue-5501.ts
80 lines (72 loc) · 3 KB
/
issue-5501.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import "reflect-metadata";
import { Connection } from "../../../src/connection/Connection";
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Post } from "./entity/Post";
import { expect } from "chai";
describe("github issues > #5501 Incorrect data loading from JSON string for column type 'simple-json'", () => {
let connections: Connection[];
before(async () => {
connections = await createTestingConnections({
entities: [Post],
schemaCreate: true,
dropSchema: true
});
});
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should correctly add/retrieve simple-json field with a string value", () =>
Promise.all(connections.map(async (connection) => {
const repo = connection.getRepository(Post);
const post = new Post();
post.id = 1;
post.jsonField = "";
await repo.save(post);
const postFound = await repo.findOne(1);
postFound!.id.should.eql(1);
postFound!.jsonField.should.eql("");
})));
it("should correctly add/retrieve simple-json field with some object value", () =>
Promise.all(connections.map(async (connection) => {
const repo = connection.getRepository(Post);
const post = new Post();
post.id = 1;
post.jsonField = {"key": "value"};
await repo.save(post);
const postFound = await repo.findOne(1);
postFound!.id.should.eql(1);
postFound!.jsonField.should.eql({"key": "value"});
})));
it("should correctly add/retrieve simple-json field with an array value", () =>
Promise.all(connections.map(async (connection) => {
const repo = connection.getRepository(Post);
const post = new Post();
post.id = 1;
post.jsonField = [{"key": "value"}];
await repo.save(post);
const postFound = await repo.findOne(1);
postFound!.id.should.eql(1);
postFound!.jsonField.should.eql([{"key": "value"}]);
})));
it("should correctly add/retrieve simple-json field with null value", () =>
Promise.all(connections.map(async (connection) => {
const repo = connection.getRepository(Post);
const post = new Post();
post.id = 1;
post.jsonField = null;
await repo.save(post);
const postFound = await repo.findOne(1);
postFound!.id.should.eql(1);
expect(postFound!.jsonField).to.eql(null);
})));
it.only("should correctly add/retrieve simple-json field with 'null' string value", () =>
Promise.all(connections.map(async (connection) => {
const repo = connection.getRepository(Post);
const post = new Post();
post.id = 1;
post.jsonField = "null";
await repo.save(post);
const postFound = await repo.findOne(1);
postFound!.id.should.eql(1);
expect(postFound!.jsonField).to.eql("null");
})));
});