|
| 1 | +import { Connection, createConnection } from 'typeorm'; |
| 2 | +import { AdvertEntity } from './entities/advert.entity'; |
| 3 | +import { UserEntity } from './entities/user.entity'; |
| 4 | +import { config } from 'dotenv'; |
| 5 | +import { resolve } from 'path'; |
| 6 | +import { AdvertRepository } from './repository/advert.repository'; |
| 7 | + |
| 8 | +describe('AbstractPolymorphicRepository', () => { |
| 9 | + let connection: Connection; |
| 10 | + beforeAll(async () => { |
| 11 | + config({ |
| 12 | + path: resolve(__dirname, '.', '..', '..', '.env'), |
| 13 | + }); |
| 14 | + |
| 15 | + connection = await createConnection({ |
| 16 | + type: 'mysql', |
| 17 | + host: process.env.TYPEORM_HOST, |
| 18 | + port: parseInt(process.env.TYPEORM_PORT, 10), |
| 19 | + username: process.env.TYPEORM_USERNAME, |
| 20 | + password: process.env.TYPEORM_PASSWORD, |
| 21 | + entities: ['./*/**/*.entity.ts'], |
| 22 | + synchronize: process.env.TYPEORM_SYNCHRONIZE === 'true', |
| 23 | + database: process.env.TYPEORM_DATABASE, |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + afterAll(async () => { |
| 28 | + await connection.close(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('Can create', async () => { |
| 32 | + const repository = connection.getCustomRepository(AdvertRepository); |
| 33 | + |
| 34 | + const user = new UserEntity(); |
| 35 | + |
| 36 | + const result = repository.create({ |
| 37 | + owner: user, |
| 38 | + }); |
| 39 | + |
| 40 | + expect(result).toBeInstanceOf(AdvertEntity); |
| 41 | + expect(result.owner).toBeInstanceOf(UserEntity); |
| 42 | + }); |
| 43 | +}); |
0 commit comments