This commit is contained in:
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user