From 5cb3b5f4c121e6c438eaa6a3d0090e603a6901c2 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 15 Jun 2023 11:07:31 +0200 Subject: [PATCH] Improve query scoping test --- tests/PostgresRLSTest.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/PostgresRLSTest.php b/tests/PostgresRLSTest.php index f1b53a2b..1f2fcebc 100644 --- a/tests/PostgresRLSTest.php +++ b/tests/PostgresRLSTest.php @@ -176,15 +176,11 @@ test('queries are correctly scoped using RLS', function() { $post1 = RlsPost::create(['text' => 'first post']); $post1Comment = $post1->scoped_comments()->create(['text' => 'first comment']); - tenancy()->end(); - tenancy()->initialize($secondTenant); $post2 = RlsPost::create(['text' => 'second post']); $post2Comment = $post2->scoped_comments()->create(['text' => 'second comment']); - tenancy()->end(); - tenancy()->initialize($tenant); expect(RlsPost::all()->pluck('text')) @@ -197,12 +193,28 @@ test('queries are correctly scoped using RLS', function() { tenancy()->end(); + expect(RlsPost::all()->pluck('text')) + ->toContain($post1->text) + ->toContain($post2->text); + + expect(ScopedComment::all()->pluck('text')) + ->toContain($post1Comment->text) + ->toContain($post2Comment->text); + tenancy()->initialize($secondTenant); expect(RlsPost::all()->pluck('text'))->toContain($post2->text)->not()->toContain($post1->text); expect(ScopedComment::all()->pluck('text'))->toContain($post2Comment->text)->not()->toContain($post1Comment->text); - tenancy()->end(); + tenancy()->initialize($tenant); + + expect(RlsPost::all()->pluck('text')) + ->toContain($post1->text) + ->not()->toContain($post2->text); + + expect(ScopedComment::all()->pluck('text')) + ->toContain($post1Comment->text) + ->not()->toContain($post2Comment->text); }); test('users created by CreatePostgresUserForTenant are only granted the permissions specified in the static property', function() {