From b122e0b4e131780b7b69f342f8702772284f7603 Mon Sep 17 00:00:00 2001 From: Ashim Shrestha Date: Wed, 25 Nov 2026 11:21:12 +0545 Subject: [PATCH] fix: smart picker doesnot list work packages Signed-off-by: Ashim Shrestha --- CHANGELOG.md | 1 + lib/Listener/OpenProjectReferenceListener.php | 2 +- .../OpenProjectReferenceListenerTest.php | 114 ++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/lib/Listener/OpenProjectReferenceListenerTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 376ead123..f2bd5996d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Selecting an OpenProject work package does not insert the reference in the Smart Picker [#1200](https://github.com/nextcloud/integration_openproject/pull/1200) +- Smart picker does not list OpenProject work packages [#1206](https://github.com/nextcloud/integration_openproject/pull/1206) ### Changed diff --git a/lib/Listener/OpenProjectReferenceListener.php b/lib/Listener/OpenProjectReferenceListener.php index b9ace2cd8..967b090ce 100644 --- a/lib/Listener/OpenProjectReferenceListener.php +++ b/lib/Listener/OpenProjectReferenceListener.php @@ -65,7 +65,7 @@ public function handle(Event $event): void { 'authMethod' => $this->appConfig->getValueString(Application::APP_ID, 'authorization_method', '') ]; $this->initialStateService->provideInitialState( - 'admin-appConfig', + 'admin-config', $adminConfig ); $this->initialStateService->provideInitialState( diff --git a/tests/lib/Listener/OpenProjectReferenceListenerTest.php b/tests/lib/Listener/OpenProjectReferenceListenerTest.php new file mode 100644 index 000000000..e1ccb4c7a --- /dev/null +++ b/tests/lib/Listener/OpenProjectReferenceListenerTest.php @@ -0,0 +1,114 @@ +appConfig = $this->createMock(IAppConfig::class); + $this->initialState = $this->createMock(IInitialState::class); + $this->openProjectAPIService = $this->createMock(OpenProjectAPIService::class); + $this->listener = new OpenProjectReferenceListener( + $this->initialState, + $this->appConfig, + $this->openProjectAPIService, + 'testUser' + ); + } + + /** + * @return array + */ + public function dataTestHandle(): array { + return [ + [ + 'authMethod' => Application::AUTH_METHOD_OAUTH, + 'openprojectUrl' => 'http://local.test', + ], + [ + 'authMethod' => Application::AUTH_METHOD_OIDC, + 'openprojectUrl' => 'http://local.test', + ], + [ + 'authMethod' => '', + 'openprojectUrl' => '', + ], + ]; + } + + /** + * @dataProvider dataTestHandle + * + * @param string $authMethod + * @param string $openprojectUrl + * + * @return void + */ + public function testHandle(string $authMethod, string $openprojectUrl) { + $values = [ + 'authorization_method' => $authMethod, + 'openproject_instance_url' => $openprojectUrl, + ]; + $this->appConfig->method('getValueString') + ->willReturnCallback( + fn (string $app, string $key, string $default = ''):string => $values[$key] ?? $default + ); + $this->openProjectAPIService->method('getAccessToken')->willReturn('some-token'); + + $initStateCalls = []; + $this->initialState->method('provideInitialState') + ->willReturnCallback(function ($state, $config) use (&$initStateCalls) { + $initStateCalls[] = [$state, $config]; + }); + + $expectedCalls = [ + ['admin-config', [ + 'isAdminConfigOk' => false, + 'authMethod' => $authMethod, + ],], + ['openproject-url', $openprojectUrl], + ]; + $this->listener->handle($this->createMock(RenderReferenceEvent::class)); + $this->assertEqualsCanonicalizing($expectedCalls, $initStateCalls); + } + + /** + * @return void + */ + public function testHandleOidcWithoutAccessToken() { + $this->appConfig + ->method('getValueString') + ->willReturnCallback( + fn (string $app, string $key, string $default = ''): string => $key === 'authorization_method' + ? Application::AUTH_METHOD_OIDC + : $default + ); + $this->openProjectAPIService + ->method('getAccessToken') + ->willReturn(''); + + $this->initialState + ->expects($this->never()) + ->method('provideInitialState'); + + $this->listener->handle($this->createMock(RenderReferenceEvent::class)); + } +}