/
issue-587.ts
30 lines (26 loc) · 1.38 KB
/
issue-587.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
import "reflect-metadata";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
describe("github issues > #587 Ordering of fields in composite indexes defined using Index decorator", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["mysql"]
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
// this test only works for fields specified as string[]
it("should preserve field ordering when fields are specified as string[]", () => Promise.all(connections.map(async connection => {
connection.entityMetadatas.forEach(entityMetadata => {
entityMetadata.indices.forEach(index => {
if (index.givenColumnNames && Array.isArray(index.givenColumnNames)) {
for (let i = 0; i < index.columns.length; i++) {
const givenColumn = (index.givenColumnNames as string[])[i];
const actualColumn = index.columns[i];
actualColumn.propertyName.should.equal(givenColumn);
}
}
});
});
})));
});