claudiodekker / inertia-laravel-testing

Testing helpers for https://github.com/inertiajs/inertia-laravel
MIT License
134 stars 6 forks source link

Add two_factor_enable to user test? #7

Closed sunscreem closed 4 years ago

sunscreem commented 4 years ago

I'm rapidly falling in love with this package.

Just working through the examples in the readme and this one where you assert againsts a model:

    /** @test */
    public function a_random_test(){

        $user = UserFactory::new()->create(['name' => 'John Doe']);

        $response = $this->actingAs($user)->get(route('dashboard'));

        $response->assertInertiaHas('user',$user);

    }

...fails (with a clean laravel/jetstream install - not using teams)

Maybe Laravel added the two_factor_enable recently or I need to tweak my user model?

1) Tests\Feature\OrganisationsTest::a_random_test
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'created_at' => '2020-10-17T18:07:55.000000Z'
     'id' => 1
     'profile_photo_url' => 'https://ui-avatars.com/api/?n...EBF4FF'
+    'two_factor_enabled' => false
 )
claudiodekker commented 4 years ago

Hi,

Yes, this is because Jetstream uses Inertia::share to share the user to Inertia globally, during which it adds the two_factor_enabled key: ShareInertiaData.php#L45-L49

My recommendation would be to basically what Jetstream does there, by manually doing ->toArray(), followed by manually merging in the key just before asserting so that the outcome is identical.

Hope this helps!

sunscreem commented 4 years ago

Perfect! As you can still trying to wrap about whats inertia.js and what's Jetstream!