Skip to content

Commit

Permalink
PB-24744 As a user performing a Json request, the date time format sh…
Browse files Browse the repository at this point in the history
…ould display the time zone
  • Loading branch information
pabloelcolombiano committed Jun 12, 2023
1 parent e11744b commit c823afc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/bootstrap.php
Expand Up @@ -43,6 +43,7 @@
use Cake\Error\ErrorTrap;
use Cake\Error\ExceptionTrap;
use Cake\Http\ServerRequest;
use Cake\I18n\FrozenTime;
use Cake\Log\Log;
use Cake\Mailer\Mailer;
use Cake\Mailer\TransportFactory;
Expand Down Expand Up @@ -186,6 +187,9 @@
Log::setConfig(Configure::consume('Log'));
Security::setSalt(Configure::consume('Security.salt'));

// Enforce the json time format
FrozenTime::setJsonEncodeFormat("yyyy-MM-dd'T'HH':'mm':'ssxxx");

/*
* Setup detectors for mobile and tablet.
*/
Expand Down
Expand Up @@ -21,6 +21,7 @@
use App\Test\Lib\AppIntegrationTestCase;
use App\Test\Lib\Model\FavoritesModelTrait;
use App\Utility\UuidFactory;
use Cake\I18n\FrozenTime;
use Cake\Utility\Hash;
use PassboltTestData\Lib\PermissionMatrix;

Expand All @@ -39,7 +40,11 @@ public function testResourcesIndexController_Success(): void
$this->getJson('/resources.json?filter=[]');
$this->assertSuccess();
$this->assertGreaterThan(1, count($this->_responseJsonBody));

// Assert that the created date is in the right format
$format = "yyyy-MM-dd'T'HH':'mm':'ssxxx";
$created = $this->_responseJsonBody[0]->created;
$createdParsed = FrozenTime::parse($this->_responseJsonBody[0]->created)->i18nFormat($format);
$this->assertSame($createdParsed, $created, "The created date $created is not in $format format");
// Expected fields.
$this->assertResourceAttributes($this->_responseJsonBody[0]);
// Not expected fields.
Expand Down

0 comments on commit c823afc

Please sign in to comment.