{{ displayName }}
-
+
{{ strings.firstPost }}
-
+
- ·
+ ·
{{
- strings.threadsLabel(userStats?.threadCount || 0)
+ strings.threadsLabel(forumUser?.threadCount || 0)
}}
- {{ userStats?.threadCount || 0 }}
+ {{ forumUser?.threadCount || 0 }}
·
{{
- strings.repliesLabel(userStats?.postCount || 0)
+ strings.repliesLabel(forumUser?.postCount || 0)
}}
- {{ userStats?.postCount || 0 }}
+ {{ forumUser?.postCount || 0 }}
@@ -170,7 +170,7 @@ import PageWrapper from '@/components/PageWrapper.vue'
import ThreadCard from '@/components/ThreadCard.vue'
import ArrowLeftIcon from '@icons/ArrowLeft.vue'
import RefreshIcon from '@icons/Refresh.vue'
-import type { UserStats, Thread, Post } from '@/types'
+import type { ForumUser, Thread, Post } from '@/types'
import { ocs } from '@/axios'
import { t, n } from '@nextcloud/l10n'
import { getCurrentUser } from '@nextcloud/auth'
@@ -195,7 +195,7 @@ export default defineComponent({
loading: false,
loadingThreads: false,
loadingPosts: false,
- userStats: null as UserStats | null,
+ forumUser: null as ForumUser | null,
displayName: '',
threads: [] as Thread[],
posts: [] as Post[],
@@ -252,13 +252,13 @@ export default defineComponent({
// Load user stats (may not exist if user hasn't posted)
try {
const userResponse = await ocs.get(`/users/${this.userId}`)
- this.userStats = userResponse.data
+ this.forumUser = userResponse.data
} catch (err: any) {
// 404 is OK - user hasn't posted yet
if (err.response?.status !== 404) {
throw err
}
- this.userStats = null
+ this.forumUser = null
}
// Load both tabs on initial load for accurate counts
diff --git a/tests/unit/Controller/ForumUserControllerTest.php b/tests/unit/Controller/ForumUserControllerTest.php
index 4500cf7..dfc6f2f 100644
--- a/tests/unit/Controller/ForumUserControllerTest.php
+++ b/tests/unit/Controller/ForumUserControllerTest.php
@@ -6,8 +6,8 @@ namespace OCA\Forum\Tests\Controller;
use OCA\Forum\AppInfo\Application;
use OCA\Forum\Controller\ForumUserController;
-use OCA\Forum\Db\UserStats;
-use OCA\Forum\Db\UserStatsMapper;
+use OCA\Forum\Db\ForumUser;
+use OCA\Forum\Db\ForumUserMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\IRequest;
@@ -18,21 +18,21 @@ use Psr\Log\LoggerInterface;
class ForumUserControllerTest extends TestCase {
private ForumUserController $controller;
- private UserStatsMapper $userStatsMapper;
+ private ForumUserMapper $forumUserMapper;
private IUserSession $userSession;
private LoggerInterface $logger;
private IRequest $request;
protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
- $this->userStatsMapper = $this->createMock(UserStatsMapper::class);
+ $this->forumUserMapper = $this->createMock(ForumUserMapper::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->controller = new ForumUserController(
Application::APP_ID,
$this->request,
- $this->userStatsMapper,
+ $this->forumUserMapper,
$this->userSession,
$this->logger
);
@@ -42,7 +42,7 @@ class ForumUserControllerTest extends TestCase {
$user1 = $this->createForumUser(1, 'user1', 10);
$user2 = $this->createForumUser(2, 'user2', 25);
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('findAll')
->willReturn([$user1, $user2]);
@@ -58,7 +58,7 @@ class ForumUserControllerTest extends TestCase {
$nextcloudUserId = 'user1';
$user = $this->createForumUser(1, $nextcloudUserId, 10);
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('find')
->with($nextcloudUserId)
->willReturn($user);
@@ -74,15 +74,15 @@ class ForumUserControllerTest extends TestCase {
public function testShowReturnsNotFoundWhenUserDoesNotExist(): void {
$nextcloudUserId = 'non-existent-user';
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('find')
->with($nextcloudUserId)
- ->willThrowException(new DoesNotExistException('User stats not found'));
+ ->willThrowException(new DoesNotExistException('Forum user not found'));
$response = $this->controller->show($nextcloudUserId);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- $this->assertEquals(['error' => 'User stats not found'], $response->getData());
+ $this->assertEquals(['error' => 'Forum user not found'], $response->getData());
}
public function testShowWithMeReturnsCurrentUserSuccessfully(): void {
@@ -93,7 +93,7 @@ class ForumUserControllerTest extends TestCase {
$user->method('getUID')->willReturn($nextcloudUserId);
$this->userSession->method('getUser')->willReturn($user);
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('find')
->with($nextcloudUserId)
->willReturn($forumUser);
@@ -111,7 +111,7 @@ class ForumUserControllerTest extends TestCase {
$response = $this->controller->show('me');
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- $this->assertEquals(['error' => 'User stats not found'], $response->getData());
+ $this->assertEquals(['error' => 'Forum user not found'], $response->getData());
}
public function testShowWithMeReturnsNotFoundWhenForumUserDoesNotExist(): void {
@@ -121,22 +121,22 @@ class ForumUserControllerTest extends TestCase {
$user->method('getUID')->willReturn($nextcloudUserId);
$this->userSession->method('getUser')->willReturn($user);
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('find')
->with($nextcloudUserId)
- ->willThrowException(new DoesNotExistException('User stats not found'));
+ ->willThrowException(new DoesNotExistException('Forum user not found'));
$response = $this->controller->show('me');
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- $this->assertEquals(['error' => 'User stats not found'], $response->getData());
+ $this->assertEquals(['error' => 'Forum user not found'], $response->getData());
}
public function testCreateForumUserSuccessfully(): void {
$nextcloudUserId = 'new-user';
$createdUser = $this->createForumUser(1, $nextcloudUserId, 0);
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('createOrUpdate')
->with($nextcloudUserId)
->willReturn($createdUser);
@@ -149,13 +149,13 @@ class ForumUserControllerTest extends TestCase {
$this->assertEquals(0, $data['postCount']);
}
- private function createForumUser(int $id, string $userId, int $postCount): UserStats {
- $userStats = new UserStats();
- $userStats->setId($id);
- $userStats->setUserId($userId);
- $userStats->setPostCount($postCount);
- $userStats->setCreatedAt(time());
- $userStats->setUpdatedAt(time());
- return $userStats;
+ private function createForumUser(int $id, string $userId, int $postCount): ForumUser {
+ $forumUser = new ForumUser();
+ $forumUser->setId($id);
+ $forumUser->setUserId($userId);
+ $forumUser->setPostCount($postCount);
+ $forumUser->setCreatedAt(time());
+ $forumUser->setUpdatedAt(time());
+ return $forumUser;
}
}
diff --git a/tests/unit/Controller/PostControllerTest.php b/tests/unit/Controller/PostControllerTest.php
index 91704d7..6cfc597 100644
--- a/tests/unit/Controller/PostControllerTest.php
+++ b/tests/unit/Controller/PostControllerTest.php
@@ -10,6 +10,8 @@ use OCA\Forum\Db\BBCode;
use OCA\Forum\Db\BBCodeMapper;
use OCA\Forum\Db\Category;
use OCA\Forum\Db\CategoryMapper;
+use OCA\Forum\Db\ForumUser;
+use OCA\Forum\Db\ForumUserMapper;
use OCA\Forum\Db\Post;
use OCA\Forum\Db\PostMapper;
use OCA\Forum\Db\Reaction;
@@ -18,8 +20,6 @@ use OCA\Forum\Db\ReadMarker;
use OCA\Forum\Db\ReadMarkerMapper;
use OCA\Forum\Db\Thread;
use OCA\Forum\Db\ThreadMapper;
-use OCA\Forum\Db\UserStats;
-use OCA\Forum\Db\UserStatsMapper;
use OCA\Forum\Service\BBCodeService;
use OCA\Forum\Service\NotificationService;
use OCA\Forum\Service\PermissionService;
@@ -38,7 +38,7 @@ class PostControllerTest extends TestCase {
private PostMapper $postMapper;
private ThreadMapper $threadMapper;
private CategoryMapper $categoryMapper;
- private UserStatsMapper $userStatsMapper;
+ private ForumUserMapper $forumUserMapper;
private ReactionMapper $reactionMapper;
private BBCodeService $bbCodeService;
private BBCodeMapper $bbCodeMapper;
@@ -56,7 +56,7 @@ class PostControllerTest extends TestCase {
$this->postMapper = $this->createMock(PostMapper::class);
$this->threadMapper = $this->createMock(ThreadMapper::class);
$this->categoryMapper = $this->createMock(CategoryMapper::class);
- $this->userStatsMapper = $this->createMock(UserStatsMapper::class);
+ $this->forumUserMapper = $this->createMock(ForumUserMapper::class);
$this->reactionMapper = $this->createMock(ReactionMapper::class);
$this->bbCodeService = $this->createMock(BBCodeService::class);
$this->bbCodeMapper = $this->createMock(BBCodeMapper::class);
@@ -83,7 +83,7 @@ class PostControllerTest extends TestCase {
$this->postMapper,
$this->threadMapper,
$this->categoryMapper,
- $this->userStatsMapper,
+ $this->forumUserMapper,
$this->reactionMapper,
$this->bbCodeService,
$this->bbCodeMapper,
@@ -226,7 +226,7 @@ class PostControllerTest extends TestCase {
$this->userSession->method('getUser')->willReturn($user);
// Mock forum user
- $forumUser = new UserStats();
+ $forumUser = new ForumUser();
$forumUser->setId(1);
$forumUser->setUserId($userId);
$forumUser->setPostCount(0);
@@ -279,8 +279,8 @@ class PostControllerTest extends TestCase {
->method('update')
->willReturn($category);
- // Mock user stats increment (void methods, no return value expectations)
- $this->userStatsMapper->expects($this->once())
+ // Mock forum user increment (void methods, no return value expectations)
+ $this->forumUserMapper->expects($this->once())
->method('incrementPostCount')
->with($userId);
@@ -596,7 +596,7 @@ class PostControllerTest extends TestCase {
return $updatedCategory;
});
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('incrementPostCount')
->with($userId);
@@ -672,7 +672,7 @@ class PostControllerTest extends TestCase {
return $updatedCategory;
});
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('decrementPostCount')
->with($userId);
@@ -741,11 +741,11 @@ class PostControllerTest extends TestCase {
->method('update');
// First post deletion should decrement thread count, not post count
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('decrementThreadCount')
->with($userId);
- $this->userStatsMapper->expects($this->never())
+ $this->forumUserMapper->expects($this->never())
->method('decrementPostCount');
$response = $this->controller->destroy($postId);
diff --git a/tests/unit/Controller/ThreadControllerTest.php b/tests/unit/Controller/ThreadControllerTest.php
index b67e834..8f98c7a 100644
--- a/tests/unit/Controller/ThreadControllerTest.php
+++ b/tests/unit/Controller/ThreadControllerTest.php
@@ -8,13 +8,13 @@ use OCA\Forum\AppInfo\Application;
use OCA\Forum\Controller\ThreadController;
use OCA\Forum\Db\Category;
use OCA\Forum\Db\CategoryMapper;
+use OCA\Forum\Db\ForumUser;
+use OCA\Forum\Db\ForumUserMapper;
use OCA\Forum\Db\Post;
use OCA\Forum\Db\PostMapper;
use OCA\Forum\Db\Thread;
use OCA\Forum\Db\ThreadMapper;
use OCA\Forum\Db\ThreadSubscriptionMapper;
-use OCA\Forum\Db\UserStats;
-use OCA\Forum\Db\UserStatsMapper;
use OCA\Forum\Service\PermissionService;
use OCA\Forum\Service\ThreadEnrichmentService;
use OCA\Forum\Service\UserPreferencesService;
@@ -32,7 +32,7 @@ class ThreadControllerTest extends TestCase {
private ThreadMapper $threadMapper;
private CategoryMapper $categoryMapper;
private PostMapper $postMapper;
- private UserStatsMapper $userStatsMapper;
+ private ForumUserMapper $forumUserMapper;
private ThreadSubscriptionMapper $threadSubscriptionMapper;
private ThreadEnrichmentService $threadEnrichmentService;
private UserPreferencesService $userPreferencesService;
@@ -47,7 +47,7 @@ class ThreadControllerTest extends TestCase {
$this->threadMapper = $this->createMock(ThreadMapper::class);
$this->categoryMapper = $this->createMock(CategoryMapper::class);
$this->postMapper = $this->createMock(PostMapper::class);
- $this->userStatsMapper = $this->createMock(UserStatsMapper::class);
+ $this->forumUserMapper = $this->createMock(ForumUserMapper::class);
$this->threadSubscriptionMapper = $this->createMock(ThreadSubscriptionMapper::class);
$this->threadEnrichmentService = $this->createMock(ThreadEnrichmentService::class);
$this->userPreferencesService = $this->createMock(UserPreferencesService::class);
@@ -73,7 +73,7 @@ class ThreadControllerTest extends TestCase {
$this->threadMapper,
$this->categoryMapper,
$this->postMapper,
- $this->userStatsMapper,
+ $this->forumUserMapper,
$this->threadSubscriptionMapper,
$this->threadEnrichmentService,
$this->userPreferencesService,
@@ -222,14 +222,14 @@ class ThreadControllerTest extends TestCase {
$user->method('getUID')->willReturn($userId);
$this->userSession->method('getUser')->willReturn($user);
- $forumUser = new UserStats();
+ $forumUser = new ForumUser();
$forumUser->setUserId($userId);
$forumUser->setPostCount(10);
- // Mock user stats increment methods (first post doesn't count, only thread count increments)
- $this->userStatsMapper->expects($this->never())
+ // Mock forum user increment methods (first post doesn't count, only thread count increments)
+ $this->forumUserMapper->expects($this->never())
->method('incrementPostCount');
- $this->userStatsMapper->expects($this->once())
+ $this->forumUserMapper->expects($this->once())
->method('incrementThreadCount');
// Mock thread subscription
@@ -311,7 +311,7 @@ class ThreadControllerTest extends TestCase {
$this->assertEquals(['error' => 'User not authenticated'], $response->getData());
}
- public function testCreateThreadReturnsForbiddenWhenUserStatsNotRegistered(): void {
+ public function testCreateThreadSucceedsEvenWhenForumUserUpdateFails(): void {
$categoryId = 1;
$title = 'New Thread';
$content = 'Initial post content';
@@ -321,11 +321,11 @@ class ThreadControllerTest extends TestCase {
$user->method('getUID')->willReturn($userId);
$this->userSession->method('getUser')->willReturn($user);
- // Mock user stats methods to throw exceptions (simulating user stats failure)
+ // Mock forum user methods to throw exceptions (simulating forum user update failure)
// The controller catches these and just logs warnings, so thread creation should still succeed
- $this->userStatsMapper->method('incrementPostCount')
+ $this->forumUserMapper->method('incrementPostCount')
->willThrowException(new \Exception('Failed to increment post count'));
- $this->userStatsMapper->method('incrementThreadCount')
+ $this->forumUserMapper->method('incrementThreadCount')
->willThrowException(new \Exception('Failed to increment thread count'));
// Mock thread subscription
@@ -348,7 +348,7 @@ class ThreadControllerTest extends TestCase {
$response = $this->controller->create($categoryId, $title, $content);
- // Thread creation should succeed even if user stats fail (they're in a try-catch)
+ // Thread creation should succeed even if forum user update fails (they're in a try-catch)
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
}
diff --git a/tests/unit/Service/UserPreferencesServiceTest.php b/tests/unit/Service/UserPreferencesServiceTest.php
index 8fe011f..c05c5ad 100644
--- a/tests/unit/Service/UserPreferencesServiceTest.php
+++ b/tests/unit/Service/UserPreferencesServiceTest.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace OCA\Forum\Tests\Service;
use OCA\Forum\AppInfo\Application;
-use OCA\Forum\Db\UserStatsMapper;
+use OCA\Forum\Db\ForumUserMapper;
use OCA\Forum\Service\UserPreferencesService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IConfig;
@@ -15,21 +15,21 @@ use Psr\Log\LoggerInterface;
class UserPreferencesServiceTest extends TestCase {
private UserPreferencesService $service;
private IConfig $config;
- private UserStatsMapper $userStatsMapper;
+ private ForumUserMapper $forumUserMapper;
private LoggerInterface $logger;
protected function setUp(): void {
$this->config = $this->createMock(IConfig::class);
- $this->userStatsMapper = $this->createMock(UserStatsMapper::class);
+ $this->forumUserMapper = $this->createMock(ForumUserMapper::class);
$this->logger = $this->createMock(LoggerInterface::class);
- // By default, mock no user stats (no signature)
- $this->userStatsMapper->method('find')
+ // By default, mock no forum user (no signature)
+ $this->forumUserMapper->method('find')
->willThrowException(new DoesNotExistException(''));
$this->service = new UserPreferencesService(
$this->config,
- $this->userStatsMapper,
+ $this->forumUserMapper,
$this->logger
);
}
@@ -37,7 +37,7 @@ class UserPreferencesServiceTest extends TestCase {
public function testGetAllPreferencesReturnsAllPreferences(): void {
$userId = 'user1';
- // Only config-based preferences (signature is from user_stats)
+ // Only config-based preferences (signature is from forum_users)
$this->config->expects($this->exactly(2))
->method('getUserValue')
->willReturnCallback(function ($uid, $appId, $key, $default) use ($userId) {