From b3901b689903b6af15b3f9adc623caeeb18a4c26 Mon Sep 17 00:00:00 2001 From: Janko Marklein Date: Thu, 2 Jan 2020 15:14:20 +0100 Subject: [PATCH] remove additional information about deleted fields --- src/lib/action/content-type-field-purge.ts | 20 +++++++++++++++++++ src/lib/intent/field-delete.ts | 5 +++++ .../contentful-migration-integration.js | 2 +- .../lib/offline-api/request-batches.spec.ts | 15 -------------- .../payload-validation-display-field.spec.ts | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/lib/action/content-type-field-purge.ts diff --git a/src/lib/action/content-type-field-purge.ts b/src/lib/action/content-type-field-purge.ts new file mode 100644 index 000000000..27740a5d6 --- /dev/null +++ b/src/lib/action/content-type-field-purge.ts @@ -0,0 +1,20 @@ +import { APIAction } from './action' +import OfflineAPI from '../offline-api/index' + +class ContentTypeFieldPurgeAction extends APIAction { + private contentTypeId: string + private fieldId: string + + constructor (contentTypeId: string, fieldId: string) { + super() + this.contentTypeId = contentTypeId + this.fieldId = fieldId + } + + async applyTo (api: OfflineAPI) { + const contentType = await api.getContentType(this.contentTypeId) + contentType.fields.deleteField(this.fieldId) + } +} + +export { ContentTypeFieldPurgeAction } diff --git a/src/lib/intent/field-delete.ts b/src/lib/intent/field-delete.ts index 722f38011..327d056f6 100644 --- a/src/lib/intent/field-delete.ts +++ b/src/lib/intent/field-delete.ts @@ -3,6 +3,7 @@ import { FieldUpdateAction } from '../action/field-update' import { ContentTypeSaveAction } from '../action/content-type-save' import { ContentTypePublishAction } from '../action/content-type-publish' import { EntryFieldPurgeAction } from '../action/entry-field-purge' +import { ContentTypeFieldPurgeAction } from '../action/content-type-field-purge' import { PlanMessage } from '../interfaces/plan-message' import chalk from 'chalk' @@ -41,6 +42,10 @@ export default class FieldDeleteIntent extends Intent { new EntryFieldPurgeAction( contentTypeId, fieldId + ), + new ContentTypeFieldPurgeAction( + contentTypeId, + fieldId ) ] } diff --git a/test/fixtures/contentful-migration-integration.js b/test/fixtures/contentful-migration-integration.js index 897a63c40..2e2c351fa 100644 --- a/test/fixtures/contentful-migration-integration.js +++ b/test/fixtures/contentful-migration-integration.js @@ -1398,7 +1398,7 @@ nock('https://api.contentful.com:443', {"encodedQueryParams":true}) nock('https://api.contentful.com:443', {"encodedQueryParams":true}) - .put('/spaces/bohepdihyxin/environments/env-integration/content_types/dog', {"name":"angry dog","displayField":null,"fields":[{"id":"woofs","name":"woof woof","type":"Number","localized":false,"required":true,"validations":[],"disabled":false,"omitted":true,"deleted":true}],"description":"super angry"}) + .put('/spaces/bohepdihyxin/environments/env-integration/content_types/dog', {"name":"angry dog","displayField":null,"fields":[],"description":"super angry"}) .reply(200, { "sys": { "space": { diff --git a/test/unit/lib/offline-api/request-batches.spec.ts b/test/unit/lib/offline-api/request-batches.spec.ts index 6ed05a1fb..f2d5dd8e9 100644 --- a/test/unit/lib/offline-api/request-batches.spec.ts +++ b/test/unit/lib/offline-api/request-batches.spec.ts @@ -142,14 +142,6 @@ describe('Payload builder', function () { type: 'Number', name: 'kills', required: true - }, - { - id: 'favoriteFood', - type: 'Symbol', - name: 'food', - required: true, - omitted: true, - deleted: true } ] } @@ -178,13 +170,6 @@ describe('Payload builder', function () { required: true }, { - id: 'favoriteFood', - type: 'Symbol', - name: 'food', - required: true, - omitted: true, - deleted: true - }, { id: 'foo', type: 'Symbol', name: 'A foo' diff --git a/test/unit/lib/offline-api/validation/payload-validation-display-field.spec.ts b/test/unit/lib/offline-api/validation/payload-validation-display-field.spec.ts index ff34a7df7..b2fd58a84 100644 --- a/test/unit/lib/offline-api/validation/payload-validation-display-field.spec.ts +++ b/test/unit/lib/offline-api/validation/payload-validation-display-field.spec.ts @@ -66,7 +66,7 @@ describe('payload validation (display field)', function () { [ { type: 'InvalidAction', - message: 'Cannot delete field "dessert" on content type "lunch" because it is set as the display field' + message: 'Cannot set "dessert" as displayField on content type "lunch" because it does not exist' } ] ])