Skip to content

Commit

Permalink
test: add format column fallback response
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed Oct 2, 2023
1 parent 035cc97 commit 0cc4bbd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/Integration/EloquentDataTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ public function it_can_return_formatted_column_using_closure()
$this->assertEquals(Carbon::parse($user->created_at)->format('Y-m-d'), $data['created_at_formatted']);
}

/** @test */
public function it_can_return_formatted_column_on_invalid_formatter()
{
$crawler = $this->call('GET', '/eloquent/formatColumn-fallback');

$crawler->assertJson([
'draw' => 0,
'recordsTotal' => 20,
'recordsFiltered' => 20,
]);

$user = User::find(1);
$data = $crawler->json('data')[0];

$this->assertTrue(isset($data['created_at']));
$this->assertTrue(isset($data['created_at_formatted']));

$this->assertEquals($user->created_at, $data['created_at_formatted']);
}

/** @test */
public function it_accepts_a_relation()
{
Expand Down Expand Up @@ -177,5 +197,11 @@ protected function setUp(): void
->formatColumn('created_at', fn($value, $row) => Carbon::parse($value)->format('Y-m-d'))
->toJson();
});

$router->get('/eloquent/formatColumn-fallback', function (DataTables $dataTable) {
return $dataTable->eloquent(User::query())
->formatColumn('created_at', 'InvalidFormatter::class')
->toJson();
});
}
}

0 comments on commit 0cc4bbd

Please sign in to comment.