1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00

Improve query scoping test

This commit is contained in:
lukinovec 2023-06-15 11:07:31 +02:00
parent e8b3c23c72
commit 5cb3b5f4c1

View file

@ -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() {