Skip to content

Commit

Permalink
test: move transformer tests in functionnal folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammy Teillet authored and Sammy Teillet committed Apr 23, 2019
1 parent d913753 commit 5a545c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, ValueTransformer, Entity, PrimaryGeneratedColumn } from "../../../../src";
import { Column, ValueTransformer, Entity, PrimaryGeneratedColumn } from "../../../../../src";

export const encode: ValueTransformer = {
const encode: ValueTransformer = {
to: (entityValue: string) => {
return encodeURI(entityValue);
},
Expand All @@ -9,7 +9,7 @@ export const encode: ValueTransformer = {
},
};

export const encrypt: ValueTransformer = {
const encrypt: ValueTransformer = {
to: (entityValue: string) => {
return Buffer.from(entityValue).toString("base64");
},
Expand All @@ -19,7 +19,7 @@ export const encrypt: ValueTransformer = {
};


export const lowercase: ValueTransformer = {
const lowercase: ValueTransformer = {
to: (entityValue: string) => {
return entityValue.toLocaleLowerCase();
},
Expand All @@ -33,6 +33,6 @@ export class User {
@PrimaryGeneratedColumn("uuid")
id: string;

@Column({transformer: [lowercase, encode]})
@Column({transformer: [lowercase, encode, encrypt]})
email: string;
}
17 changes: 15 additions & 2 deletions test/functional/columns/value-transformer/value-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import "reflect-metadata";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";

import {Connection} from "../../../../src/connection/Connection";
import { PhoneBook } from "./entity/PhoneBook";
import {PhoneBook} from "./entity/PhoneBook";
import {Post} from "./entity/Post";
import {User} from "./entity/User";
import {expect} from "chai";

describe("columns > value-transformer functionality", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [Post, PhoneBook],
entities: [Post, PhoneBook, User],
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand Down Expand Up @@ -54,5 +55,17 @@ describe("columns > value-transformer functionality", () => {

})));

it("should apply three transformers", () => Promise.all(connections.map(async connection => {
const userRepository = await connection.getRepository(User);
const email = `${connection.name}@JOHN.doe`;
const user = new User();
user.email = email;

await userRepository.save(user);

const dbUser = await userRepository.findOne();
dbUser && dbUser.email.should.be.eql(email.toLocaleLowerCase());

})));

});
11 changes: 0 additions & 11 deletions test/github-issues/4007/entity/Category.ts

This file was deleted.

11 changes: 0 additions & 11 deletions test/github-issues/4007/entity/Secret.ts

This file was deleted.

53 changes: 0 additions & 53 deletions test/github-issues/4007/issue-4007.ts

This file was deleted.

0 comments on commit 5a545c3

Please sign in to comment.