Skip to content

Commit

Permalink
Merge pull request #47 from packbackbooks/lti-add-get-delete
Browse files Browse the repository at this point in the history
PODB-411: Add getLineItem to library
  • Loading branch information
JonahL authored Feb 1, 2022
2 parents 527563b + 043fb4a commit 9de4796
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/LtiAssignmentsGradesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ public function getLineItems(): array
return $lineitems;
}

public function getLineItem(string $url): LtiLineitem
{
if (!in_array(LtiConstants::AGS_SCOPE_LINEITEM, $this->getScope())) {
throw new LtiException('Missing required scope', 1);
}

$request = new ServiceRequest(LtiServiceConnector::METHOD_GET, $url);
$request->setAccept(static::CONTENTTYPE_LINEITEM);

$response = $this->makeServiceRequest($request)['body'];

return new LtiLineitem($response);
}

private function ensureLineItemExists(LtiLineitem $lineitem = null): LtiLineitem
{
// If no line item is passed in, attempt to use the one associated with
Expand Down
28 changes: 28 additions & 0 deletions tests/LtiAssignmentsGradesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Packback\Lti1p3\Interfaces\ILtiRegistration;
use Packback\Lti1p3\Interfaces\ILtiServiceConnector;
use Packback\Lti1p3\LtiAssignmentsGradesService;
use Packback\Lti1p3\LtiConstants;
use Packback\Lti1p3\LtiLineitem;

class LtiAssignmentsGradesServiceTest extends TestCase
{
Expand All @@ -22,6 +24,32 @@ public function testItInstantiates()
$this->assertInstanceOf(LtiAssignmentsGradesService::class, $service);
}

public function testItGetsSingleLineItem()
{
$ltiLineitemData = [
'id' => 'testId',
];

$serviceData = [
'scope' => [LtiConstants::AGS_SCOPE_LINEITEM],
];

$service = new LtiAssignmentsGradesService($this->connector, $this->registration, $serviceData);

$response = [
'body' => $ltiLineitemData,
];

$this->connector->shouldReceive('makeServiceRequest')
->once()->andReturn($response);

$expected = new LtiLineitem($ltiLineitemData);

$result = $service->getLineItem('someUrl');

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

/*
* @todo Test this
*/
Expand Down

0 comments on commit 9de4796

Please sign in to comment.