-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from Sysix/dunnings
add dunnings endpoint
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sysix\LexOffice\Clients; | ||
|
||
use Sysix\LexOffice\BaseClient; | ||
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait; | ||
use Sysix\LexOffice\Clients\Traits\GetTrait; | ||
use Sysix\LexOffice\Clients\Traits\PursueTrait; | ||
|
||
class Dunning extends BaseClient | ||
{ | ||
use DocumentClientTrait; | ||
use GetTrait; | ||
use PursueTrait; | ||
|
||
protected string $resource = 'dunnings'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sysix\LexOffice\Tests\Clients; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Sysix\LexOffice\Clients\Dunning; | ||
use Sysix\LexOffice\Tests\TestClient; | ||
|
||
class DunningTest extends TestClient | ||
{ | ||
public function testGet(): void | ||
{ | ||
[$api, $stub] = $this->createClientMockObject(Dunning::class); | ||
|
||
$response = $stub->get('resource-id'); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
|
||
$this->assertEquals('GET', $api->getRequest()->getMethod()); | ||
$this->assertEquals( | ||
$api->apiUrl . '/v1/dunnings/resource-id', | ||
$api->getRequest()->getUri()->__toString() | ||
); | ||
} | ||
|
||
public function testPursue(): void | ||
{ | ||
[$api, $stub] = $this->createClientMockObject(Dunning::class); | ||
|
||
$response = $stub->pursue('resource-id', [ | ||
'version' => 0 | ||
]); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
|
||
$this->assertEquals('POST', $api->getRequest()->getMethod()); | ||
$this->assertEquals( | ||
$api->apiUrl . '/v1/dunnings?precedingSalesVoucherId=resource-id', | ||
$api->getRequest()->getUri()->__toString() | ||
); | ||
} | ||
|
||
public function testDocument(): void | ||
{ | ||
[$api, $stub] = $this->createClientMockObject(Dunning::class); | ||
|
||
$response = $stub->document('resource-id'); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
|
||
$this->assertEquals('GET', $api->getRequest()->getMethod()); | ||
$this->assertEquals( | ||
$api->apiUrl . '/v1/dunnings/resource-id/document', | ||
$api->getRequest()->getUri()->__toString() | ||
); | ||
} | ||
|
||
public function testDocumentContent(): void | ||
{ | ||
[$api, $stub] = $this->createClientMultiMockObject( | ||
Dunning::class, | ||
[ | ||
new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), | ||
new Response() | ||
] | ||
); | ||
|
||
$response = $stub->document('resource-id', true); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
|
||
$this->assertEquals('GET', $api->getRequest()->getMethod()); | ||
$this->assertEquals( | ||
$api->apiUrl . '/v1/files/fake-id', | ||
$api->getRequest()->getUri()->__toString() | ||
); | ||
} | ||
|
||
public function testFailedDocumentContent(): void | ||
{ | ||
[$api, $stub] = $this->createClientMultiMockObject( | ||
Dunning::class, | ||
[ | ||
new Response(500), | ||
new Response() | ||
] | ||
); | ||
|
||
$response = $stub->document('resource-id', true); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $response); | ||
$this->assertEquals(500, $response->getStatusCode()); | ||
} | ||
} |