Skip to content

Commit

Permalink
Merge pull request #14 from andrei-ghenov/feature/T-005-api-client-test
Browse files Browse the repository at this point in the history
T-005: Generate the timestamp in the specified format and ensure it's in GMT/UTC
  • Loading branch information
andrei-ghenov authored Mar 3, 2024
2 parents 07ca15a + b19a831 commit a6de9bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/Api/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function sendRequest(
string $endpoint,
array $data = []
): mixed {
$dateTime = new DateTime('now', new DateTimeZone('America/New_York'));
$timestamp = $dateTime->format('c');
// Generate the timestamp in the specified format and ensure it's in GMT/UTC
$timestamp = gmdate('Y-m-d\TH:i:s');
$authKey = $this->generateAuthHmac($timestamp, $this->apiSecurityKey);
$hashedPassword = $this->generateAuthHmac($this->apiPassword, $authKey);

Expand All @@ -88,7 +88,6 @@ public function sendRequest(
'User' => $this->apiUser,
'Password' => $hashedPassword,
], $data);

try {
$response = $this->client->request($method, $endpoint, [
'json' => $data,
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function testWSLoginSuccess() {

// Use PHPUnit assertions to check for successful login
// Display the response for debugging purposes
// (usually done during development only)
// (usually done during development only).
echo "Response: ";
var_dump($response);

// Assert the response indicates a successful login
// Assert the response indicates a successful login.
$this->assertArrayHasKey(
'AccessCode', $response, "Response does not contain AccessCode"
);
Expand All @@ -48,7 +48,7 @@ public function testWSLoginSuccess() {
// In production or CI environments, it might be better to log this error
// or handle it accordingly.
echo "Error during WSLogin request: ".$e->getMessage();
// Fail the test if an exception is caught
// Fail the test if an exception is caught.
$this->fail(
"WSLogin request failed with an exception: ".$e->getMessage()
);
Expand All @@ -66,7 +66,7 @@ public function testWSLoginFailure() {
'Password' => 'incorrectPassword',
]);

// Debugging output (use sparingly)
// Debugging output (use sparingly).
echo "Response: ";
var_dump($response);

Expand Down

0 comments on commit a6de9bb

Please sign in to comment.