297 lines
13 KiB
PHP
297 lines
13 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Business;
|
||
|
||
use App\Models\Auth\Permission;
|
||
use App\Models\Business\CourierAgreementSignature;
|
||
use App\Services\Esign\EsignClient;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||
use Tests\Feature\FeatureTestCase;
|
||
|
||
class AgreementSigningPageTest extends FeatureTestCase
|
||
{
|
||
protected function grantWorkspaceAccess(): void
|
||
{
|
||
$this->user->attachPermission(
|
||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||
);
|
||
}
|
||
|
||
public function testAgreementSigningPageRendersTheSigningWorkspace(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
]))
|
||
->assertOk()
|
||
->assertSeeText('协议签署')
|
||
->assertSeeText('签署任务')
|
||
->assertSeeText('发起签章')
|
||
->assertSeeText('模板管理')
|
||
->assertSeeText(EsignClient::configured() ? 'E签宝已连接' : 'E签宝未连接')
|
||
->assertSeeText('还没有协议签署任务')
|
||
->assertSeeText('收款账户变更证明.doc')
|
||
->assertSeeText('收款账户证明文件.doc')
|
||
->assertSeeText('公司主体变更证明.docx')
|
||
->assertSeeText('共用合同证明.docx')
|
||
->assertSeeText('授权委托书(快递).docx');
|
||
}
|
||
|
||
public function testAgreementSigningPageIncludesSinglePageRequestFormAndLivePreview(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
'agreement_view' => 'create',
|
||
]))
|
||
->assertOk()
|
||
->assertSee('data-signing-request-form', false)
|
||
->assertSee('data-agreement-preview', false)
|
||
->assertSee('data-sign-request-send', false)
|
||
->assertDontSee('data-agreement-step-panel', false)
|
||
->assertSeeText('发起签章请求')
|
||
->assertSeeText('快递公司')
|
||
->assertSeeText('文件类型')
|
||
->assertSeeText('收款账户证明')
|
||
->assertSeeText('TPL-ACCOUNT-CERT-V2')
|
||
->assertSeeText('我方签署主体')
|
||
->assertSeeText('公司全称')
|
||
->assertSee('name="company_full_name"', false)
|
||
->assertSee('data-company-name', false)
|
||
->assertSee('data-subject-linked-name', false)
|
||
->assertSeeText('签署截止日期')
|
||
->assertSeeText('对方 E 签宝账号')
|
||
->assertSee('data-primary-esign-label', false)
|
||
->assertSee('data-secondary-esign-label', false)
|
||
->assertSee("labels.primary = '快递方 E 签宝账号'", false)
|
||
->assertSee("labels.secondary = '我方 E 签宝账号'", false)
|
||
->assertSee("labels.primary = '委托方 E 签宝账号'", false)
|
||
->assertSee("labels.secondary = '受托方 E 签宝账号'", false)
|
||
->assertSeeText('合作合同统一使用我方账号 18052733960')
|
||
->assertSeeText('填写变量')
|
||
->assertSeeText('签署完成后自动归档')
|
||
->assertSeeText('人工确认后归档')
|
||
->assertSeeText('刷新预览')
|
||
->assertSeeText('推送至E签宝')
|
||
->assertSeeText('收款帐户资料证明');
|
||
}
|
||
|
||
public function testAgreementSigningPageShowsOurCompanyAsInitiator(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
CourierAgreementSignature::create([
|
||
'company_id' => $this->company->id,
|
||
'business_no' => 'AGR-INITIATOR-001',
|
||
'idempotency_key' => 'initiator-001',
|
||
'document_type' => 'account-proof',
|
||
'template_code' => 'TPL-ACCOUNT-CERT-V2',
|
||
'template_version' => '2',
|
||
'source_file_name' => '收款账户证明文件.doc',
|
||
'status' => CourierAgreementSignature::STATUS_SIGNING,
|
||
'courier_name' => '新北中通',
|
||
'company_full_name' => $this->company->name,
|
||
'organization_name' => '新北中通',
|
||
'operator_name' => '张经理',
|
||
'operator_account' => '13800138000',
|
||
'payload' => ['signing_subject' => $this->company->name],
|
||
'environment' => 'sandbox',
|
||
'source_pdf_path' => 'courier-agreements/initiator/source.pdf',
|
||
'source_pdf_sha256' => hash('sha256', '%PDF-source'),
|
||
'esign_sign_flow_id' => 'flow-initiator-001',
|
||
'created_by' => $this->user->id,
|
||
'updated_by' => $this->user->id,
|
||
]);
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
]))
|
||
->assertOk()
|
||
->assertSee('<td>' . e($this->company->name) . '</td>', false)
|
||
->assertDontSee('<td>张经理</td>', false);
|
||
}
|
||
|
||
public function testAgreementSigningPageDistinguishesDefinitiveFailureFromUnknownResult(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
foreach ([
|
||
[
|
||
'business_no' => 'AGR-DEFINITIVE-FAILURE',
|
||
'last_error' => 'E 签宝接口返回业务错误(1435002):签署账号 18810726376 与身份信息不一致',
|
||
],
|
||
[
|
||
'business_no' => 'AGR-UNKNOWN-RESULT',
|
||
'last_error' => '创建签署流程时连接超时,无法确认远端结果。',
|
||
],
|
||
] as $index => $error) {
|
||
CourierAgreementSignature::create([
|
||
'company_id' => $this->company->id,
|
||
'business_no' => $error['business_no'],
|
||
'idempotency_key' => 'status-display-' . $index,
|
||
'document_type' => 'authorization',
|
||
'template_code' => 'TPL-AUTHORIZATION-V1',
|
||
'template_version' => '1',
|
||
'source_file_name' => '授权委托书(快递).docx',
|
||
'status' => CourierAgreementSignature::STATUS_UNKNOWN,
|
||
'courier_name' => '测试快递',
|
||
'company_full_name' => $this->company->name,
|
||
'organization_name' => '测试快递有限公司',
|
||
'operator_name' => '测试人员',
|
||
'operator_account' => '18810726376',
|
||
'payload' => ['signing_subject' => $this->company->name],
|
||
'environment' => 'production',
|
||
'source_pdf_path' => "courier-agreements/status-{$index}/source.pdf",
|
||
'source_pdf_sha256' => hash('sha256', '%PDF-source-' . $index),
|
||
'last_error' => $error['last_error'],
|
||
'created_by' => $this->user->id,
|
||
'updated_by' => $this->user->id,
|
||
]);
|
||
}
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
]))
|
||
->assertOk()
|
||
->assertSeeText('处理失败')
|
||
->assertSeeText('状态未知,请人工核对')
|
||
->assertSeeText('E 签宝接口返回业务错误(1435002):签署账号 188****6376 与身份信息不一致')
|
||
->assertDontSee('签署账号 18810726376', false);
|
||
}
|
||
|
||
public function testAgreementSigningPageKeepsRenderingWhenLegacyPayloadCannotBeDecrypted(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
DB::table('business_courier_agreement_signatures')->insert([
|
||
'company_id' => $this->company->id,
|
||
'business_no' => 'AGR-LEGACY-001',
|
||
'idempotency_key' => 'legacy-payload-001',
|
||
'document_type' => 'account-proof',
|
||
'template_code' => 'TPL-ACCOUNT-CERT-V2',
|
||
'template_version' => '2',
|
||
'source_file_name' => '收款账户证明文件.doc',
|
||
'status' => CourierAgreementSignature::STATUS_COMPLETED,
|
||
'courier_name' => '新北中通',
|
||
'company_full_name' => $this->company->name,
|
||
'organization_name' => '新北中通',
|
||
'operator_name' => '张经理',
|
||
'operator_account' => '13800138000',
|
||
// This value is intentionally not decryptable by the current APP_KEY.
|
||
'payload' => 'legacy-ciphertext',
|
||
'environment' => 'sandbox',
|
||
'source_pdf_path' => 'courier-agreements/legacy/source.pdf',
|
||
'source_pdf_sha256' => hash('sha256', '%PDF-source'),
|
||
'created_by' => $this->user->id,
|
||
'updated_by' => $this->user->id,
|
||
'created_at' => now(),
|
||
'updated_at' => now(),
|
||
]);
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
]))
|
||
->assertOk()
|
||
->assertSeeText('AGR-LEGACY-001')
|
||
->assertSee('<td>' . e($this->company->name) . '</td>', false);
|
||
}
|
||
|
||
public function testAgreementSigningPageMapsEverySourceDocumentToItsOwnFieldsAndPreview(): void
|
||
{
|
||
$this->grantWorkspaceAccess();
|
||
|
||
$response = $this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
'agreement_view' => 'create',
|
||
]))
|
||
->assertOk();
|
||
|
||
$response
|
||
->assertSee('data-template-fields="account-proof"', false)
|
||
->assertSee('data-template-preview="account-proof"', false)
|
||
->assertSeeText('生效日期')
|
||
->assertSeeText('银行帐户')
|
||
->assertSeeText('开户名称(持卡人姓名)')
|
||
->assertSeeText('填写实际收款银行卡对应的持卡人姓名,无需与营业执照或公司全称一致。')
|
||
->assertSeeText('我司同意自')
|
||
->assertSee('data-template-fields="account-change"', false)
|
||
->assertSee('data-template-preview="account-change"', false)
|
||
->assertSeeText('原收款账户')
|
||
->assertSeeText('原账户停止使用日期')
|
||
->assertSeeText('新账户启用日期')
|
||
->assertSeeText('之前相应的账户')
|
||
->assertSee('data-template-fields="entity-change"', false)
|
||
->assertSee('data-template-preview="entity-change"', false)
|
||
->assertSeeText('变更前公司名称')
|
||
->assertSeeText('变更后公司名称')
|
||
->assertSeeText('变更后,原公司的各项事宜由变更后的公司继续执行')
|
||
->assertSee('data-template-fields="shared-contract"', false)
|
||
->assertSee('data-template-preview="shared-contract"', false)
|
||
->assertSeeText('合同合作方')
|
||
->assertSeeText('快递公司甲(主体)')
|
||
->assertSeeText('共用合同的快递公司(可多个)')
|
||
->assertSee('name="shared_courier_names[]"', false)
|
||
->assertSee('data-shared-courier-add', false)
|
||
->assertSeeText('添加共用公司')
|
||
->assertSeeText('备注')
|
||
->assertSeeText('共同用一份合同,打款资料为同一份资料')
|
||
->assertSee('data-template-fields="cooperation-contract"', false)
|
||
->assertSee('data-template-preview="cooperation-contract"', false)
|
||
->assertSee('data-template-preview="quote-confirmation"', false)
|
||
->assertSee('data-quote-version', false)
|
||
->assertSeeText('报价确认单')
|
||
->assertSeeText('绑定已审核报价版本')
|
||
->assertSeeText('甲方名称')
|
||
->assertSee('name="cooperation_party_a_name"', false)
|
||
->assertSee('data-subject-linked-name', false)
|
||
->assertSeeText('乙方电话')
|
||
->assertSeeText('协议开始日期')
|
||
->assertSeeText('协议结束日期')
|
||
->assertSeeText('甲、乙双方根据')
|
||
->assertSee('data-template-fields="authorization"', false)
|
||
->assertSee('data-template-preview="authorization"', false)
|
||
->assertSeeText('委托方(个人或公司)')
|
||
->assertSeeText('授权事项(可多选)')
|
||
->assertSeeText('代签汇款账号变更')
|
||
->assertSeeText('委托有效期:从');
|
||
}
|
||
|
||
public function testAgreementSigningPageRejectsUsersWithoutItsSidebarPermission(): void
|
||
{
|
||
$subject = 'user_' . $this->user->id;
|
||
|
||
$this->user->roles()->sync([\App\Models\Auth\Role::where('name', 'admin')->firstOrFail()->id]);
|
||
setting()->set('system.sidebar_permissions', json_encode([
|
||
'configured' => [$subject],
|
||
'subjects' => [
|
||
$subject => ['courier-payables/freight-reconciliation'],
|
||
],
|
||
], JSON_UNESCAPED_UNICODE));
|
||
|
||
try {
|
||
$this->loginAs()->get(route('business.pages.show', [
|
||
'section' => 'courier-payables',
|
||
'page' => 'agreement-signing',
|
||
]));
|
||
$this->fail('没有协议签署页面权限的用户不应访问该页面。');
|
||
} catch (HttpException $exception) {
|
||
$this->assertSame(404, $exception->getStatusCode());
|
||
}
|
||
}
|
||
}
|