From 2e1a0acf898d1ed9e89c3fad50d30cf20ae0a1f1 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 23 Dec 2018 16:50:20 +0100 Subject: [PATCH] fixing test --- backend/model/sql/SQLConnection.ts | 6 +++++- backend/model/threading/MetadataLoader.ts | 1 - test/backend/integration/model/sql/typeorm.ts | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/model/sql/SQLConnection.ts b/backend/model/sql/SQLConnection.ts index 20860251..004aef55 100644 --- a/backend/model/sql/SQLConnection.ts +++ b/backend/model/sql/SQLConnection.ts @@ -101,7 +101,11 @@ export class SQLConnection { } version.version = DataStructureVersion; - const users = await connection.getRepository(UserEntity).find(); + let users: UserEntity[] = []; + try { + users = await connection.getRepository(UserEntity).createQueryBuilder('user').getMany(); + } catch (ex) { + } await connection.dropDatabase(); await connection.synchronize(); await connection.getRepository(VersionEntity).save(version); diff --git a/backend/model/threading/MetadataLoader.ts b/backend/model/threading/MetadataLoader.ts index abc0849d..16e506e0 100644 --- a/backend/model/threading/MetadataLoader.ts +++ b/backend/model/threading/MetadataLoader.ts @@ -81,7 +81,6 @@ export class MetadataLoader { try { const stat = fs.statSync(fullPath); - console.log(stat); metadata.fileSize = stat.size; metadata.creationDate = stat.ctime.getTime(); } catch (err) { diff --git a/test/backend/integration/model/sql/typeorm.ts b/test/backend/integration/model/sql/typeorm.ts index 7c8673ca..f3f3d763 100644 --- a/test/backend/integration/model/sql/typeorm.ts +++ b/test/backend/integration/model/sql/typeorm.ts @@ -16,6 +16,8 @@ import { PositionMetaDataEntity } from '../../../../../backend/model/sql/enitites/PhotoEntity'; import {MediaDimensionEntity} from '../../../../../backend/model/sql/enitites/MediaEntity'; +import {DataStructureVersion} from '../../../../../common/DataStructureVersion'; +import {VersionEntity} from '../../../../../backend/model/sql/enitites/VersionEntity'; describe('Typeorm integration', () => { @@ -104,6 +106,25 @@ describe('Typeorm integration', () => { return d; }; + it('should migrate users', async () => { + const conn = await SQLConnection.getConnection(); + const a = new UserEntity(); + a.name = 'migrated admin'; + a.password = PasswordHelper.cryptPassword('Test admin'); + a.role = UserRoles.Admin; + await conn.getRepository(UserEntity).save(a); + + const version = await conn.getRepository(VersionEntity).findOne(); + version.version--; + await conn.getRepository(VersionEntity).save(version); + + await SQLConnection.close(); + + const conn2 = await SQLConnection.getConnection(); + const admins = await conn2.getRepository(UserEntity).find({name: 'migrated admin'}); + expect(admins.length).to.be.equal(1); + }); + it('should open and close connection', async () => { const conn = await SQLConnection.getConnection(); expect(conn.isConnected).to.equal(true);