diff --git a/packages/core/database/src/__tests__/index.test.ts b/packages/core/database/src/__tests__/index.test.ts index 5cbc37b2f4..8c28be771b 100644 --- a/packages/core/database/src/__tests__/index.test.ts +++ b/packages/core/database/src/__tests__/index.test.ts @@ -1,7 +1,7 @@ -import { Database } from '../index'; +import { Database, DatabaseConfig } from '../index'; -jest.mock('../connection', () => - jest.fn(() => { +jest.mock('../connection', () => ({ + createConnection: jest.fn(() => { const trx = { commit: jest.fn(), rollback: jest.fn(), @@ -10,8 +10,8 @@ jest.mock('../connection', () => ...trx, transaction: jest.fn(async () => trx), }; - }) -); + }), +})); jest.mock('../dialects', () => ({ getDialect: jest.fn(() => ({ @@ -24,10 +24,13 @@ jest.mock('../migrations', () => ({ createMigrationsProvider: jest.fn(), })); -const config = { +const config: DatabaseConfig = { models: [ { + uid: 'test', + singularName: 'test', tableName: 'strapi_core_store_settings', + attributes: {}, }, ], connection: { @@ -40,14 +43,11 @@ const config = { host: 'localhost', }, }, + settings: {}, }; describe('Database', () => { describe('constructor', () => { - it('should throw an error if no config is provided', async () => { - expect(async () => Database.init()).rejects.toThrowError(); - }); - it('it should intialize if config is provided', async () => { expect(() => Database.init(config)).toBeDefined(); }); @@ -63,7 +63,7 @@ describe('Database', () => { const db = await Database.init(config); const result = await db.transaction(async () => 'test'); expect(result).toBe('test'); - expect(db.connection.commit).toHaveBeenCalledTimes(1); + expect((db.connection as any).commit).toHaveBeenCalledTimes(1); }); it('rollback is called incase of error', async () => { @@ -75,7 +75,7 @@ describe('Database', () => { } catch { /* ignore */ } - expect(db.connection.rollback).toHaveBeenCalledTimes(1); + expect((db.connection as any).rollback).toHaveBeenCalledTimes(1); }); it('should throw error', async () => { diff --git a/packages/core/database/src/__tests__/lifecycles.test.ts b/packages/core/database/src/__tests__/lifecycles.test.ts index 577a27f52a..bc35d797c4 100644 --- a/packages/core/database/src/__tests__/lifecycles.test.ts +++ b/packages/core/database/src/__tests__/lifecycles.test.ts @@ -1,4 +1,5 @@ import { createLifecyclesProvider } from '../lifecycles'; +import type { Database } from '..'; describe('LifecycleProvider', () => { describe('run', () => { @@ -11,7 +12,8 @@ describe('LifecycleProvider', () => { metadata: { get: dbMetadataGetStub, }, - }; + } as any as Database; + provider = createLifecyclesProvider(db); provider.clear(); });