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.
This commit is contained in:
Fabien "egg" O'Carroll 2023-07-26 11:15:19 +02:00 committed by Fabien 'egg' O'Carroll
parent acd84fe25c
commit 607ea8dcd7
3 changed files with 29 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -4,3 +4,4 @@ export * from './Collection';
export * from './events/PostDeletedEvent';
export * from './events/PostAddedEvent';
export * from './events/PostEditedEvent';
export * from './events/TagDeletedEvent';

View File

@ -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');
});
});