diff --git a/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/index.test.ts b/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/index.test.ts index d41d903112..1a175d1ab6 100644 --- a/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/index.test.ts +++ b/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/index.test.ts @@ -107,61 +107,6 @@ describe('Local Strapi Source Destination', () => { expect(deleteAllSpy).toBeCalledTimes(1); }); - test('Should delete only chosen contentTypes', async () => { - const entities = [ - { - entity: { id: 1, title: 'My first foo' }, - contentType: { uid: 'foo' }, - }, - { - entity: { id: 4, title: 'Another Foo' }, - contentType: { uid: 'foo' }, - }, - { - entity: { id: 12, title: 'Last foo' }, - contentType: { uid: 'foo' }, - }, - { - entity: { id: 1, age: 21 }, - contentType: { uid: 'bar' }, - }, - { - entity: { id: 2, age: 42 }, - contentType: { uid: 'bar' }, - }, - { - entity: { id: 7, age: 84 }, - contentType: { uid: 'bar' }, - }, - { - entity: { id: 9, age: 0 }, - contentType: { uid: 'bar' }, - }, - ]; - const deleteMany = jest.fn(async (uid: string) => ({ - count: entities.filter((entity) => entity.contentType.uid === uid).length, - })); - const provider = createLocalStrapiDestinationProvider({ - getStrapi: getStrapiFactory({ - contentTypes: getContentTypes(), - entityService: { - deleteMany, - }, - }), - strategy: 'restore', - restore: { - /* @ts-ignore: disable-next-line */ - contentTypes: [getContentTypes()['foo']], - }, - }); - - const deleteAllSpy = jest.spyOn(restoreApi, 'deleteAllRecords'); - await provider.bootstrap(); - await provider.beforeStreaming(); - - expect(deleteAllSpy).toBeCalledTimes(1); - }); - test('Should not delete if it is a merge strategy', async () => { const provider = createLocalStrapiDestinationProvider({ getStrapi: getStrapiFactory({}), diff --git a/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/restore.test.ts b/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/restore.test.ts new file mode 100644 index 0000000000..890fc8217f --- /dev/null +++ b/packages/core/data-transfer/lib/providers/local-strapi-destination-provider/__tests__/restore.test.ts @@ -0,0 +1,68 @@ +import { deleteAllRecords } from '../restore'; +import { getStrapiFactory, getContentTypes } from '../../test-utils'; + +const entities = [ + { + entity: { id: 1, title: 'My first foo' }, + contentType: { uid: 'foo' }, + }, + { + entity: { id: 4, title: 'Another Foo' }, + contentType: { uid: 'foo' }, + }, + { + entity: { id: 12, title: 'Last foo' }, + contentType: { uid: 'foo' }, + }, + { + entity: { id: 1, age: 21 }, + contentType: { uid: 'bar' }, + }, + { + entity: { id: 2, age: 42 }, + contentType: { uid: 'bar' }, + }, + { + entity: { id: 7, age: 84 }, + contentType: { uid: 'bar' }, + }, + { + entity: { id: 9, age: 0 }, + contentType: { uid: 'bar' }, + }, +]; + +describe('Restore ', () => { + test('Should delete all contentTypes', async () => { + const deleteMany = jest.fn(async (uid: string) => ({ + count: entities.filter((entity) => entity.contentType.uid === uid).length, + })); + const strapi = getStrapiFactory({ + contentTypes: getContentTypes(), + entityService: { + deleteMany, + }, + })(); + + const { count } = await deleteAllRecords(strapi); + expect(count).toBe(entities.length); + }); + + test('Should only delete chosen contentTypes', async () => { + const deleteMany = jest.fn(async (uid: string) => ({ + count: entities.filter((entity) => entity.contentType.uid === uid).length, + })); + const strapi = getStrapiFactory({ + contentTypes: getContentTypes(), + entityService: { + deleteMany, + }, + })(); + + const { count } = await deleteAllRecords(strapi, { + /* @ts-ignore: disable-next-line */ + contentTypes: [getContentTypes()['foo']], + }); + expect(count).toBe(3); + }); +});