bulk client creation
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-07-07 16:53:35 +02:00
parent 181ca2b7d4
commit 4afab336ee
7 changed files with 566 additions and 29 deletions

View File

@ -111,4 +111,59 @@ final class ClientsLifecycleTest extends QdbTestCase
$codes = array_column($list['data']['clients'], 'clientCode');
$this->assertNotContains($code, $codes);
}
public function testAdminCreatesClientRange(): void
{
$token = $this->api()->loginWebAndGetToken(
DatabaseSeeder::ADMIN_USERNAME,
DatabaseSeeder::PASSWORD
)['token'];
$prefix = 'RANGE-' . bin2hex(random_bytes(2)) . '-';
$res = $this->api()->withToken($token, 'POST', 'clients', [
'bulk' => true,
'fromCode' => $prefix . '001',
'toCode' => $prefix . '003',
'coachID' => $this->fixture()->coachId,
]);
$this->assertApiOk($res);
$this->assertSame(3, $res['data']['createdCount']);
$this->assertSame(
[$prefix . '001', $prefix . '002', $prefix . '003'],
$res['data']['created'],
);
$list = $this->api()->withToken($token, 'GET', 'clients');
$codes = array_column($list['data']['clients'], 'clientCode');
foreach ([$prefix . '001', $prefix . '002', $prefix . '003'] as $code) {
$this->assertContains($code, $codes);
}
}
public function testBulkCreateSkipsDuplicates(): void
{
$token = $this->api()->loginWebAndGetToken(
DatabaseSeeder::ADMIN_USERNAME,
DatabaseSeeder::PASSWORD
)['token'];
$prefix = 'DUP-' . bin2hex(random_bytes(2)) . '-';
$existing = $prefix . '002';
$single = $this->api()->withToken($token, 'POST', 'clients', [
'clientCode' => $existing,
'coachID' => $this->fixture()->coachId,
]);
$this->assertApiOk($single);
$res = $this->api()->withToken($token, 'POST', 'clients', [
'bulk' => true,
'fromCode' => $prefix . '001',
'toCode' => $prefix . '003',
'coachID' => $this->fixture()->coachId,
]);
$this->assertApiOk($res);
$this->assertSame(2, $res['data']['createdCount']);
$this->assertSame(1, $res['data']['skippedCount']);
$this->assertSame($existing, $res['data']['skipped'][0]['clientCode']);
}
}