Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Oct 30, 2016
1 parent 903a565 commit 92b25ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,41 @@ public function __construct(DateFactory $dates)
* @return \CachetHQ\Cachet\Models\Schedule
*/
public function handle(CreateScheduleCommand $command)
{
$schedule = Schedule::create($this->filter($command));

event(new ScheduleWasCreatedEvent($schedule));

return $schedule;
}

/**
* Filter the command data.
*
* @param \CachetHQ\Cachet\Bus\Commands\Schedule\CreateScheduleCommand $command
*
* @return array
*/
protected function filter(CreateScheduleCommand $command)
{
$scheduledAt = $this->dates->create('Y-m-d H:i', $command->scheduled_at);

if ($completedAt = $command->completed_at) {
$completedAt = $this->dates->create('Y-m-d H:i', $command->completed_at);
}

$schedule = Schedule::create([
$params = [
'name' => $command->name,
'message' => $command->message,
'status' => $command->status,
'scheduled_at' => $scheduledAt,
'completed_at' => $completedAt,
]);
];

event(new ScheduleWasCreatedEvent($schedule));
$availableParams = array_filter($params, function ($val) {
return $val !== null;
});

return $schedule;
return $availableParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ protected function filter(UpdateScheduleCommand $command)
'status' => $command->status,
];

$params['scheduled_at'] = $this->dates->create('Y-m-d H:i', $command->scheduled_at);
if ($scheduleddAt = $command->scheduled_at) {
$params['scheduled_at'] = $this->dates->create('Y-m-d H:i', $scheduledAt);
}

if ($completedAt = $command->completed_at) {
$params['completed_at'] = $this->dates->create('Y-m-d H:i', $completedAt);
Expand Down
2 changes: 0 additions & 2 deletions app/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class Schedule extends Model implements HasPresenter
'name' => 'required|string',
'message' => 'nullable|string',
'status' => 'required|int|between:0,2',
'scheduled_at' => 'required|date',
'completed_at' => 'nullable|date',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/ScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testCreateSchedule()
'name' => 'Test Schedule',
'message' => 'Foo bar, baz.',
'status' => 1,
'scheduled_at' => strtotime('now'),
'scheduled_at' => date('Y-m-d H:i'),
];

$this->post('/api/v1/schedules/', $schedule);
Expand Down

0 comments on commit 92b25ef

Please sign in to comment.