Replaced deprecated Connection API in tests (#451)

This commit is contained in:
Robin De Schepper 2023-01-24 17:59:12 +01:00 committed by GitHub
parent 8832cfae74
commit 30f4b45785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
import { createConnection, Repository, In, Connection } from 'typeorm'
import { Repository, In, DataSource } from 'typeorm'
import {
Paginated,
paginate,
@ -17,7 +17,7 @@ import { CatHomeEntity } from './__tests__/cat-home.entity'
import { clone } from 'lodash'
describe('paginate', () => {
let connection: Connection
let dataSource: DataSource
let catRepo: Repository<CatEntity>
let catToyRepo: Repository<CatToyEntity>
let catHomeRepo: Repository<CatHomeEntity>
@ -26,16 +26,18 @@ describe('paginate', () => {
let catHomes: CatHomeEntity[]
beforeAll(async () => {
connection = await createConnection({
dataSource = new DataSource({
type: 'sqlite',
database: ':memory:',
synchronize: true,
logging: false,
entities: [CatEntity, CatToyEntity, CatHomeEntity],
})
catRepo = connection.getRepository(CatEntity)
catToyRepo = connection.getRepository(CatToyEntity)
catHomeRepo = connection.getRepository(CatHomeEntity)
await dataSource.initialize()
catRepo = dataSource.getRepository(CatEntity)
catToyRepo = dataSource.getRepository(CatToyEntity)
catHomeRepo = dataSource.getRepository(CatHomeEntity)
cats = await catRepo.save([
catRepo.create({ name: 'Milo', color: 'brown', age: 6, size: { height: 25, width: 10, length: 40 } }),
catRepo.create({ name: 'Garfield', color: 'ginger', age: 5, size: { height: 30, width: 15, length: 45 } }),
@ -98,7 +100,7 @@ describe('paginate', () => {
path: '',
}
const queryBuilder = await connection
const queryBuilder = await dataSource
.createQueryBuilder()
.select('cats')
.from(CatEntity, 'cats')