File: /home/xedaptot/be.naniguide.com/tests/Feature/SendingServerFeatureTest.php
<?php
/**
* SendingServer model feature tests.
*
* Tests server types, status constants, and quota configuration.
*/
use App\Model\SendingServer;
uses(Tests\TestCase::class);
test('sending server status constants are defined', function () {
expect(SendingServer::STATUS_ACTIVE)->toBe('active');
expect(SendingServer::STATUS_INACTIVE)->toBe('inactive');
});
test('sending server model accepts smtp attributes', function () {
$server = new SendingServer([
'name' => 'Office SMTP',
'type' => 'smtp',
'host' => 'smtp.office365.com',
'smtp_port' => '587',
'smtp_protocol' => 'tls',
'smtp_username' => '[email protected]',
'smtp_password' => 'password123',
'status' => SendingServer::STATUS_ACTIVE,
'quota_value' => 500,
'quota_base' => 1,
'quota_unit' => 'hour',
]);
expect($server->name)->toBe('Office SMTP');
expect($server->type)->toBe('smtp');
expect($server->host)->toBe('smtp.office365.com');
expect($server->status)->toBe(SendingServer::STATUS_ACTIVE);
});
test('sending server has required fillable fields', function () {
$server = new SendingServer();
$fillable = $server->getFillable();
expect($fillable)->toContain('name');
expect($fillable)->toContain('type');
expect($fillable)->toContain('quota_value');
expect($fillable)->toContain('config');
});
test('sending server vendor credentials route through JSON config (driver pattern)', function () {
// Driver-architecture: vendor keys (host, smtp_*, api_key, etc) live in
// the JSON `config` column, not in fillable. fill() override routes them
// via SendingServer::VENDOR_CONFIG_KEYS → setConfig().
$server = new SendingServer();
$server->fill([
'name' => 'Office SMTP',
'type' => 'smtp',
'host' => 'smtp.office365.com',
'smtp_username' => '[email protected]',
]);
expect($server->name)->toBe('Office SMTP');
expect($server->type)->toBe('smtp');
expect($server->getConfig('host'))->toBe('smtp.office365.com');
expect($server->getConfig('smtp_username'))->toBe('[email protected]');
// Backwards-compat: getAttribute() falls back to JSON config for vendor keys.
expect($server->host)->toBe('smtp.office365.com');
expect($server->smtp_username)->toBe('[email protected]');
});
test('SendingServer::VENDOR_CONFIG_KEYS contains all 16 vendor credentials', function () {
expect(SendingServer::VENDOR_CONFIG_KEYS)
->toContain('api_key')
->toContain('api_secret_key')
->toContain('host')
->toContain('domain')
->toContain('username')
->toContain('smtp_username')
->toContain('smtp_password')
->toContain('smtp_port')
->toContain('smtp_protocol')
->toContain('aws_access_key_id')
->toContain('aws_secret_access_key')
->toContain('aws_region')
->toContain('sendmail_path')
->toContain('oauth_access_token')
->toContain('oauth_refresh_token')
->toContain('oauth_token_expires_at');
});