-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve issue with conversion string to simple-json (#4476)
Closes: #4440
- Loading branch information
1 parent
c321562
commit d1594f5
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Column } from "../../../../src/decorator/columns/Column"; | ||
import { PrimaryColumn } from "../../../../src/decorator/columns/PrimaryColumn"; | ||
import { Entity } from "../../../../src/decorator/entity/Entity"; | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column({ | ||
type: "simple-json", | ||
nullable: true | ||
}) | ||
jsonField: any; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Post } from "./entity/Post"; | ||
|
||
describe("github issues > #4440 simple-json column type throws error for string with no value", () => { | ||
|
||
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 no 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 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"}); | ||
}))); | ||
|
||
}); |