Skip to content

Formalise concept of state-change rules within aggregate #60

Description

@rhyslbw

A common business rule is to only allow a state change if the current state is equal to or is not equal to a single or group of values. It's currently tedious to protect against this, and as such I suspect may be just left out of testing or forgotten in the command handler.

Now

Donations.domain.test(Donations.Appeal)
  .given(closedAppeal.call(this))
  .when(
    new Donations.MakeAppeal({ targetId: this.appealId })
  )
  .expect([
    new Space.domain.Exception({
      thrower: 'Donations.Appeal',
      error: new Donations.InvalidAppealState('MakeAppeal', 'closed')
    })
  ]);

I suggest we take the focus of the message type ( commandMap and eventMap), and work on a pipeline for external state-change messages stateChangeMap? Mapping to a handler would be part of this, but only after enforcing state change rules as defined. It could throw a generic Space.Error like InvalidState.

As part of this we will need to abstract the mapping of internal state-change events into fields rather than just mapping an event type to a handler. This will be easier to test, and ensure dependencies are not being used to manipulate data once saved

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions