This repository has been archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced legacy MissionDaysCalculator with new ones
- Loading branch information
Showing
5 changed files
with
81 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Services\Calculator\MissionDaysCalculator; | ||
use Carbon\Carbon; | ||
use Illuminate\Http\Request; | ||
|
||
class MissionDayController extends Controller | ||
{ | ||
public function eligibleDays(Request $request) | ||
{ | ||
$validatedData = $this->validate($request, [ | ||
'end' => 'required|date', | ||
'start' => 'required|date' | ||
]); | ||
|
||
$carbonizedStart = Carbon::parse($validatedData['start']); | ||
$carbonizedEnd = Carbon::parse($validatedData['end']); | ||
|
||
return MissionDaysCalculator::calculateEligibleDays($carbonizedStart, $carbonizedEnd); | ||
} | ||
|
||
public function possibleEndDate(Request $request) | ||
{ | ||
$validatedData = $this->validate($request, [ | ||
'days' => 'required|integer', | ||
'start' => 'required|date' | ||
]); | ||
|
||
$carbonizedStart = Carbon::parse($validatedData['start']); | ||
|
||
return MissionDaysCalculator::calculatePossibleEndDate($carbonizedStart, $validatedData['days'])->format('Y-m-d'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Tests\Integration; | ||
|
||
class MissionDayControllerTest extends \TestCase | ||
{ | ||
public function testInvalidEligibleDays() | ||
{ | ||
$this->asUser()->json('GET', 'api/mission_days/eligible_days')->assertResponseStatus(422); | ||
} | ||
|
||
public function testValidEligibleDays() | ||
{ | ||
$this->asUser()->json('GET', 'api/mission_days/eligible_days', [ | ||
'start' => '2019-01-01', | ||
'end' => '2019-01-31' | ||
])->assertResponseOk(); | ||
|
||
$this->assertEquals(31, $this->response->getContent()); | ||
} | ||
|
||
public function testInvalidEndDate() | ||
{ | ||
$this->asUser()->json('GET', 'api/mission_days/possible_end_date')->assertResponseStatus(422); | ||
} | ||
|
||
public function testValidEndDate() | ||
{ | ||
$this->asUser()->json('GET', 'api/mission_days/possible_end_date', [ | ||
'start' => '2019-01-01', | ||
'days' => '31' | ||
])->assertResponseOk(); | ||
|
||
$this->assertEquals('2019-01-31', $this->response->getContent()); | ||
} | ||
} |