Skip to content

Commit

Permalink
BUGFIX: Disallow updating course capacity if the value is not new
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Jun 15, 2023
1 parent 120a5d2 commit c6d8270
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Model/Aggregate/CourseCapacityAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function apply(DomainEvent $domainEvent): void

public function changeCourseCapacity(CourseCapacity $newCapacity): void
{
if ($newCapacity->equals($this->state->courseCapacity)) {
throw new ConstraintException(sprintf('Failed to change capacity of course with id "%s" to %d because that is already the courses capacity', $this->courseId->value, $newCapacity->value), 1686819073);
}
if ($this->state->numberOfSubscriptions > $newCapacity->value) {
throw new ConstraintException(sprintf('Failed to change capacity of course with id "%s" to %d because it already has %d active subscriptions', $this->courseId->value, $newCapacity->value, $this->state->numberOfSubscriptions), 1684604361);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Model/CourseCapacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static function fromInteger(int $value): self
return new self($value);
}

public function equals(self $other): bool
{
return $other->value === $this->value;
}

public function jsonSerialize(): int
{
return $this->value;
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/CourseConstraints.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Feature:
Failed to change capacity of course with id "non-existing" to 3 because a course with that id does not exist
"""

Scenario:
Given course "c1" exists with a capacity of 3
When course "c1" capacity is changed to 3
Then the command should be rejected with the following message:
"""
Failed to change capacity of course with id "c1" to 3 because that is already the courses capacity
"""

Scenario:
Given course "c1" exists with the title "Some Course Title"
When course "c1" is renamed to "Some Course Title"
Expand Down

0 comments on commit c6d8270

Please sign in to comment.