-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
base-entity.test.ts
51 lines (43 loc) · 1.8 KB
/
base-entity.test.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
import "../../utils/test-setup"
import { setupTestingConnections } from "../../utils/test-utils"
import { User } from "./entity/User"
import { expect } from "chai"
import { DataSource } from "../../../src"
describe("base entity", () => {
it("test if DataSource calls `useDataSource` of the provided entities", async () => {
const dataSourceOptions = setupTestingConnections({
entities: [User],
enabledDrivers: ["sqlite"],
})
if (!dataSourceOptions.length) return
// reset data source just to make sure inside DataSource it's really being set
User.useDataSource(null)
const dataSource = new DataSource(dataSourceOptions[0])
await dataSource.initialize()
await dataSource.synchronize(true)
await User.save({ name: "Timber Saw" })
const timber = await User.findOneByOrFail({ name: "Timber Saw" })
expect(timber).to.be.eql({
id: 1,
name: "Timber Saw",
})
})
it("test if DataSource calls `useDataSource` of the provided entities in the entities directory", async () => {
const dataSourceOptions = setupTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["sqlite"],
})
if (!dataSourceOptions.length) return
// reset data source just to make sure inside DataSource it's really being set
User.useDataSource(null)
const dataSource = new DataSource(dataSourceOptions[0])
await dataSource.initialize()
await dataSource.synchronize(true)
await User.save({ name: "Timber Saw" })
const timber = await User.findOneByOrFail({ name: "Timber Saw" })
expect(timber).to.be.eql({
id: 1,
name: "Timber Saw",
})
})
})