@qwickapps/server 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/plugins/bans/bans-plugin.d.ts.map +1 -1
- package/dist/plugins/bans/bans-plugin.js +12 -3
- package/dist/plugins/bans/bans-plugin.js.map +1 -1
- package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts +11 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts.map +1 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.js +410 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.js.map +1 -0
- package/dist/plugins/devices/__tests__/token-utils.test.d.ts +7 -0
- package/dist/plugins/devices/__tests__/token-utils.test.d.ts.map +1 -0
- package/dist/plugins/devices/__tests__/token-utils.test.js +197 -0
- package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -0
- package/dist/plugins/devices/adapters/compute-adapter.d.ts +36 -0
- package/dist/plugins/devices/adapters/compute-adapter.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/compute-adapter.js +100 -0
- package/dist/plugins/devices/adapters/compute-adapter.js.map +1 -0
- package/dist/plugins/devices/adapters/index.d.ts +12 -0
- package/dist/plugins/devices/adapters/index.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/index.js +10 -0
- package/dist/plugins/devices/adapters/index.js.map +1 -0
- package/dist/plugins/devices/adapters/mobile-adapter.d.ts +41 -0
- package/dist/plugins/devices/adapters/mobile-adapter.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/mobile-adapter.js +131 -0
- package/dist/plugins/devices/adapters/mobile-adapter.js.map +1 -0
- package/dist/plugins/devices/devices-plugin.d.ts +70 -0
- package/dist/plugins/devices/devices-plugin.d.ts.map +1 -0
- package/dist/plugins/devices/devices-plugin.js +453 -0
- package/dist/plugins/devices/devices-plugin.js.map +1 -0
- package/dist/plugins/devices/index.d.ts +18 -0
- package/dist/plugins/devices/index.d.ts.map +1 -0
- package/dist/plugins/devices/index.js +18 -0
- package/dist/plugins/devices/index.js.map +1 -0
- package/dist/plugins/devices/stores/index.d.ts +9 -0
- package/dist/plugins/devices/stores/index.d.ts.map +1 -0
- package/dist/plugins/devices/stores/index.js +9 -0
- package/dist/plugins/devices/stores/index.js.map +1 -0
- package/dist/plugins/devices/stores/postgres-store.d.ts +26 -0
- package/dist/plugins/devices/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/devices/stores/postgres-store.js +199 -0
- package/dist/plugins/devices/stores/postgres-store.js.map +1 -0
- package/dist/plugins/devices/token-utils.d.ts +100 -0
- package/dist/plugins/devices/token-utils.d.ts.map +1 -0
- package/dist/plugins/devices/token-utils.js +162 -0
- package/dist/plugins/devices/token-utils.js.map +1 -0
- package/dist/plugins/devices/types.d.ts +307 -0
- package/dist/plugins/devices/types.d.ts.map +1 -0
- package/dist/plugins/devices/types.js +10 -0
- package/dist/plugins/devices/types.js.map +1 -0
- package/dist/plugins/index.d.ts +14 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +13 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts +5 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts.map +1 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.js +470 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.js.map +1 -0
- package/dist/plugins/notifications/index.d.ts +71 -0
- package/dist/plugins/notifications/index.d.ts.map +1 -0
- package/dist/plugins/notifications/index.js +72 -0
- package/dist/plugins/notifications/index.js.map +1 -0
- package/dist/plugins/notifications/notifications-manager.d.ts +182 -0
- package/dist/plugins/notifications/notifications-manager.d.ts.map +1 -0
- package/dist/plugins/notifications/notifications-manager.js +610 -0
- package/dist/plugins/notifications/notifications-manager.js.map +1 -0
- package/dist/plugins/notifications/notifications-plugin.d.ts +83 -0
- package/dist/plugins/notifications/notifications-plugin.d.ts.map +1 -0
- package/dist/plugins/notifications/notifications-plugin.js +337 -0
- package/dist/plugins/notifications/notifications-plugin.js.map +1 -0
- package/dist/plugins/notifications/types.d.ts +164 -0
- package/dist/plugins/notifications/types.d.ts.map +1 -0
- package/dist/plugins/notifications/types.js +9 -0
- package/dist/plugins/notifications/types.js.map +1 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts +12 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts.map +1 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.js +349 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.js.map +1 -0
- package/dist/plugins/parental/adapters/index.d.ts +8 -0
- package/dist/plugins/parental/adapters/index.d.ts.map +1 -0
- package/dist/plugins/parental/adapters/index.js +7 -0
- package/dist/plugins/parental/adapters/index.js.map +1 -0
- package/dist/plugins/parental/adapters/kids-adapter.d.ts +24 -0
- package/dist/plugins/parental/adapters/kids-adapter.d.ts.map +1 -0
- package/dist/plugins/parental/adapters/kids-adapter.js +174 -0
- package/dist/plugins/parental/adapters/kids-adapter.js.map +1 -0
- package/dist/plugins/parental/index.d.ts +14 -0
- package/dist/plugins/parental/index.d.ts.map +1 -0
- package/dist/plugins/parental/index.js +15 -0
- package/dist/plugins/parental/index.js.map +1 -0
- package/dist/plugins/parental/parental-plugin.d.ts +88 -0
- package/dist/plugins/parental/parental-plugin.d.ts.map +1 -0
- package/dist/plugins/parental/parental-plugin.js +666 -0
- package/dist/plugins/parental/parental-plugin.js.map +1 -0
- package/dist/plugins/parental/stores/index.d.ts +7 -0
- package/dist/plugins/parental/stores/index.d.ts.map +1 -0
- package/dist/plugins/parental/stores/index.js +7 -0
- package/dist/plugins/parental/stores/index.js.map +1 -0
- package/dist/plugins/parental/stores/postgres-store.d.ts +10 -0
- package/dist/plugins/parental/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/parental/stores/postgres-store.js +209 -0
- package/dist/plugins/parental/stores/postgres-store.js.map +1 -0
- package/dist/plugins/parental/types.d.ts +154 -0
- package/dist/plugins/parental/types.d.ts.map +1 -0
- package/dist/plugins/parental/types.js +10 -0
- package/dist/plugins/parental/types.js.map +1 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts +11 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts.map +1 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.js +243 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.js.map +1 -0
- package/dist/plugins/profiles/index.d.ts +12 -0
- package/dist/plugins/profiles/index.d.ts.map +1 -0
- package/dist/plugins/profiles/index.js +13 -0
- package/dist/plugins/profiles/index.js.map +1 -0
- package/dist/plugins/profiles/profiles-plugin.d.ts +71 -0
- package/dist/plugins/profiles/profiles-plugin.d.ts.map +1 -0
- package/dist/plugins/profiles/profiles-plugin.js +481 -0
- package/dist/plugins/profiles/profiles-plugin.js.map +1 -0
- package/dist/plugins/profiles/stores/index.d.ts +9 -0
- package/dist/plugins/profiles/stores/index.d.ts.map +1 -0
- package/dist/plugins/profiles/stores/index.js +9 -0
- package/dist/plugins/profiles/stores/index.js.map +1 -0
- package/dist/plugins/profiles/stores/postgres-store.d.ts +18 -0
- package/dist/plugins/profiles/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/profiles/stores/postgres-store.js +310 -0
- package/dist/plugins/profiles/stores/postgres-store.js.map +1 -0
- package/dist/plugins/profiles/types.d.ts +289 -0
- package/dist/plugins/profiles/types.d.ts.map +1 -0
- package/dist/plugins/profiles/types.js +10 -0
- package/dist/plugins/profiles/types.js.map +1 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts +11 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts.map +1 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js +305 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js.map +1 -0
- package/dist/plugins/subscriptions/index.d.ts +12 -0
- package/dist/plugins/subscriptions/index.d.ts.map +1 -0
- package/dist/plugins/subscriptions/index.js +13 -0
- package/dist/plugins/subscriptions/index.js.map +1 -0
- package/dist/plugins/subscriptions/stores/index.d.ts +9 -0
- package/dist/plugins/subscriptions/stores/index.d.ts.map +1 -0
- package/dist/plugins/subscriptions/stores/index.js +9 -0
- package/dist/plugins/subscriptions/stores/index.js.map +1 -0
- package/dist/plugins/subscriptions/stores/postgres-store.d.ts +14 -0
- package/dist/plugins/subscriptions/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/subscriptions/stores/postgres-store.js +359 -0
- package/dist/plugins/subscriptions/stores/postgres-store.js.map +1 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.d.ts +82 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.js +449 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.js.map +1 -0
- package/dist/plugins/subscriptions/types.d.ts +308 -0
- package/dist/plugins/subscriptions/types.d.ts.map +1 -0
- package/dist/plugins/subscriptions/types.js +10 -0
- package/dist/plugins/subscriptions/types.js.map +1 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts +11 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts.map +1 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.js +218 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.js.map +1 -0
- package/dist/plugins/usage/index.d.ts +12 -0
- package/dist/plugins/usage/index.d.ts.map +1 -0
- package/dist/plugins/usage/index.js +13 -0
- package/dist/plugins/usage/index.js.map +1 -0
- package/dist/plugins/usage/stores/index.d.ts +9 -0
- package/dist/plugins/usage/stores/index.d.ts.map +1 -0
- package/dist/plugins/usage/stores/index.js +9 -0
- package/dist/plugins/usage/stores/index.js.map +1 -0
- package/dist/plugins/usage/stores/postgres-store.d.ts +14 -0
- package/dist/plugins/usage/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/usage/stores/postgres-store.js +146 -0
- package/dist/plugins/usage/stores/postgres-store.js.map +1 -0
- package/dist/plugins/usage/types.d.ts +195 -0
- package/dist/plugins/usage/types.d.ts.map +1 -0
- package/dist/plugins/usage/types.js +10 -0
- package/dist/plugins/usage/types.js.map +1 -0
- package/dist/plugins/usage/usage-plugin.d.ts +51 -0
- package/dist/plugins/usage/usage-plugin.d.ts.map +1 -0
- package/dist/plugins/usage/usage-plugin.js +412 -0
- package/dist/plugins/usage/usage-plugin.js.map +1 -0
- package/dist/plugins/users/__tests__/postgres-store.test.d.ts +10 -0
- package/dist/plugins/users/__tests__/postgres-store.test.d.ts.map +1 -0
- package/dist/plugins/users/__tests__/postgres-store.test.js +229 -0
- package/dist/plugins/users/__tests__/postgres-store.test.js.map +1 -0
- package/dist/plugins/users/__tests__/users-plugin.test.js +3 -0
- package/dist/plugins/users/__tests__/users-plugin.test.js.map +1 -1
- package/dist/plugins/users/index.d.ts +2 -2
- package/dist/plugins/users/index.d.ts.map +1 -1
- package/dist/plugins/users/index.js +1 -1
- package/dist/plugins/users/index.js.map +1 -1
- package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -1
- package/dist/plugins/users/stores/postgres-store.js +76 -0
- package/dist/plugins/users/stores/postgres-store.js.map +1 -1
- package/dist/plugins/users/types.d.ts +74 -6
- package/dist/plugins/users/types.d.ts.map +1 -1
- package/dist/plugins/users/users-plugin.d.ts +15 -1
- package/dist/plugins/users/users-plugin.d.ts.map +1 -1
- package/dist/plugins/users/users-plugin.js +29 -0
- package/dist/plugins/users/users-plugin.js.map +1 -1
- package/dist-ui/assets/index-CynOqPkb.js +469 -0
- package/dist-ui/assets/index-CynOqPkb.js.map +1 -0
- package/dist-ui/index.html +1 -1
- package/dist-ui-lib/api/controlPanelApi.d.ts +46 -0
- package/dist-ui-lib/components/StatCard.d.ts +16 -0
- package/dist-ui-lib/dashboard/widgets/NotificationsStatsWidget.d.ts +12 -0
- package/dist-ui-lib/dashboard/widgets/index.d.ts +1 -0
- package/dist-ui-lib/index.js +1822 -1611
- package/dist-ui-lib/index.js.map +1 -1
- package/dist-ui-lib/pages/NotificationsPage.d.ts +9 -0
- package/dist-ui-lib/utils/formatters.d.ts +19 -0
- package/package.json +1 -1
- package/src/index.ts +178 -0
- package/src/plugins/bans/bans-plugin.ts +15 -3
- package/src/plugins/devices/__tests__/devices-plugin.test.ts +551 -0
- package/src/plugins/devices/__tests__/token-utils.test.ts +264 -0
- package/src/plugins/devices/adapters/compute-adapter.ts +139 -0
- package/src/plugins/devices/adapters/index.ts +13 -0
- package/src/plugins/devices/adapters/mobile-adapter.ts +179 -0
- package/src/plugins/devices/devices-plugin.ts +538 -0
- package/src/plugins/devices/index.ts +69 -0
- package/src/plugins/devices/stores/index.ts +9 -0
- package/src/plugins/devices/stores/postgres-store.ts +304 -0
- package/src/plugins/devices/token-utils.ts +213 -0
- package/src/plugins/devices/types.ts +351 -0
- package/src/plugins/index.ts +218 -0
- package/src/plugins/notifications/__tests__/notifications-manager.test.ts +637 -0
- package/src/plugins/notifications/index.ts +91 -0
- package/src/plugins/notifications/notifications-manager.ts +773 -0
- package/src/plugins/notifications/notifications-plugin.ts +398 -0
- package/src/plugins/notifications/types.ts +207 -0
- package/src/plugins/parental/__tests__/parental-plugin.test.ts +465 -0
- package/src/plugins/parental/adapters/index.ts +8 -0
- package/src/plugins/parental/adapters/kids-adapter.ts +206 -0
- package/src/plugins/parental/index.ts +55 -0
- package/src/plugins/parental/parental-plugin.ts +759 -0
- package/src/plugins/parental/stores/index.ts +7 -0
- package/src/plugins/parental/stores/postgres-store.ts +304 -0
- package/src/plugins/parental/types.ts +180 -0
- package/src/plugins/profiles/__tests__/profiles-plugin.test.ts +321 -0
- package/src/plugins/profiles/index.ts +49 -0
- package/src/plugins/profiles/profiles-plugin.ts +546 -0
- package/src/plugins/profiles/stores/index.ts +9 -0
- package/src/plugins/profiles/stores/postgres-store.ts +439 -0
- package/src/plugins/profiles/types.ts +338 -0
- package/src/plugins/subscriptions/__tests__/subscriptions-plugin.test.ts +404 -0
- package/src/plugins/subscriptions/index.ts +51 -0
- package/src/plugins/subscriptions/stores/index.ts +9 -0
- package/src/plugins/subscriptions/stores/postgres-store.ts +482 -0
- package/src/plugins/subscriptions/subscriptions-plugin.ts +530 -0
- package/src/plugins/subscriptions/types.ts +355 -0
- package/src/plugins/usage/__tests__/usage-plugin.test.ts +288 -0
- package/src/plugins/usage/index.ts +39 -0
- package/src/plugins/usage/stores/index.ts +9 -0
- package/src/plugins/usage/stores/postgres-store.ts +213 -0
- package/src/plugins/usage/types.ts +222 -0
- package/src/plugins/usage/usage-plugin.ts +484 -0
- package/src/plugins/users/__tests__/postgres-store.test.ts +326 -0
- package/src/plugins/users/__tests__/users-plugin.test.ts +3 -0
- package/src/plugins/users/index.ts +6 -0
- package/src/plugins/users/stores/postgres-store.ts +104 -0
- package/src/plugins/users/types.ts +82 -6
- package/src/plugins/users/users-plugin.ts +37 -0
- package/ui/src/App.tsx +5 -1
- package/ui/src/api/controlPanelApi.ts +103 -6
- package/ui/src/components/StatCard.tsx +58 -0
- package/ui/src/dashboard/builtInWidgets.tsx +3 -1
- package/ui/src/dashboard/widgets/NotificationsStatsWidget.tsx +167 -0
- package/ui/src/dashboard/widgets/index.ts +1 -0
- package/ui/src/pages/NotificationsPage.tsx +417 -0
- package/ui/src/utils/formatters.ts +33 -0
- package/dist-ui/assets/index-D7DoZ9rL.js +0 -478
- package/dist-ui/assets/index-D7DoZ9rL.js.map +0 -1
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles Plugin Tests
|
|
3
|
+
*
|
|
4
|
+
* Unit tests for the profiles plugin including:
|
|
5
|
+
* - Plugin lifecycle
|
|
6
|
+
* - Profile CRUD operations
|
|
7
|
+
* - Age group calculation
|
|
8
|
+
* - Default profile management
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
12
|
+
import {
|
|
13
|
+
createProfilesPlugin,
|
|
14
|
+
getProfileStore,
|
|
15
|
+
createProfile,
|
|
16
|
+
getProfileById,
|
|
17
|
+
updateProfile,
|
|
18
|
+
deleteProfile,
|
|
19
|
+
listUserProfiles,
|
|
20
|
+
setDefaultProfile,
|
|
21
|
+
} from '../profiles-plugin.js';
|
|
22
|
+
import type { ProfileStore, Profile, AgeGroup } from '../types.js';
|
|
23
|
+
import type { PluginRegistry } from '../../../core/plugin-registry.js';
|
|
24
|
+
|
|
25
|
+
describe('Profiles Plugin', () => {
|
|
26
|
+
// Mock profile data
|
|
27
|
+
const mockProfile: Profile = {
|
|
28
|
+
id: 'profile-id-123',
|
|
29
|
+
org_id: 'org-123',
|
|
30
|
+
user_id: 'user-123',
|
|
31
|
+
name: 'Emma',
|
|
32
|
+
avatar: 'robot_pink',
|
|
33
|
+
birth_date: new Date('2018-06-15'),
|
|
34
|
+
age: 6,
|
|
35
|
+
age_group: 'child',
|
|
36
|
+
content_filter_level: 'strict',
|
|
37
|
+
daily_time_limit_minutes: 60,
|
|
38
|
+
allowed_hours_start: '08:00',
|
|
39
|
+
allowed_hours_end: '20:00',
|
|
40
|
+
is_active: true,
|
|
41
|
+
is_default: false,
|
|
42
|
+
metadata: { voice_id: 'en-US-child-1' },
|
|
43
|
+
created_at: new Date(),
|
|
44
|
+
updated_at: new Date(),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Mock store factory
|
|
48
|
+
const createMockStore = (): ProfileStore => ({
|
|
49
|
+
name: 'mock',
|
|
50
|
+
initialize: vi.fn().mockResolvedValue(undefined),
|
|
51
|
+
getById: vi.fn().mockResolvedValue(mockProfile),
|
|
52
|
+
create: vi.fn().mockResolvedValue(mockProfile),
|
|
53
|
+
update: vi.fn().mockResolvedValue(mockProfile),
|
|
54
|
+
delete: vi.fn().mockResolvedValue(true),
|
|
55
|
+
search: vi.fn().mockResolvedValue({
|
|
56
|
+
profiles: [mockProfile],
|
|
57
|
+
total: 1,
|
|
58
|
+
page: 1,
|
|
59
|
+
limit: 20,
|
|
60
|
+
totalPages: 1,
|
|
61
|
+
}),
|
|
62
|
+
listByUser: vi.fn().mockResolvedValue([mockProfile]),
|
|
63
|
+
getDefaultProfile: vi.fn().mockResolvedValue(mockProfile),
|
|
64
|
+
getProfileCount: vi.fn().mockResolvedValue(1),
|
|
65
|
+
getByAgeGroup: vi.fn().mockResolvedValue([mockProfile]),
|
|
66
|
+
setDefaultProfile: vi.fn().mockResolvedValue(true),
|
|
67
|
+
shutdown: vi.fn().mockResolvedValue(undefined),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Mock registry factory
|
|
71
|
+
const createMockRegistry = (): PluginRegistry =>
|
|
72
|
+
({
|
|
73
|
+
hasPlugin: vi.fn().mockReturnValue(false),
|
|
74
|
+
getPlugin: vi.fn().mockReturnValue(null),
|
|
75
|
+
listPlugins: vi.fn().mockReturnValue([]),
|
|
76
|
+
addRoute: vi.fn(),
|
|
77
|
+
addMenuItem: vi.fn(),
|
|
78
|
+
addPage: vi.fn(),
|
|
79
|
+
addWidget: vi.fn(),
|
|
80
|
+
getRoutes: vi.fn().mockReturnValue([]),
|
|
81
|
+
getMenuItems: vi.fn().mockReturnValue([]),
|
|
82
|
+
getPages: vi.fn().mockReturnValue([]),
|
|
83
|
+
getWidgets: vi.fn().mockReturnValue([]),
|
|
84
|
+
getConfig: vi.fn().mockReturnValue({}),
|
|
85
|
+
setConfig: vi.fn().mockResolvedValue(undefined),
|
|
86
|
+
subscribe: vi.fn().mockReturnValue(() => {}),
|
|
87
|
+
emit: vi.fn(),
|
|
88
|
+
registerHealthCheck: vi.fn(),
|
|
89
|
+
getApp: vi.fn().mockReturnValue({} as any),
|
|
90
|
+
getRouter: vi.fn().mockReturnValue({} as any),
|
|
91
|
+
getLogger: vi.fn().mockReturnValue({
|
|
92
|
+
debug: vi.fn(),
|
|
93
|
+
info: vi.fn(),
|
|
94
|
+
warn: vi.fn(),
|
|
95
|
+
error: vi.fn(),
|
|
96
|
+
}),
|
|
97
|
+
}) as unknown as PluginRegistry;
|
|
98
|
+
|
|
99
|
+
let mockStore: ProfileStore;
|
|
100
|
+
let mockRegistry: PluginRegistry;
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
vi.clearAllMocks();
|
|
104
|
+
mockStore = createMockStore();
|
|
105
|
+
mockRegistry = createMockRegistry();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
afterEach(async () => {
|
|
109
|
+
// Clean up by stopping the plugin if it was started
|
|
110
|
+
const store = getProfileStore();
|
|
111
|
+
if (store) {
|
|
112
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
113
|
+
await plugin.onStop?.();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('createProfilesPlugin', () => {
|
|
118
|
+
it('should create a plugin with correct id', () => {
|
|
119
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
120
|
+
expect(plugin.id).toBe('profiles');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should create a plugin with correct name', () => {
|
|
124
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
125
|
+
expect(plugin.name).toBe('Profiles');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should create a plugin with version', () => {
|
|
129
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
130
|
+
expect(plugin.version).toBe('1.0.0');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('onStart', () => {
|
|
135
|
+
it('should initialize store on start', async () => {
|
|
136
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
137
|
+
await plugin.onStart({}, mockRegistry);
|
|
138
|
+
|
|
139
|
+
expect(mockStore.initialize).toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should register health check', async () => {
|
|
143
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
144
|
+
await plugin.onStart({}, mockRegistry);
|
|
145
|
+
|
|
146
|
+
expect(mockRegistry.registerHealthCheck).toHaveBeenCalledWith(
|
|
147
|
+
expect.objectContaining({
|
|
148
|
+
name: 'profiles-store',
|
|
149
|
+
type: 'custom',
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should register CRUD routes by default', async () => {
|
|
155
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
156
|
+
await plugin.onStart({}, mockRegistry);
|
|
157
|
+
|
|
158
|
+
// GET /profiles, GET /profiles/:id, POST /profiles, PUT /profiles/:id,
|
|
159
|
+
// DELETE /profiles/:id, POST /profiles/:id/default
|
|
160
|
+
expect(mockRegistry.addRoute).toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('onStop', () => {
|
|
165
|
+
it('should shutdown store', async () => {
|
|
166
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
167
|
+
await plugin.onStart({}, mockRegistry);
|
|
168
|
+
await plugin.onStop?.();
|
|
169
|
+
|
|
170
|
+
expect(mockStore.shutdown).toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should clear store reference', async () => {
|
|
174
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
175
|
+
await plugin.onStart({}, mockRegistry);
|
|
176
|
+
await plugin.onStop?.();
|
|
177
|
+
|
|
178
|
+
expect(getProfileStore()).toBeNull();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('helper functions', () => {
|
|
183
|
+
describe('getProfileStore', () => {
|
|
184
|
+
it('should return null when plugin not started', () => {
|
|
185
|
+
expect(getProfileStore()).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should return store when plugin started', async () => {
|
|
189
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
190
|
+
await plugin.onStart({}, mockRegistry);
|
|
191
|
+
|
|
192
|
+
expect(getProfileStore()).toBe(mockStore);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('createProfile', () => {
|
|
197
|
+
it('should throw when plugin not initialized', async () => {
|
|
198
|
+
await expect(
|
|
199
|
+
createProfile({ user_id: 'user-123', name: 'Test' })
|
|
200
|
+
).rejects.toThrow('Profiles plugin not initialized');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should create profile', async () => {
|
|
204
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
205
|
+
await plugin.onStart({}, mockRegistry);
|
|
206
|
+
|
|
207
|
+
const result = await createProfile({
|
|
208
|
+
user_id: 'user-123',
|
|
209
|
+
name: 'Emma',
|
|
210
|
+
age: 6,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(result.id).toBe(mockProfile.id);
|
|
214
|
+
expect(mockStore.create).toHaveBeenCalled();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('getProfileById', () => {
|
|
219
|
+
it('should throw when plugin not initialized', async () => {
|
|
220
|
+
await expect(getProfileById('profile-id')).rejects.toThrow(
|
|
221
|
+
'Profiles plugin not initialized'
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should return profile when found', async () => {
|
|
226
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
227
|
+
await plugin.onStart({}, mockRegistry);
|
|
228
|
+
|
|
229
|
+
const result = await getProfileById(mockProfile.id);
|
|
230
|
+
expect(result).toEqual(mockProfile);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should return null when not found', async () => {
|
|
234
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
235
|
+
await plugin.onStart({}, mockRegistry);
|
|
236
|
+
|
|
237
|
+
(mockStore.getById as any).mockResolvedValue(null);
|
|
238
|
+
|
|
239
|
+
const result = await getProfileById('non-existent');
|
|
240
|
+
expect(result).toBeNull();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('updateProfile', () => {
|
|
245
|
+
it('should throw when plugin not initialized', async () => {
|
|
246
|
+
await expect(
|
|
247
|
+
updateProfile('profile-id', { name: 'New Name' })
|
|
248
|
+
).rejects.toThrow('Profiles plugin not initialized');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('should update profile', async () => {
|
|
252
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
253
|
+
await plugin.onStart({}, mockRegistry);
|
|
254
|
+
|
|
255
|
+
const updated = { ...mockProfile, name: 'Updated Name' };
|
|
256
|
+
(mockStore.update as any).mockResolvedValue(updated);
|
|
257
|
+
|
|
258
|
+
const result = await updateProfile(mockProfile.id, { name: 'Updated Name' });
|
|
259
|
+
|
|
260
|
+
expect(result?.name).toBe('Updated Name');
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('deleteProfile', () => {
|
|
265
|
+
it('should throw when plugin not initialized', async () => {
|
|
266
|
+
await expect(deleteProfile('profile-id')).rejects.toThrow(
|
|
267
|
+
'Profiles plugin not initialized'
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should delete profile', async () => {
|
|
272
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
273
|
+
await plugin.onStart({}, mockRegistry);
|
|
274
|
+
|
|
275
|
+
const result = await deleteProfile(mockProfile.id);
|
|
276
|
+
|
|
277
|
+
expect(result).toBe(true);
|
|
278
|
+
expect(mockStore.delete).toHaveBeenCalledWith(mockProfile.id);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('listUserProfiles', () => {
|
|
283
|
+
it('should throw when plugin not initialized', async () => {
|
|
284
|
+
await expect(listUserProfiles('user-id')).rejects.toThrow(
|
|
285
|
+
'Profiles plugin not initialized'
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should return user profiles', async () => {
|
|
290
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
291
|
+
await plugin.onStart({}, mockRegistry);
|
|
292
|
+
|
|
293
|
+
const result = await listUserProfiles('user-123');
|
|
294
|
+
|
|
295
|
+
expect(result).toHaveLength(1);
|
|
296
|
+
expect(result[0]).toEqual(mockProfile);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('setDefaultProfile', () => {
|
|
301
|
+
it('should throw when plugin not initialized', async () => {
|
|
302
|
+
await expect(
|
|
303
|
+
setDefaultProfile('profile-id', 'user-id')
|
|
304
|
+
).rejects.toThrow('Profiles plugin not initialized');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('should set default profile', async () => {
|
|
308
|
+
const plugin = createProfilesPlugin({ store: mockStore });
|
|
309
|
+
await plugin.onStart({}, mockRegistry);
|
|
310
|
+
|
|
311
|
+
const result = await setDefaultProfile(mockProfile.id, 'user-123');
|
|
312
|
+
|
|
313
|
+
expect(result).toBe(true);
|
|
314
|
+
expect(mockStore.setDefaultProfile).toHaveBeenCalledWith(
|
|
315
|
+
mockProfile.id,
|
|
316
|
+
'user-123'
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles Plugin
|
|
3
|
+
*
|
|
4
|
+
* Generic multi-profile management with age support.
|
|
5
|
+
* Exports all profile-related functionality.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Main plugin
|
|
11
|
+
export {
|
|
12
|
+
createProfilesPlugin,
|
|
13
|
+
getProfileStore,
|
|
14
|
+
createProfile,
|
|
15
|
+
getProfileById,
|
|
16
|
+
updateProfile,
|
|
17
|
+
deleteProfile,
|
|
18
|
+
listUserProfiles,
|
|
19
|
+
getDefaultProfile,
|
|
20
|
+
setDefaultProfile,
|
|
21
|
+
getProfilesByAgeGroup,
|
|
22
|
+
getChildProfiles,
|
|
23
|
+
getProfileAge,
|
|
24
|
+
checkTimeRestrictions,
|
|
25
|
+
getContentFilterLevel,
|
|
26
|
+
canAccessContent,
|
|
27
|
+
} from './profiles-plugin.js';
|
|
28
|
+
|
|
29
|
+
// Types
|
|
30
|
+
export type {
|
|
31
|
+
Profile,
|
|
32
|
+
CreateProfileInput,
|
|
33
|
+
UpdateProfileInput,
|
|
34
|
+
ProfileSearchParams,
|
|
35
|
+
ProfileListResponse,
|
|
36
|
+
TimeRestrictionResult,
|
|
37
|
+
ContentFilterLevel,
|
|
38
|
+
AgeGroup,
|
|
39
|
+
ProfileStore,
|
|
40
|
+
ProfilesPluginConfig,
|
|
41
|
+
ProfilesApiConfig,
|
|
42
|
+
PostgresProfileStoreConfig,
|
|
43
|
+
AgeThresholds,
|
|
44
|
+
QwickBotProfileMetadata,
|
|
45
|
+
GamingProfileMetadata,
|
|
46
|
+
} from './types.js';
|
|
47
|
+
|
|
48
|
+
// Stores
|
|
49
|
+
export { postgresProfileStore } from './stores/index.js';
|