Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: select supports false value instead of only undefined * test: issue-8796 * refactor: add test description * refactor: format code
- Loading branch information
Showing
3 changed files
with
74 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, Entity, PrimaryColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryColumn({ type: "int", nullable: false }) | ||
id: number | ||
|
||
@Column() | ||
firstName: string | ||
|
||
@Column() | ||
lastName: string | ||
|
||
@Column() | ||
github: string | ||
} |
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,57 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { Connection } from "../../../src/connection/Connection" | ||
import { expect } from "chai" | ||
import { User } from "../8796/entity/User" | ||
|
||
describe("github issues > #8796 New find select object api should support false values as expected", () => { | ||
let connections: Connection[] | ||
|
||
const user: User = { | ||
id: 1, | ||
firstName: "Christian", | ||
lastName: "Fleury", | ||
github: "chfleury", | ||
} | ||
|
||
const expectedUser: Partial<User> = { | ||
id: 1, | ||
firstName: "Christian", | ||
} | ||
|
||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should suport false value when selecting fields", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const userRepository = connection.getRepository(User) | ||
|
||
await userRepository.save(user) | ||
|
||
const foundUser = await userRepository.find({ | ||
where: { id: 1 }, | ||
select: { | ||
id: true, | ||
firstName: true, | ||
lastName: undefined, | ||
github: false, | ||
}, | ||
}) | ||
|
||
expect(foundUser[0]).to.deep.equal(expectedUser) | ||
}), | ||
)) | ||
}) |