File size: 4,118 Bytes
6773345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php

namespace Tests\Unit;

use App\Domain\Applications\ApplicationService;
use App\Domain\Contracts\ContractService;
use App\Domain\Identity\ClientOnboardingService;
use App\Support\PlatformUrl;
use ReflectionClass;
use Tests\TestCase;

class PlatformUrlTest extends TestCase
{
    public function test_platform_urls_join_paths_without_duplicate_slashes(): void
    {
        config([
            'platform.backend_app_url' => 'https://clientportaldev.qhtestingserver.com/diaspora_nexus_backend',
            'platform.backend_api_base_url' => 'https://clientportaldev.qhtestingserver.com/diaspora_nexus_backend/api/v1',
            'platform.website_url' => 'https://clientportaldev.qhtestingserver.com/diaspora-nexus',
            'platform.admin_portal_url' => 'https://clientportaldev.qhtestingserver.com/admin_portal',
            'platform.client_portal_url' => 'https://clientportaldev.qhtestingserver.com/portal',
        ]);

        $this->assertSame('https://clientportaldev.qhtestingserver.com/diaspora_nexus_backend', PlatformUrl::backendApp());
        $this->assertSame('https://clientportaldev.qhtestingserver.com/diaspora_nexus_backend/api/v1', PlatformUrl::backendApi());
        $this->assertSame('https://clientportaldev.qhtestingserver.com/diaspora-nexus/payment', PlatformUrl::website('/payment'));
        $this->assertSame('https://clientportaldev.qhtestingserver.com/admin_portal/review', PlatformUrl::adminPortal('review'));
        $this->assertSame('https://clientportaldev.qhtestingserver.com/portal/dashboard', PlatformUrl::clientPortal('/dashboard'));
    }

    public function test_contract_signing_url_derives_from_website_url_when_override_is_missing(): void
    {
        config([
            'app.membership_contract_signing_url' => null,
            'platform.website_url' => 'https://clientportaldev.qhtestingserver.com/diaspora-nexus',
        ]);

        $reflection = new ReflectionClass(ContractService::class);
        $service = $reflection->newInstanceWithoutConstructor();
        $method = $reflection->getMethod('membershipContractSigningUrl');
        $method->setAccessible(true);

        $this->assertSame(
            'https://clientportaldev.qhtestingserver.com/diaspora-nexus/contracts/membership?token=contract-token-123',
            $method->invoke($service, 'contract-token-123'),
        );
    }

    public function test_approval_payment_url_derives_from_website_url_when_override_is_missing(): void
    {
        config([
            'app.approval_payment_form_url' => null,
            'platform.website_url' => 'https://clientportaldev.qhtestingserver.com/diaspora-nexus',
        ]);

        $reflection = new ReflectionClass(ApplicationService::class);
        $service = $reflection->newInstanceWithoutConstructor();
        $method = $reflection->getMethod('approvalPaymentUrl');
        $method->setAccessible(true);

        $url = $method->invoke($service, 'approval-token-123');
        $parts = parse_url($url);
        parse_str($parts['query'] ?? '', $query);

        $this->assertSame('https://clientportaldev.qhtestingserver.com/diaspora-nexus/payment', ($parts['scheme'] ?? '').'://'.($parts['host'] ?? '').($parts['path'] ?? ''));
        $this->assertSame('membership_fee', $query['payment_type'] ?? null);
        $this->assertSame('approval-token-123', $query['approval_token'] ?? null);
    }

    public function test_client_setup_url_derives_from_website_url_when_override_is_missing(): void
    {
        config([
            'app.client_portal_setup_url' => null,
            'platform.website_url' => 'https://clientportaldev.qhtestingserver.com/diaspora-nexus',
        ]);

        $reflection = new ReflectionClass(ClientOnboardingService::class);
        $service = $reflection->newInstanceWithoutConstructor();
        $method = $reflection->getMethod('clientSetupUrl');
        $method->setAccessible(true);

        $this->assertSame(
            'https://clientportaldev.qhtestingserver.com/diaspora-nexus/client/setup/setup-token-123',
            $method->invoke($service, 'setup-token-123'),
        );
    }
}