Skip to content

Commit

Permalink
Merge pull request 1EdTech#31 from packbackbooks/add-request-logging-…
Browse files Browse the repository at this point in the history
…lti13

PODB-266 Adds logging of a request/response we send/receive when syncing an LTI 1.3 grade
  • Loading branch information
zlayaAvocado authored Oct 28, 2021
2 parents fc2dae1 + 70d5215 commit 68e361b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/LtiServiceConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public function makeServiceRequest(
});
$respBody = $response->getBody();

error_log('Syncing grade for this lti_user_id: '.
json_decode($request->getPayload()['body'])->userId.' '.print_r([
'request_method' => $request->getMethod(),
'request_url' => $request->getUrl(),
'request_body' => $request->getPayload()['body'],
'response_headers' => $respHeaders,
'response_body' => (string) $respBody,
], true));

return [
'headers' => $respHeaders,
'body' => json_decode($respBody, true),
Expand Down
17 changes: 8 additions & 9 deletions tests/LtiServiceConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function setUp(): void
$this->token = 'TokenOfAccess';
$this->method = LtiServiceConnector::METHOD_POST;
$this->url = 'https://example.com';
$this->body = json_encode(['post' => 'body']);
$this->body = json_encode(['userId' => 'id']);
$this->requestHeaders = [
'Authorization' => 'Bearer '.$this->token,
'Accept' => 'application/json',
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testItRetriesServiceRequestOn401Error()
{
$this->method = LtiServiceConnector::METHOD_POST;
$this->url = 'https://example.com';
$this->body = json_encode(['post' => 'body']);
$this->body = json_encode(['userId' => 'id']);
$this->requestHeaders = [
'Authorization' => 'Bearer '.$this->token,
'Accept' => 'application/json',
Expand Down Expand Up @@ -202,7 +202,6 @@ public function testItRetriesServiceRequestOn401Error()
->once()->andReturn($this->responseStatus);

$result = $this->connector->makeServiceRequest($this->registration, $this->scopes, $this->request);

$this->assertEquals($expected, $result);
}

Expand Down Expand Up @@ -288,11 +287,11 @@ public function testItGetsAll()

// Makes two requests, but gets the method and URL once before making the request
$this->request->shouldReceive('getMethod')
->times(3)->andReturn($method);
->times(5)->andReturn($method);
$this->request->shouldReceive('getUrl')
->times(3)->andReturn($this->url);
->times(5)->andReturn($this->url);
$this->request->shouldReceive('getPayload')
->twice()->andReturn($this->requestPayload);
->times(6)->andReturn($this->requestPayload);
// Doesn't find a matching link in on the second header, so only updates the URL once
$this->request->shouldReceive('setUrl')
->once()->andReturn($this->request);
Expand Down Expand Up @@ -321,11 +320,11 @@ private function mockMakeRequest()
{
// It makes another request
$this->request->shouldReceive('getMethod')
->once()->andReturn($this->method);
->andReturn($this->method);
$this->request->shouldReceive('getUrl')
->once()->andReturn($this->url);
->andReturn($this->url);
$this->request->shouldReceive('getPayload')
->once()->andReturn($this->requestPayload);
->andReturn($this->requestPayload);
}

private function mockRequestReturnsA401()
Expand Down

0 comments on commit 68e361b

Please sign in to comment.