Skip to content

Commit a852c44

Browse files
committed
feat(settings): add getUserIdentificationSettings method with tests
- Add getUserIdentificationSettings() public method - Extract user identification logic for reusability - Add comprehensive test coverage for all scenarios: * identification documents disabled * need to send documents * waiting for approval * documents approved This enables external services to check user identification status without duplicating the status resolution logic. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 45a76e0 commit a852c44

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

lib/Service/File/SettingsLoader.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ public function getIdentificationDocumentsStatus(string $userId = ''): int {
8383

8484
return self::IDENTIFICATION_DOCUMENTS_APPROVED;
8585
}
86+
87+
/**
88+
* Get user identification documents settings
89+
* These are user-specific settings, not file-specific
90+
*
91+
* @return array{needIdentificationDocuments: bool, identificationDocumentsWaitingApproval: bool}
92+
*/
93+
public function getUserIdentificationSettings(string $userId): array {
94+
$status = $this->getIdentificationDocumentsStatus($userId);
95+
96+
return [
97+
'needIdentificationDocuments' => in_array($status, [
98+
self::IDENTIFICATION_DOCUMENTS_NEED_SEND,
99+
self::IDENTIFICATION_DOCUMENTS_NEED_APPROVAL,
100+
], true),
101+
'identificationDocumentsWaitingApproval' => $status === self::IDENTIFICATION_DOCUMENTS_NEED_APPROVAL,
102+
];
103+
}
86104
}

tests/php/Unit/Service/File/SettingsLoaderTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,67 @@ public function testLoadSettingsEmptyUserIdReturnsNeedSend(): void {
232232

233233
$this->assertEquals(SettingsLoader::IDENTIFICATION_DOCUMENTS_NEED_SEND, $status);
234234
}
235+
236+
public function testGetUserIdentificationSettingsDisabled(): void {
237+
$this->appConfig->method('getValueBool')
238+
->with(Application::APP_ID, 'identification_documents', false)
239+
->willReturn(false);
240+
241+
$service = $this->getService();
242+
$result = $service->getUserIdentificationSettings('user123');
243+
244+
$this->assertFalse($result['needIdentificationDocuments']);
245+
$this->assertFalse($result['identificationDocumentsWaitingApproval']);
246+
}
247+
248+
public function testGetUserIdentificationSettingsNeedSend(): void {
249+
$this->appConfig->method('getValueBool')
250+
->with(Application::APP_ID, 'identification_documents', false)
251+
->willReturn(true);
252+
253+
$this->fileMapper->method('getFilesOfAccount')->with('user456')->willReturn([]);
254+
255+
$service = $this->getService();
256+
$result = $service->getUserIdentificationSettings('user456');
257+
258+
$this->assertTrue($result['needIdentificationDocuments']);
259+
$this->assertFalse($result['identificationDocumentsWaitingApproval']);
260+
}
261+
262+
public function testGetUserIdentificationSettingsNeedApproval(): void {
263+
$this->appConfig->method('getValueBool')
264+
->with(Application::APP_ID, 'identification_documents', false)
265+
->willReturn(true);
266+
267+
$file = new File();
268+
$file->setStatus(File::STATUS_DRAFT);
269+
270+
$this->fileMapper->method('getFilesOfAccount')->with('user789')->willReturn([$file]);
271+
272+
$service = $this->getService();
273+
$result = $service->getUserIdentificationSettings('user789');
274+
275+
$this->assertTrue($result['needIdentificationDocuments']);
276+
$this->assertTrue($result['identificationDocumentsWaitingApproval']);
277+
}
278+
279+
public function testGetUserIdentificationSettingsApproved(): void {
280+
$this->appConfig->method('getValueBool')
281+
->with(Application::APP_ID, 'identification_documents', false)
282+
->willReturn(true);
283+
284+
$file1 = new File();
285+
$file1->setStatus(File::STATUS_SIGNED);
286+
287+
$file2 = new File();
288+
$file2->setStatus(File::STATUS_SIGNED);
289+
290+
$this->fileMapper->method('getFilesOfAccount')->with('user999')->willReturn([$file1, $file2]);
291+
292+
$service = $this->getService();
293+
$result = $service->getUserIdentificationSettings('user999');
294+
295+
$this->assertFalse($result['needIdentificationDocuments']);
296+
$this->assertFalse($result['identificationDocumentsWaitingApproval']);
297+
}
235298
}

0 commit comments

Comments
 (0)