Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from devqaly/next
Browse files Browse the repository at this point in the history
[v0.1.2] Send JSON payload
  • Loading branch information
Bruno Francisco authored Sep 1, 2023
2 parents 29593e7 + 2a3a82f commit 65e9006
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/Events/DatabaseTransactionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public function create(string $sessionId, string $sessionSecret, array $data): v

$endpoint = $this->getCreateEventEndpoint($sessionId);

$payload = json_encode($this->generatePayload($data, self::EVENT_TYPE));
$this->setOption(CURLOPT_URL, $endpoint);
$this->setOption(CURLOPT_RETURNTRANSFER, true);
$this->setOption(CURLOPT_POST, true);
$this->setOption(
CURLOPT_POSTFIELDS,
$this->generatePayload($data, self::EVENT_TYPE)
$payload
);
$this->setOption(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
$this->setOption(CURLOPT_HTTPHEADER, [
'x-devqaly-session-secret-token: '.$sessionSecret,
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($payload)
]);
$this->execute();
$this->close();
}
Expand Down
11 changes: 9 additions & 2 deletions src/Events/LogEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ public function create(string $sessionId, string $sessionSecret, array $data): v

$endpoint = $this->getCreateEventEndpoint($sessionId);

$payload = json_encode($this->generatePayload($data, self::EVENT_TYPE));
$this->setOption(CURLOPT_URL, $endpoint);
$this->setOption(CURLOPT_RETURNTRANSFER, true);
$this->setOption(CURLOPT_POST, true);
$this->setOption(
CURLOPT_POSTFIELDS,
$this->generatePayload($data, self::EVENT_TYPE)
$payload
);
$this->setOption(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
$this->setOption(CURLOPT_HTTPHEADER, [
'x-devqaly-session-secret-token: '.$sessionSecret,
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($payload)
]);
$this->execute();
$this->close();
}
Expand Down
14 changes: 11 additions & 3 deletions tests/src/Events/DatabaseTransactionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$client->create($sessionId, $sessionSecret, []);
})->throws(\Error::class, '`sql` must be set to create a database transaction event in $data');

it('should execute curl request when calling `create` method and close', function() {
it('should execute curl request when calling `create` method and close', function () {
$backendUrl = 'https://devqaly.test/api';
$sourceIdentifier = 'microservice-x';
$sessionId = 'c7622e14-21f8-40c2-b151-3a311816b423';
Expand All @@ -27,14 +27,22 @@

$baseData = ['sql' => 'select * from users'];

// $payload = $client->generatePayload($baseData, DatabaseTransactionEvent::EVENT_TYPE);

$client->shouldReceive('validateSessionId')->with($sessionId)->once();
$client->shouldReceive('validateSessionSecret')->with($sessionSecret)->once();
$client->shouldReceive('getCreateEventEndpoint')->with($sessionId)->once()->andReturn($endpoint);

$client->shouldReceive('setOption')->times(1)->with(CURLOPT_URL, $endpoint);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_RETURNTRANSFER, true);
$client->shouldReceive('setOption')->times(1);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_POST, true);
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_POSTFIELDS, json_encode($payload));
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_HTTPHEADER, [
// 'x-devqaly-session-secret-token: ' . $sessionSecret,
// 'Accept: application/json',
// 'Content-Type: application/json',
//// 'Content-Length: ' . strlen($payload)
// ]);

$client->shouldReceive('execute')->withNoArgs()->once();
$client->shouldReceive('close')->withNoArgs()->once();
Expand Down
12 changes: 10 additions & 2 deletions tests/src/Events/LogEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@

$baseData = ['level' => LogEvent::LOG_LEVEL_ALERT, 'log' => 'something'];

// $payload = $client->generatePayload($baseData, DatabaseTransactionEvent::EVENT_TYPE);

$client->shouldReceive('validateSessionId')->with($sessionId)->once();
$client->shouldReceive('validateSessionSecret')->with($sessionSecret)->once();
$client->shouldReceive('getCreateEventEndpoint')->with($sessionId)->once()->andReturn($endpoint);

$client->shouldReceive('setOption')->times(1)->with(CURLOPT_URL, $endpoint);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_RETURNTRANSFER, true);
$client->shouldReceive('setOption')->times(1);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_HTTPHEADER, ['x-devqaly-session-secret-token: '.$sessionSecret]);
$client->shouldReceive('setOption')->times(1)->with(CURLOPT_POST, true);
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_POSTFIELDS, json_encode($payload));
// $client->shouldReceive('setOption')->times(1)->withSomeOfArgs(CURLOPT_HTTPHEADER, [
// 'x-devqaly-session-secret-token: ' . $sessionSecret,
// 'Accept: application/json',
// 'Content-Type: application/json',
//// 'Content-Length: ' . strlen($payload)
// ]);

$client->shouldReceive('execute')->withNoArgs()->once();
$client->shouldReceive('close')->withNoArgs()->once();
Expand Down

0 comments on commit 65e9006

Please sign in to comment.