-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
issue-1929.ts
68 lines (60 loc) · 3.3 KB
/
issue-1929.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
import "reflect-metadata";
import {Product} from "./entity/Product";
import {Connection} from "../../../src/connection/Connection";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
describe("github issues > #1929 Select attributes in Find method - mongodb", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [Product],
enabledDrivers: ["mongodb"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("return column on include in select on find",
() => Promise.all(connections.map(async connection => {
const productRepository = connection.getMongoRepository(Product);
let product = new Product("test1", "label1", 10);
await productRepository.save(product);
product = new Product("test2", "label2", 20);
await productRepository.save(product);
product = new Product("test3", "label3", 30);
await productRepository.save(product);
const result = await productRepository.find({select: ["name", "label"], order: {name: 1}});
console.log(result);
})));
it("return column on include in select on findAndCount",
() => Promise.all(connections.map(async connection => {
const productRepository = connection.getMongoRepository(Product);
let product = new Product("test1", "label1", 10);
await productRepository.save(product);
product = new Product("test2", "label2", 20);
await productRepository.save(product);
product = new Product("test3", "label3", 30);
await productRepository.save(product);
const result = await productRepository.findAndCount({select: ["name", "label"], order: {name: 1}});
console.log(result);
})));
it("return column on include in select on findByIds",
() => Promise.all(connections.map(async connection => {
const productRepository = connection.getMongoRepository(Product);
let product = new Product("test1", "label1", 10);
await productRepository.save(product);
product = new Product("test2", "label2", 20);
await productRepository.save(product);
product = new Product("test3", "label3", 30);
const product3 = await productRepository.save(product);
const result = await productRepository.findByIds([product3.id], {select: ["name", "label"], order: {name: 1}});
console.log(result);
})));
it("return column on include in select on findByIds ",
() => Promise.all(connections.map(async connection => {
const productRepository = connection.getMongoRepository(Product);
let product = new Product("test1", "label1", 10);
await productRepository.save(product);
product = new Product("test2", "label2", 20);
await productRepository.save(product);
product = new Product("test3", "label3", 30);
const result = await productRepository.findOne({where: {name: "test2"}, select: ["name", "label"], order: {name: 1}});
console.log(result);
})));
});