87 - Feature Test and JSON Updates

This commit is contained in:
Adam Wathan
2017-03-31 16:20:22 -04:00
parent e0bfaceb20
commit e1867deb43
3 changed files with 20 additions and 8 deletions

View File

@@ -48,8 +48,10 @@ class Order extends Model
return [
'confirmation_number' => $this->confirmation_number,
'email' => $this->email,
'ticket_quantity' => $this->ticketQuantity(),
'amount' => $this->amount,
'tickets' => $this->tickets->map(function ($ticket) {
return ['code' => $ticket->code];
})->all(),
];
}
}

View File

@@ -3,6 +3,7 @@
use App\Concert;
use App\Billing\PaymentGateway;
use App\Billing\FakePaymentGateway;
use App\Facades\OrderConfirmationNumber;
use App\OrderConfirmationNumberGenerator;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
@@ -52,10 +53,7 @@ class PurchaseTicketsTest extends TestCase
{
$this->disableExceptionHandling();
$orderConfirmationNumberGenerator = Mockery::mock(OrderConfirmationNumberGenerator::class, [
'generate' => 'ORDERCONFIRMATION1234',
]);
$this->app->instance(OrderConfirmationNumberGenerator::class, $orderConfirmationNumberGenerator);
OrderConfirmationNumber::shouldReceive('generate')->andReturn('ORDERCONFIRMATION1234');
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250])->addTickets(3);
@@ -70,8 +68,12 @@ class PurchaseTicketsTest extends TestCase
$this->seeJsonSubset([
'confirmation_number' => 'ORDERCONFIRMATION1234',
'email' => 'john@example.com',
'ticket_quantity' => 3,
'amount' => 9750,
'tickets' => [
['code' => 'TICKETCODE1'],
['code' => 'TICKETCODE2'],
['code' => 'TICKETCODE3'],
]
]);
$this->assertEquals(9750, $this->paymentGateway->totalCharges());

View File

@@ -60,15 +60,23 @@ class OrderTest extends TestCase
'email' => 'jane@example.com',
'amount' => 6000,
]);
$order->tickets()->saveMany(factory(Ticket::class)->times(5)->create());
$order->tickets()->saveMany([
factory(Ticket::class)->create(['code' => 'TICKETCODE1']),
factory(Ticket::class)->create(['code' => 'TICKETCODE2']),
factory(Ticket::class)->create(['code' => 'TICKETCODE3']),
]);
$result = $order->toArray();
$this->assertEquals([
'confirmation_number' => 'ORDERCONFIRMATION1234',
'email' => 'jane@example.com',
'ticket_quantity' => 5,
'amount' => 6000,
'tickets' => [
['code' => 'TICKETCODE1'],
['code' => 'TICKETCODE2'],
['code' => 'TICKETCODE3'],
]
], $result);
}
}