Skip to content

Commit

Permalink
Add assertion test for issue typeorm#5762
Browse files Browse the repository at this point in the history
  • Loading branch information
dhritzkiv committed Jun 17, 2021
1 parent 7a0f773 commit 17b2ee6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/github-issues/5762/entity/User.ts
@@ -0,0 +1,24 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {PrimaryColumn, Column} from "../../../../src";
import { URL } from "url";

@Entity()
export class User {

@PrimaryColumn()
id: number;

@Column("varchar", {
// marshall
transformer: {
from(value: string): URL {
return new URL(value);
},
to(value: URL): string {
return value.toString();
},
},
})
url: URL;

}
39 changes: 39 additions & 0 deletions test/github-issues/5762/issue-5762.ts
@@ -0,0 +1,39 @@
import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../../src";
import {User} from "./entity/User";
import {createTestingConnections, reloadTestingDatabases, closeTestingConnections} from "../../utils/test-utils";
import { URL } from "url";

describe("github issues > #5762 `Using URL as a rich column type breaks", () => {

let connections: Connection[];

before(async () => {
connections = await createTestingConnections({
entities: [User],
schemaCreate: true,
dropSchema: true
});
});
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should allow assigning URL as a field value", () =>
Promise.all(connections.map(async (connection) => {
const userRepository = connection.getRepository(User);

const url = new URL("https://typeorm.io");

const user = new User();
user.id = 1;
user.url = url;

const promise = userRepository.save(user);

return expect(promise).to.eventually.be.deep.equal(user)
.and.to.have.property("url").be.instanceOf(URL)
.and.to.have.nested.property("href").equal(url.href);
})));

});

0 comments on commit 17b2ee6

Please sign in to comment.