Skip to content

Commit

Permalink
Testing transmission failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
firebed committed Jun 15, 2024
1 parent 5a7ab4a commit 7f5d2ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 20 additions & 4 deletions tests/Http/SendInvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Http;

use Firebed\AadeMyData\Exceptions\MyDataException;
use Firebed\AadeMyData\Exceptions\TransmissionFailedException;
use Firebed\AadeMyData\Factories\ResponseDocXmlFactory;
use Firebed\AadeMyData\Http\MyDataRequest;
use Firebed\AadeMyData\Http\SendInvoices;
Expand Down Expand Up @@ -34,14 +35,14 @@ public function test_dev_provider_url_is_correct()
$sendInvoices = new SendInvoices();
$this->assertEquals('https://mydataapidev.aade.gr/myDataProvider/SendInvoices', $sendInvoices->getUrl());
}

public function test_prod_provider_url_is_correct()
{
MyDataRequest::init('test_user_id', 'test_user_secret', 'prod', true);
$sendInvoices = new SendInvoices();
$this->assertEquals('https://mydatapi.aade.gr/myDataProvider/SendInvoices', $sendInvoices->getUrl());
}
}

/**
* @throws MyDataException
*/
Expand All @@ -59,7 +60,7 @@ public function test_it_sends_single_invoice()

$this->assertCount(1, $responseDoc);
}

/**
* @throws MyDataException
*/
Expand Down Expand Up @@ -126,4 +127,19 @@ public function test_it_sends_a_single_invoice()

$this->assertCount(1, $responseDoc);
}

/**
* @throws MyDataException
*/
public function test_transmission_failure_throws_exception()
{
MyDataRequest::setHandler(new MockHandler([
new HttpResponse(500),
]));

$this->expectException(TransmissionFailedException::class);

$sendInvoices = new SendInvoices();
$sendInvoices->handle(new Invoice());
}
}
6 changes: 3 additions & 3 deletions tests/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function test_invoice_xml()
]
]
]);

$invoice = Invoice::factory()->make();
$this->assertNotEmpty($invoice->toXml());
}
Expand All @@ -54,13 +54,13 @@ public function test_invoice_validation()
$invoice = Invoice::factory()->make();
$this->assertEmpty($invoice->validate());
}

public function test_invoice_validation_fail()
{
$invoice = Invoice::factory()->make();
$invoice->getInvoiceHeader()->setInvoiceType("wrong");
$invoice->getInvoiceSummary()->setTotalGrossValue(-10);

// "wrong" value will be cast to null because InvoiceType enum does
// not have "wrong" value.
// Since null values are stripped from the array, we expect a failure
Expand Down

0 comments on commit 7f5d2ff

Please sign in to comment.