Skip to content

Commit 14b4e18

Browse files
committed
Add test for upsert with tenant per doc
1 parent 27c442c commit 14b4e18

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/e2e/Adapter/Base.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16523,6 +16523,62 @@ public function testSharedTablesTenantPerDocument(): void
1652316523
$this->assertEquals(1, \count($docs));
1652416524
$this->assertEquals($doc1Id, $docs[0]->getId());
1652516525

16526+
// Test upsert with tenant per doc
16527+
$doc3Id = ID::unique();
16528+
$database
16529+
->setTenant(null)
16530+
->setTenantPerDocument(true)
16531+
->createOrUpdateDocuments(__FUNCTION__, [new Document([
16532+
'$id' => $doc3Id,
16533+
'$tenant' => 3,
16534+
'name' => 'Superman',
16535+
])]);
16536+
16537+
// Set to tenant 1 and read
16538+
$doc = $database
16539+
->setTenantPerDocument(false)
16540+
->setTenant(3)
16541+
->getDocument(__FUNCTION__, $doc3Id);
16542+
16543+
$this->assertEquals('Superman', $doc['name']);
16544+
$this->assertEquals(3, $doc->getTenant());
16545+
$this->assertEquals($doc3Id, $doc->getId());
16546+
16547+
// Test no read from other tenants
16548+
$docs = $database
16549+
->setTenantPerDocument(false)
16550+
->setTenant(1)
16551+
->find(__FUNCTION__);
16552+
16553+
$this->assertEquals(1, \count($docs));
16554+
16555+
// Ensure no cross-tenant upsert
16556+
try {
16557+
$database
16558+
->setTenant(null)
16559+
->setTenantPerDocument(true)
16560+
->createOrUpdateDocuments(__FUNCTION__, [new Document([
16561+
'$id' => $doc3Id,
16562+
'$tenant' => 1,
16563+
'name' => 'Superman updated',
16564+
])]);
16565+
16566+
$this->fail('Expected to throw for cross-tenant upsert');
16567+
} catch (\Throwable) {
16568+
// Expected
16569+
}
16570+
16571+
// Ensure no cross-tenant read from upsert
16572+
try {
16573+
$database
16574+
->setTenant(1)
16575+
->setTenantPerDocument(false)
16576+
->getDocument(__FUNCTION__, $doc3Id);
16577+
$this->fail('Expected to throw for cross-tenant read');
16578+
} catch (\Throwable) {
16579+
// Expected
16580+
}
16581+
1652616582
// Reset instance
1652716583
$database
1652816584
->setSharedTables($sharedTables)

0 commit comments

Comments
 (0)