|
|
@@ -1,5 +1,7 @@
|
|
|
import { vi } from 'vitest';
|
|
|
|
|
|
+import config from '^/config/next-i18next.config';
|
|
|
+
|
|
|
import { configManager } from '~/server/service/config-manager/config-manager';
|
|
|
|
|
|
import NamedQuery from '../models/named-query';
|
|
|
@@ -55,12 +57,15 @@ describe('searchParseQuery()', () => {
|
|
|
});
|
|
|
|
|
|
it('should contain /user in the not_prefix query when user pages are disabled', async () => {
|
|
|
- vi.mocked(configManager.getConfig).mockReturnValue(true);
|
|
|
+ vi.mocked(configManager.getConfig).mockImplementation((key: string) => {
|
|
|
+ if (key === 'security:disableUserPages') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- const result = await (searchService as any).parseSearchQuery(
|
|
|
- '/user/settings',
|
|
|
- null,
|
|
|
- );
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ const result = await searchService.parseSearchQuery('/user/settings', null);
|
|
|
|
|
|
expect(configManager.getConfig).toHaveBeenCalledWith(
|
|
|
'security:disableUserPages',
|
|
|
@@ -70,12 +75,15 @@ describe('searchParseQuery()', () => {
|
|
|
});
|
|
|
|
|
|
it('should contain /user in the not_prefix even when search query is not a user page', async () => {
|
|
|
- vi.mocked(configManager.getConfig).mockReturnValue(true);
|
|
|
+ vi.mocked(configManager.getConfig).mockImplementation((key: string) => {
|
|
|
+ if (key === 'security:disableUserPages') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- const result = await (searchService as any).parseSearchQuery(
|
|
|
- '/new-task',
|
|
|
- null,
|
|
|
- );
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ const result = await searchService.parseSearchQuery('/new-task', null);
|
|
|
|
|
|
expect(configManager.getConfig).toHaveBeenCalledWith(
|
|
|
'security:disableUserPages',
|
|
|
@@ -85,12 +93,15 @@ describe('searchParseQuery()', () => {
|
|
|
});
|
|
|
|
|
|
it('should add specific user prefixes in the query when user pages are enabled', async () => {
|
|
|
- vi.mocked(configManager.getConfig).mockReturnValue(false);
|
|
|
+ vi.mocked(configManager.getConfig).mockImplementation((key: string) => {
|
|
|
+ if (key === 'security:disableUserPages') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- const result = await (searchService as any).parseSearchQuery(
|
|
|
- '/user/settings',
|
|
|
- null,
|
|
|
- );
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ const result = await searchService.parseSearchQuery('/user/settings', null);
|
|
|
|
|
|
expect(configManager.getConfig).toHaveBeenCalledWith(
|
|
|
'security:disableUserPages',
|
|
|
@@ -101,7 +112,13 @@ describe('searchParseQuery()', () => {
|
|
|
});
|
|
|
|
|
|
it('should filter user pages even when resolved from a named query alias', async () => {
|
|
|
- vi.mocked(configManager.getConfig).mockReturnValue(true);
|
|
|
+ vi.mocked(configManager.getConfig).mockImplementation((key: string) => {
|
|
|
+ if (key === 'security:disableUserPages') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ });
|
|
|
|
|
|
const shortcutName = 'my-shortcut';
|
|
|
const aliasPath = '/user/my-private-page';
|
|
|
@@ -110,12 +127,9 @@ describe('searchParseQuery()', () => {
|
|
|
vi.mocked(NamedQuery.findOne).mockResolvedValue({
|
|
|
name: shortcutName,
|
|
|
aliasOf: aliasPath,
|
|
|
- } as any);
|
|
|
+ });
|
|
|
|
|
|
- const result = await (searchService as any).parseSearchQuery(
|
|
|
- 'dummy',
|
|
|
- shortcutName,
|
|
|
- );
|
|
|
+ const result = await searchService.parseSearchQuery('dummy', shortcutName);
|
|
|
|
|
|
expect(configManager.getConfig).toHaveBeenCalledWith(
|
|
|
'security:disableUserPages',
|