Skip to content

Commit 9d91083

Browse files
committed
test(policy): map blocked target-user policy save to bad request
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 009c700 commit 9d91083

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/php/Unit/Controller/PolicyControllerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,27 @@ public function testSetUserPolicyForTargetUserReturnsSavedResolvedPolicy(): void
478478
$this->assertSame('ordered_numeric', $response->getData()['policy']['effectiveValue']);
479479
}
480480

481+
public function testSetUserPolicyForTargetUserReturnsBadRequestWhenServiceBlocksSave(): void {
482+
$this->l10n
483+
->expects($this->once())
484+
->method('t')
485+
->with('Saving a user preference is not allowed for signature_flow')
486+
->willReturn('Saving a user preference is not allowed for signature_flow');
487+
488+
$this->policyService
489+
->expects($this->once())
490+
->method('saveUserPreferenceForUserId')
491+
->with('signature_flow', 'user1', 'ordered_numeric')
492+
->willThrowException(new \InvalidArgumentException('Saving a user preference is not allowed for signature_flow'));
493+
494+
$response = $this->controller->setUserPolicyForUser('user1', 'signature_flow', 'ordered_numeric');
495+
496+
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
497+
$this->assertSame([
498+
'error' => 'Saving a user preference is not allowed for signature_flow',
499+
], $response->getData());
500+
}
501+
481502
public function testSetUserPreferenceReadsBodyParamsFromRequest(): void {
482503
$request = $this->createMock(IRequest::class);
483504
$request

0 commit comments

Comments
 (0)