mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 19:04:38 +00:00
Update tests
This commit is contained in:
parent
c9516d4bf5
commit
c4573af2eb
@ -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 () => {
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user