mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 04:54:03 +00:00
Improve query scoping test
This commit is contained in:
parent
e8b3c23c72
commit
5cb3b5f4c1
1 changed files with 17 additions and 5 deletions
|
|
@ -176,15 +176,11 @@ test('queries are correctly scoped using RLS', function() {
|
||||||
$post1 = RlsPost::create(['text' => 'first post']);
|
$post1 = RlsPost::create(['text' => 'first post']);
|
||||||
$post1Comment = $post1->scoped_comments()->create(['text' => 'first comment']);
|
$post1Comment = $post1->scoped_comments()->create(['text' => 'first comment']);
|
||||||
|
|
||||||
tenancy()->end();
|
|
||||||
|
|
||||||
tenancy()->initialize($secondTenant);
|
tenancy()->initialize($secondTenant);
|
||||||
|
|
||||||
$post2 = RlsPost::create(['text' => 'second post']);
|
$post2 = RlsPost::create(['text' => 'second post']);
|
||||||
$post2Comment = $post2->scoped_comments()->create(['text' => 'second comment']);
|
$post2Comment = $post2->scoped_comments()->create(['text' => 'second comment']);
|
||||||
|
|
||||||
tenancy()->end();
|
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
expect(RlsPost::all()->pluck('text'))
|
expect(RlsPost::all()->pluck('text'))
|
||||||
|
|
@ -197,12 +193,28 @@ test('queries are correctly scoped using RLS', function() {
|
||||||
|
|
||||||
tenancy()->end();
|
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);
|
tenancy()->initialize($secondTenant);
|
||||||
|
|
||||||
expect(RlsPost::all()->pluck('text'))->toContain($post2->text)->not()->toContain($post1->text);
|
expect(RlsPost::all()->pluck('text'))->toContain($post2->text)->not()->toContain($post1->text);
|
||||||
expect(ScopedComment::all()->pluck('text'))->toContain($post2Comment->text)->not()->toContain($post1Comment->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() {
|
test('users created by CreatePostgresUserForTenant are only granted the permissions specified in the static property', function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue