d1a4c28dc1
ClientSmsController (index/preview/store/show, база контактов, шаблоны; tenant по $request->user()->tenant_id + явный where; 409 при нехватке денег, freeze при создании). AdminSmsTariffController (правка ступеней и настроек, зона saas-admin/admin-db, crm_admin_user). Маршруты /api/sms и /api/admin/sms. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
use App\Models\ClientSmsSettings;
|
||
use App\Models\ClientSmsTariff;
|
||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
||
uses(DatabaseTransactions::class);
|
||
|
||
/**
|
||
* Task 8: SaaS-admin «Клиентские СМС» — тарифная сетка (client_sms_tariffs)
|
||
* и общие настройки (client_sms_settings, singleton).
|
||
*
|
||
* Сидированы миграциями: 5 ступеней (1/9.00, 100/8.50, 250/8.30, 500/8.10,
|
||
* 1000/8.00) + settings (fee 2500.00, grace 29 дней).
|
||
*/
|
||
test('GET /api/admin/sms/tariffs возвращает сидированные ступени и настройки', function () {
|
||
$r = $this->getJson('/api/admin/sms/tariffs');
|
||
$r->assertStatus(200);
|
||
|
||
$tariffs = $r->json('tariffs');
|
||
expect($tariffs)->toHaveCount(5);
|
||
expect(collect($tariffs)->pluck('min_qty')->all())->toBe([1, 100, 250, 500, 1000]);
|
||
expect($tariffs[0]['price_rub'])->toBe('9.00');
|
||
|
||
expect($r->json('settings.name_fee_rub_per_operator'))->toBe('2500.00');
|
||
expect($r->json('settings.name_debt_grace_days'))->toBe(29);
|
||
});
|
||
|
||
test('PUT /api/admin/sms/tariffs заменяет весь набор ступеней', function () {
|
||
$r = $this->putJson('/api/admin/sms/tariffs', [
|
||
'rows' => [
|
||
['min_qty' => 1, 'price_rub' => '10.00'],
|
||
['min_qty' => 500, 'price_rub' => '7.50'],
|
||
],
|
||
]);
|
||
|
||
$r->assertStatus(200);
|
||
|
||
expect(ClientSmsTariff::count())->toBe(2);
|
||
|
||
$rows = ClientSmsTariff::orderBy('min_qty')->get();
|
||
expect($rows[0]->min_qty)->toBe(1);
|
||
expect($rows[0]->price_rub)->toBe('10.00');
|
||
expect($rows[1]->min_qty)->toBe(500);
|
||
expect($rows[1]->price_rub)->toBe('7.50');
|
||
|
||
$responseTariffs = $r->json('tariffs');
|
||
expect($responseTariffs)->toHaveCount(2);
|
||
expect(collect($responseTariffs)->pluck('min_qty')->all())->toBe([1, 500]);
|
||
});
|
||
|
||
test('PUT /api/admin/sms/settings обновляет singleton настроек', function () {
|
||
$r = $this->putJson('/api/admin/sms/settings', [
|
||
'name_fee_rub_per_operator' => '3000.00',
|
||
'name_debt_grace_days' => 14,
|
||
]);
|
||
|
||
$r->assertStatus(200);
|
||
expect($r->json('name_fee_rub_per_operator'))->toBe('3000.00');
|
||
expect($r->json('name_debt_grace_days'))->toBe(14);
|
||
|
||
$settings = ClientSmsSettings::first();
|
||
expect($settings->name_fee_rub_per_operator)->toBe('3000.00');
|
||
expect($settings->name_debt_grace_days)->toBe(14);
|
||
});
|
||
|
||
test('PUT /api/admin/sms/tariffs с некорректной ступенью → 422', function () {
|
||
$r = $this->putJson('/api/admin/sms/tariffs', [
|
||
'rows' => [
|
||
['min_qty' => 0, 'price_rub' => '10.00'],
|
||
],
|
||
]);
|
||
$r->assertStatus(422);
|
||
|
||
$r2 = $this->putJson('/api/admin/sms/tariffs', [
|
||
'rows' => [
|
||
['min_qty' => 1, 'price_rub' => '0.00'],
|
||
],
|
||
]);
|
||
$r2->assertStatus(422);
|
||
|
||
// Исходные 5 ступеней не тронуты.
|
||
expect(ClientSmsTariff::count())->toBe(5);
|
||
});
|