mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Fixed tag.deleted event mapping
https://github.com/TryGhost/Arch/issues/90 - When a tag.deleted event is emitted the original 'data' object does not contain an 'id' property. The logic in collections service assumes the id would be present to update the collections efficiently.
This commit is contained in:
parent
11624e48ca
commit
cb532ea819
2 changed files with 32 additions and 1 deletions
|
@ -94,7 +94,10 @@ export class ModelToDomainEventInterceptor {
|
|||
});
|
||||
break;
|
||||
case 'tag.deleted':
|
||||
event = TagDeletedEvent.create({id: data.id, slug: data.attributes.slug});
|
||||
event = TagDeletedEvent.create({
|
||||
id: data.id || data._previousAttributes?.id,
|
||||
slug: data.attributes?.slug || data._previousAttributes?.slug
|
||||
});
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
|
|
@ -192,6 +192,34 @@ describe('ModelToDomainEventInterceptor', function () {
|
|||
interceptedEvent = event;
|
||||
});
|
||||
|
||||
eventRegistry.emit('tag.deleted', {
|
||||
_previousAttributes: {
|
||||
id: '1234-deleted',
|
||||
slug: 'tag-slug'
|
||||
}
|
||||
});
|
||||
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.ok(interceptedEvent);
|
||||
});
|
||||
|
||||
it('Intercepts tag.deleted Model event without an id property and dispatches TagDeletedEvent Domain event', async function () {
|
||||
let eventRegistry = new EventRegistry();
|
||||
const modelToDomainEventInterceptor = new ModelToDomainEventInterceptor({
|
||||
ModelEvents: eventRegistry,
|
||||
DomainEvents: DomainEvents
|
||||
});
|
||||
|
||||
modelToDomainEventInterceptor.init();
|
||||
|
||||
let interceptedEvent;
|
||||
DomainEvents.subscribe(TagDeletedEvent, (event: TagDeletedEvent) => {
|
||||
assert.equal(event.id, '1234-deleted');
|
||||
assert.equal(event.data.slug, 'tag-slug');
|
||||
interceptedEvent = event;
|
||||
});
|
||||
|
||||
eventRegistry.emit('tag.deleted', {
|
||||
id: '1234-deleted',
|
||||
attributes: {
|
||||
|
|
Loading…
Reference in a new issue