How does the ReturnsRequest factory look? Also is that assert 1 or two that fails?
Nov 20, 2019
8
Level 33
Failing Test and I am Lost
Am I doing something wrong here?
I can't figure out WHY this test is failing. (I still have SO MUCH to learn about testing)
/** @test */
public function user_can_update_return_admin_notes () {
$user = factory(User::class)->create();
$rma = factory(ReturnsRequest::class)->create([
'initiator_id' => 1,
'company_name' => 'Fruit Loops',
'description' => 'Fruity breakfast cereal'
]);
$this->assertDatabaseHas('returns_requests', [
'initiator_id' => 1,
'company_name' => 'Fruit Loops',
'description' => 'Fruity breakfast cereal'
]);
$this->actingAs($user)
->patchJson('/api/returns/update_rma/' . $rma->id, [
'admin_notes' => 'This is a note for this RMA.'
]);
$this->assertDatabaseHas('returns_requests', [
'initiator_id' => 1,
'company_name' => 'Fruit Loops',
'description' => 'Fruity breakfast cereal',
'admin_notes' => 'This is a note for this RMA.'
]);
} // end test
That api route hits this controller method:
public function update_rma($id)
{
$arrUpdate = [
'status_id' => request('status_id'),
'initiator_id' => request('initiator_id'),
'rma_number' => request('rma_number'),
'has_other_fee' => request('has_other_fee'),
'restocking_fee' => request('restocking_fee'),
'exposure' => request('exposure'),
'credit_memo_amount' => request('credit_memo_amount'),
'restocking_fee_amount' => request('restocking_fee_amount'),
'other_fee_amount' => request('other_fee_amount'),
'adjusted_amount' => request('adjusted_amount'),
'repair_cost_quote' => request('repair_cost_quote'),
'contact' => request('contact'),
'email' => request('email'),
'other_fee_description' => request('other_fee_description'),
'responsible_for_shipping' => request('responsible_for_shipping'),
'rma_date' => request('rma_date'),
'admin_notes' => request('admin_notes'),
'description' => request('description'),
'rma_explanation' => request('rma_explanation'),
];
$rma = ReturnsRequest::with('reasons')->whereId($id)->first();
$rma->update($arrUpdate);
return new ReturnsResource($rma);
} // end function
but I get this in testing
There was 1 failure:
1) Tests\Feature\Http\Controllers\ReturnsControllerTest::user_can_update_return_admin_notes
Failed asserting that a row in the table [returns_requests] matches the attributes {
"initiator_id": 1,
"company_name": "Fruit Loops",
"description": "Fruity breakfast cereal",
"admin_notes": "This is a note for this RMA."
}.
Found: [
{
"id": "1",
"status_id": "1",
"initiator_id": "1",
"rma_number": "830809",
"has_other_fee": "0",
"restocking_fee": "1",
"exposure": "15.101828524",
"credit_memo_amount": "7.468288",
"restocking_fee_amount": "7.24514821",
"other_fee_amount": "10.5147019",
"adjusted_amount": "44206.24723654",
"repair_cost_quote": "5221.10429",
"contact": "Danika Mueller",
"email": "[email protected]",
"other_fee_description": "exercitationem",
"responsible_for_shipping": "nihil",
"rma_date": "2011-11-30",
"admin_notes": "Quisquam nihil ex sed odit rerum dolor. Quo optio dolorem temporibus. Est nihil dolor consequatur totam facilis illum aut.",
"description": "Fruity breakfast cereal",
"rma_explanation": "Aut soluta laudantium et sunt numquam eligendi harum. At id beatae consequatur. Fuga vitae rerum delectus qui ea porro nesciunt fugiat.",
"created_at": "2019-11-20 17:48:14",
"updated_at": "2019-11-20 17:48:14"
}
].
/Users/jgravois/code/my-uam/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php:25
/Users/jgravois/code/my-uam/tests/Feature/Http/Controllers/ReturnsControllerTest.php:35
Level 51
Well, first of all, it looks like you don't have a company_name field within your returns_requests table, so the test will fail against that.
As for the admin_notes not being updated, are you certain it's actually hitting that method on your controller? Could middleware be intercepting it? Add a dd() and make sure the method is actually being called, or inspect the response:
dd($this->actingAs($user)
->patchJson('/api/returns/update_rma/' . $rma->id, [
'admin_notes' => 'This is a note for this RMA.'
]));
Please or to participate in this conversation.