mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
fix unit tests
This commit is contained in:
parent
5e8d1ae9ee
commit
81f4a931a9
@ -17,6 +17,12 @@ const createWriteStreamMock = jest.fn(() => {
|
||||
});
|
||||
|
||||
jest.mock('fs-extra');
|
||||
const transaction = jest.fn(async (cb) => {
|
||||
const trx = {};
|
||||
const rollback = jest.fn();
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
await cb({ trx, rollback });
|
||||
});
|
||||
|
||||
describe('Local Strapi Destination Provider - Get Assets Stream', () => {
|
||||
test('Throws an error if the Strapi instance is not provided', async () => {
|
||||
@ -37,6 +43,7 @@ describe('Local Strapi Destination Provider - Get Assets Stream', () => {
|
||||
public: 'static/public/assets',
|
||||
},
|
||||
},
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'restore',
|
||||
});
|
||||
@ -63,6 +70,7 @@ describe('Local Strapi Destination Provider - Get Assets Stream', () => {
|
||||
public: assetsDirectory,
|
||||
},
|
||||
},
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'restore',
|
||||
});
|
||||
|
||||
@ -17,11 +17,20 @@ jest.mock('../strategies/restore', () => {
|
||||
};
|
||||
});
|
||||
|
||||
const transaction = jest.fn(async (cb) => {
|
||||
const trx = {};
|
||||
const rollback = jest.fn();
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
await cb({ trx, rollback });
|
||||
});
|
||||
|
||||
describe('Local Strapi Source Destination', () => {
|
||||
describe('Bootstrap', () => {
|
||||
test('Should not have a defined Strapi instance if bootstrap has not been called', () => {
|
||||
const provider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory(),
|
||||
getStrapi: getStrapiFactory({
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'restore',
|
||||
});
|
||||
|
||||
@ -30,7 +39,9 @@ describe('Local Strapi Source Destination', () => {
|
||||
|
||||
test('Should have a defined Strapi instance if bootstrap has been called', async () => {
|
||||
const provider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory(),
|
||||
getStrapi: getStrapiFactory({
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'restore',
|
||||
});
|
||||
await provider.bootstrap();
|
||||
@ -42,14 +53,18 @@ describe('Local Strapi Source Destination', () => {
|
||||
describe('Strategy', () => {
|
||||
test('requires strategy to be either restore or merge', async () => {
|
||||
const restoreProvider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory(),
|
||||
getStrapi: getStrapiFactory({
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'restore',
|
||||
});
|
||||
await restoreProvider.bootstrap();
|
||||
expect(restoreProvider.strapi).toBeDefined();
|
||||
|
||||
const mergeProvider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory(),
|
||||
getStrapi: getStrapiFactory({
|
||||
db: { transaction },
|
||||
}),
|
||||
strategy: 'merge',
|
||||
});
|
||||
await mergeProvider.bootstrap();
|
||||
@ -58,7 +73,9 @@ describe('Local Strapi Source Destination', () => {
|
||||
await expect(
|
||||
(async () => {
|
||||
const invalidProvider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory(),
|
||||
getStrapi: getStrapiFactory({
|
||||
db: { transaction },
|
||||
}),
|
||||
/* @ts-ignore: disable-next-line */
|
||||
strategy: 'foo',
|
||||
});
|
||||
@ -115,10 +132,6 @@ describe('Local Strapi Source Destination', () => {
|
||||
};
|
||||
});
|
||||
|
||||
const transaction = jest.fn(async (cb) => {
|
||||
await cb();
|
||||
});
|
||||
|
||||
const getModel = jest.fn((uid: string) => getContentTypes()[uid]);
|
||||
|
||||
const strapi = getStrapiFactory({
|
||||
@ -142,9 +155,6 @@ describe('Local Strapi Source Destination', () => {
|
||||
});
|
||||
|
||||
test('Should not delete if it is a merge strategy', async () => {
|
||||
const transaction = jest.fn(async (cb) => {
|
||||
await cb();
|
||||
});
|
||||
const provider = createLocalStrapiDestinationProvider({
|
||||
getStrapi: getStrapiFactory({
|
||||
db: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user