From 607ea8dcd72429bbfe6c940b7afb9cde4bd6bcb7 Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Wed, 26 Jul 2023 11:15:19 +0200 Subject: [PATCH] Added TagDeletedEvent refs https://github.com/TryGhost/Arch/issues/60 This will be used to update collections when a tag is deleted. Like the Post events this should not be in the collections package, instead we should have these as part of the tags and posts packages. These packages don't exist right now, so I'm following the existing pattern. --- ghost/collections/src/events/TagDeletedEvent.ts | 15 +++++++++++++++ ghost/collections/src/index.ts | 1 + ghost/collections/test/TagDeletedEvent.test.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ghost/collections/src/events/TagDeletedEvent.ts create mode 100644 ghost/collections/test/TagDeletedEvent.test.ts diff --git a/ghost/collections/src/events/TagDeletedEvent.ts b/ghost/collections/src/events/TagDeletedEvent.ts new file mode 100644 index 0000000000..b460147610 --- /dev/null +++ b/ghost/collections/src/events/TagDeletedEvent.ts @@ -0,0 +1,15 @@ +export class TagDeletedEvent { + id: string; + data: {slug: string, id: string}; + timestamp: Date; + + constructor(data: {slug: string, id: string}, timestamp: Date) { + this.id = data.id; + this.data = data; + this.timestamp = timestamp; + } + + static create(data: any, timestamp = new Date()) { + return new TagDeletedEvent(data, timestamp); + } +} diff --git a/ghost/collections/src/index.ts b/ghost/collections/src/index.ts index 205a008490..db92222232 100644 --- a/ghost/collections/src/index.ts +++ b/ghost/collections/src/index.ts @@ -4,3 +4,4 @@ export * from './Collection'; export * from './events/PostDeletedEvent'; export * from './events/PostAddedEvent'; export * from './events/PostEditedEvent'; +export * from './events/TagDeletedEvent'; diff --git a/ghost/collections/test/TagDeletedEvent.test.ts b/ghost/collections/test/TagDeletedEvent.test.ts new file mode 100644 index 0000000000..3440317390 --- /dev/null +++ b/ghost/collections/test/TagDeletedEvent.test.ts @@ -0,0 +1,13 @@ +import assert from 'assert/strict'; +import {TagDeletedEvent} from '../src'; + +describe('TagDeletedEvent', function () { + it('should create a TagDeletedEvent', function () { + const event = TagDeletedEvent.create({id: '1', slug: 'tag-1'}); + + const actual = event instanceof TagDeletedEvent; + const expected = true; + + assert.equal(actual, expected, 'TagDeletedEvent.create() did not return an instance of TagDeletedEvent'); + }); +});