@jmruthers/pace-core 0.5.74 → 0.5.75

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.
Files changed (278) hide show
  1. package/dist/{DataTable-2QR5TER5.js → DataTable-HWZQGASI.js} +8 -8
  2. package/dist/{PublicLoadingSpinner-DLpF5bbs.d.ts → PublicLoadingSpinner-BKNBT6b6.d.ts} +2 -2
  3. package/dist/RBACService-C4udt_Zp.d.ts +528 -0
  4. package/dist/{UnifiedAuthProvider-K4NRGXL4.js → UnifiedAuthProvider-3NKDOSOK.js} +6 -4
  5. package/dist/UnifiedAuthProvider-Bj6YCf7c.d.ts +113 -0
  6. package/dist/{chunk-UJMCGBLS.js → chunk-2CHATWBF.js} +5 -7
  7. package/dist/chunk-2CHATWBF.js.map +1 -0
  8. package/dist/{chunk-BKVGJVUR.js → chunk-2DFZ432F.js} +496 -30
  9. package/dist/chunk-2DFZ432F.js.map +1 -0
  10. package/dist/{chunk-LVQ26TCN.js → chunk-33PHABLB.js} +36 -3
  11. package/dist/chunk-33PHABLB.js.map +1 -0
  12. package/dist/chunk-5F3NDPJV.js +232 -0
  13. package/dist/chunk-5F3NDPJV.js.map +1 -0
  14. package/dist/chunk-A4FUBC7B.js +17 -0
  15. package/dist/chunk-A4FUBC7B.js.map +1 -0
  16. package/dist/{chunk-SMJZMKYN.js → chunk-A6HBIY5P.js} +2 -11
  17. package/dist/{chunk-SMJZMKYN.js.map → chunk-A6HBIY5P.js.map} +1 -1
  18. package/dist/{chunk-IHMMNKNA.js → chunk-CY3AHGO4.js} +6256 -1937
  19. package/dist/chunk-CY3AHGO4.js.map +1 -0
  20. package/dist/{chunk-H2TNUICK.js → chunk-DAXLNIDY.js} +47 -49
  21. package/dist/chunk-DAXLNIDY.js.map +1 -0
  22. package/dist/{chunk-VKOCWWVY.js → chunk-L3RV2ALE.js} +1 -6
  23. package/dist/{chunk-VKOCWWVY.js.map → chunk-L3RV2ALE.js.map} +1 -1
  24. package/dist/chunk-LW7MMEAQ.js +59 -0
  25. package/dist/chunk-LW7MMEAQ.js.map +1 -0
  26. package/dist/{chunk-DG5Z55HH.js → chunk-NTNILOBC.js} +7 -9
  27. package/dist/chunk-NTNILOBC.js.map +1 -0
  28. package/dist/chunk-PYUXFQJ3.js +11 -0
  29. package/dist/chunk-PYUXFQJ3.js.map +1 -0
  30. package/dist/chunk-URUTVZ7N.js +27 -0
  31. package/dist/chunk-URUTVZ7N.js.map +1 -0
  32. package/dist/chunk-WN6XJWOS.js +2468 -0
  33. package/dist/chunk-WN6XJWOS.js.map +1 -0
  34. package/dist/{chunk-3SP4P7NS.js → chunk-XLZ7U46Z.js} +59 -1
  35. package/dist/chunk-XLZ7U46Z.js.map +1 -0
  36. package/dist/{chunk-ORSMVXO2.js → chunk-ZTT2AXMX.js} +9 -14
  37. package/dist/chunk-ZTT2AXMX.js.map +1 -0
  38. package/dist/components.d.ts +4 -5
  39. package/dist/components.js +32 -39
  40. package/dist/components.js.map +1 -1
  41. package/dist/hooks.d.ts +3 -3
  42. package/dist/hooks.js +9 -8
  43. package/dist/hooks.js.map +1 -1
  44. package/dist/index.d.ts +156 -10
  45. package/dist/index.js +188 -93
  46. package/dist/index.js.map +1 -1
  47. package/dist/{organisation-t-vvQC3g.d.ts → organisation-BtshODVF.d.ts} +4 -3
  48. package/dist/providers.d.ts +27 -38
  49. package/dist/providers.js +33 -23
  50. package/dist/rbac/index.d.ts +61 -5
  51. package/dist/rbac/index.js +13 -14
  52. package/dist/styles/index.js +2 -2
  53. package/dist/theming/runtime.js +1 -3
  54. package/dist/types.d.ts +3 -3
  55. package/dist/types.js +1 -1
  56. package/dist/types.js.map +1 -1
  57. package/dist/{unified-CMPjE_fv.d.ts → unified-CM7T0aTK.d.ts} +1 -1
  58. package/dist/useInactivityTracker-MRUU55XI.js +10 -0
  59. package/dist/useInactivityTracker-MRUU55XI.js.map +1 -0
  60. package/dist/{usePublicRouteParams-Ua1Vz-HG.d.ts → usePublicRouteParams-B-CumWRc.d.ts} +3 -3
  61. package/dist/utils.js +7 -9
  62. package/dist/utils.js.map +1 -1
  63. package/dist/validation.d.ts +1 -1
  64. package/docs/api/classes/ColumnFactory.md +1 -1
  65. package/docs/api/classes/ErrorBoundary.md +1 -1
  66. package/docs/api/classes/InvalidScopeError.md +1 -1
  67. package/docs/api/classes/MissingUserContextError.md +1 -1
  68. package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
  69. package/docs/api/classes/PermissionDeniedError.md +1 -1
  70. package/docs/api/classes/PublicErrorBoundary.md +1 -1
  71. package/docs/api/classes/RBACAuditManager.md +1 -1
  72. package/docs/api/classes/RBACCache.md +1 -1
  73. package/docs/api/classes/RBACEngine.md +1 -1
  74. package/docs/api/classes/RBACError.md +1 -1
  75. package/docs/api/classes/RBACNotInitializedError.md +1 -1
  76. package/docs/api/classes/SecureSupabaseClient.md +1 -1
  77. package/docs/api/classes/StorageUtils.md +1 -1
  78. package/docs/api/enums/FileCategory.md +1 -1
  79. package/docs/api/interfaces/AggregateConfig.md +1 -1
  80. package/docs/api/interfaces/ButtonProps.md +3 -3
  81. package/docs/api/interfaces/CardProps.md +2 -2
  82. package/docs/api/interfaces/ColorPalette.md +1 -1
  83. package/docs/api/interfaces/ColorShade.md +1 -1
  84. package/docs/api/interfaces/DataAccessRecord.md +1 -1
  85. package/docs/api/interfaces/DataTableAction.md +1 -1
  86. package/docs/api/interfaces/DataTableColumn.md +1 -1
  87. package/docs/api/interfaces/DataTableProps.md +1 -1
  88. package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
  89. package/docs/api/interfaces/EmptyStateConfig.md +1 -1
  90. package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
  91. package/docs/api/interfaces/EventLogoProps.md +2 -2
  92. package/docs/api/interfaces/FileDisplayProps.md +1 -1
  93. package/docs/api/interfaces/FileMetadata.md +1 -1
  94. package/docs/api/interfaces/FileReference.md +1 -1
  95. package/docs/api/interfaces/FileSizeLimits.md +1 -1
  96. package/docs/api/interfaces/FileUploadOptions.md +1 -1
  97. package/docs/api/interfaces/FileUploadProps.md +1 -1
  98. package/docs/api/interfaces/FooterProps.md +1 -1
  99. package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
  100. package/docs/api/interfaces/InputProps.md +2 -2
  101. package/docs/api/interfaces/LabelProps.md +1 -1
  102. package/docs/api/interfaces/LoginFormProps.md +1 -1
  103. package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
  104. package/docs/api/interfaces/NavigationContextType.md +1 -1
  105. package/docs/api/interfaces/NavigationGuardProps.md +1 -1
  106. package/docs/api/interfaces/NavigationItem.md +1 -1
  107. package/docs/api/interfaces/NavigationMenuProps.md +1 -1
  108. package/docs/api/interfaces/NavigationProviderProps.md +1 -1
  109. package/docs/api/interfaces/Organisation.md +1 -1
  110. package/docs/api/interfaces/OrganisationContextType.md +28 -17
  111. package/docs/api/interfaces/OrganisationMembership.md +1 -1
  112. package/docs/api/interfaces/OrganisationProviderProps.md +2 -2
  113. package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
  114. package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
  115. package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
  116. package/docs/api/interfaces/PageAccessRecord.md +1 -1
  117. package/docs/api/interfaces/PagePermissionContextType.md +1 -1
  118. package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
  119. package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
  120. package/docs/api/interfaces/PaletteData.md +1 -1
  121. package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
  122. package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
  123. package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
  124. package/docs/api/interfaces/PublicLoadingSpinnerProps.md +2 -2
  125. package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
  126. package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
  127. package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
  128. package/docs/api/interfaces/RBACConfig.md +1 -1
  129. package/docs/api/interfaces/RBACContextType.md +5 -11
  130. package/docs/api/interfaces/RBACLogger.md +1 -1
  131. package/docs/api/interfaces/RBACProviderProps.md +1 -1
  132. package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
  133. package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
  134. package/docs/api/interfaces/RouteAccessRecord.md +1 -1
  135. package/docs/api/interfaces/RouteConfig.md +1 -1
  136. package/docs/api/interfaces/SecureDataContextType.md +1 -1
  137. package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
  138. package/docs/api/interfaces/StorageConfig.md +1 -1
  139. package/docs/api/interfaces/StorageFileInfo.md +1 -1
  140. package/docs/api/interfaces/StorageFileMetadata.md +1 -1
  141. package/docs/api/interfaces/StorageListOptions.md +1 -1
  142. package/docs/api/interfaces/StorageListResult.md +1 -1
  143. package/docs/api/interfaces/StorageUploadOptions.md +1 -1
  144. package/docs/api/interfaces/StorageUploadResult.md +1 -1
  145. package/docs/api/interfaces/StorageUrlOptions.md +1 -1
  146. package/docs/api/interfaces/StyleImport.md +1 -1
  147. package/docs/api/interfaces/SwitchProps.md +1 -1
  148. package/docs/api/interfaces/ToastActionElement.md +1 -1
  149. package/docs/api/interfaces/ToastProps.md +1 -1
  150. package/docs/api/interfaces/UnifiedAuthContextType.md +524 -440
  151. package/docs/api/interfaces/UnifiedAuthProviderProps.md +14 -14
  152. package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
  153. package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
  154. package/docs/api/interfaces/UsePublicEventLogoOptions.md +1 -1
  155. package/docs/api/interfaces/UsePublicEventLogoReturn.md +1 -1
  156. package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
  157. package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
  158. package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
  159. package/docs/api/interfaces/UserEventAccess.md +11 -11
  160. package/docs/api/interfaces/UserMenuProps.md +1 -1
  161. package/docs/api/interfaces/UserProfile.md +1 -1
  162. package/docs/api/modules.md +179 -52
  163. package/docs/architecture/services.md +30 -32
  164. package/docs/breaking-changes.md +2 -5
  165. package/docs/migration/service-architecture.md +121 -260
  166. package/docs/rbac/README-rbac-rls-integration.md +48 -38
  167. package/{src/rbac/examples → examples/RBAC}/CompleteRBACExample.tsx +3 -2
  168. package/{src/rbac/examples → examples/RBAC}/EventBasedApp.tsx +5 -4
  169. package/{src/components/examples → examples/RBAC}/PermissionExample.tsx +7 -6
  170. package/examples/RBAC/__tests__/PermissionExample.test.tsx +150 -0
  171. package/examples/RBAC/index.ts +13 -0
  172. package/examples/README.md +37 -0
  173. package/examples/index.ts +22 -0
  174. package/{src/examples → examples/public-pages}/CorrectPublicPageImplementation.tsx +1 -1
  175. package/{src/examples → examples/public-pages}/PublicEventPage.tsx +1 -1
  176. package/{src/examples → examples/public-pages}/PublicPageApp.tsx +1 -1
  177. package/{src/examples → examples/public-pages}/PublicPageUsageExample.tsx +1 -1
  178. package/examples/public-pages/__tests__/PublicPageUsageExample.test.tsx +159 -0
  179. package/examples/public-pages/index.ts +14 -0
  180. package/package.json +22 -18
  181. package/src/__tests__/TEST_GUIDE_CURSOR.md +650 -9
  182. package/src/__tests__/helpers/README.md +255 -0
  183. package/src/__tests__/helpers/index.ts +62 -0
  184. package/src/__tests__/helpers/supabaseMock.ts +27 -3
  185. package/src/__tests__/rbac/PagePermissionGuard.test.tsx +6 -8
  186. package/src/components/DataTable/components/__tests__/COVERAGE_NOTE.md +55 -0
  187. package/src/components/DataTable/core/ColumnManager.ts +10 -0
  188. package/src/components/DataTable/core/__tests__/ColumnFactory.test.ts +254 -0
  189. package/src/components/DataTable/core/__tests__/ColumnManager.test.ts +193 -0
  190. package/src/components/DataTable/examples/__tests__/HierarchicalExample.test.tsx +45 -0
  191. package/src/components/DataTable/examples/__tests__/PerformanceExample.test.tsx +117 -0
  192. package/src/components/Dialog/examples/__tests__/HtmlDialogExample.test.tsx +71 -0
  193. package/src/components/Dialog/examples/__tests__/SimpleHtmlTest.test.tsx +122 -0
  194. package/src/components/EventSelector/EventSelector.tsx +1 -1
  195. package/src/components/Header/Header.test.tsx +35 -1
  196. package/src/components/Header/Header.tsx +3 -1
  197. package/src/components/OrganisationSelector/OrganisationSelector.tsx +3 -3
  198. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.rbac.test.tsx +24 -4
  199. package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +3 -2
  200. package/src/hooks/__tests__/useFocusManagement.unit.test.ts +220 -0
  201. package/src/hooks/__tests__/useIsMobile.unit.test.ts +117 -0
  202. package/src/hooks/__tests__/useKeyboardShortcuts.unit.test.ts +295 -0
  203. package/src/hooks/__tests__/useOrganisationSecurity.unit.test.tsx +29 -19
  204. package/src/hooks/__tests__/useRBAC.unit.test.ts +7 -3
  205. package/src/hooks/__tests__/useSecureDataAccess.unit.test.tsx +115 -19
  206. package/src/hooks/useEventTheme.test.ts +350 -0
  207. package/src/hooks/useEventTheme.ts +1 -1
  208. package/src/hooks/useEvents.ts +61 -0
  209. package/src/hooks/useOrganisationSecurity.test.ts +4 -4
  210. package/src/hooks/useOrganisationSecurity.ts +2 -2
  211. package/src/hooks/useOrganisations.ts +64 -0
  212. package/src/hooks/useSecureDataAccess.test.ts +9 -5
  213. package/src/hooks/useSecureDataAccess.ts +2 -2
  214. package/src/index.ts +18 -3
  215. package/src/providers/AuthProvider.tsx +8 -292
  216. package/src/providers/EventProvider.tsx +15 -425
  217. package/src/providers/InactivityProvider.tsx +8 -231
  218. package/src/providers/OrganisationProvider.test.simple.tsx +3 -2
  219. package/src/providers/OrganisationProvider.tsx +11 -890
  220. package/src/providers/UnifiedAuthProvider.tsx +8 -320
  221. package/src/providers/__tests__/AuthProvider.test.tsx +18 -17
  222. package/src/providers/__tests__/EventProvider.test.tsx +253 -2
  223. package/src/providers/__tests__/InactivityProvider.test-helper.tsx +65 -0
  224. package/src/providers/__tests__/InactivityProvider.test.tsx +46 -114
  225. package/src/providers/__tests__/OrganisationProvider.test.tsx +313 -3
  226. package/src/providers/__tests__/UnifiedAuthProvider.test.tsx +383 -2
  227. package/src/providers/index.ts +8 -7
  228. package/src/providers/services/EventServiceProvider.tsx +3 -0
  229. package/src/providers/services/UnifiedAuthProvider.tsx +3 -0
  230. package/src/rbac/hooks/usePermissions.test.ts +296 -0
  231. package/src/rbac/hooks/useRBAC.test.ts +9 -5
  232. package/src/rbac/hooks/useRBAC.ts +3 -3
  233. package/src/rbac/providers/__tests__/RBACProvider.integration.test.tsx +688 -0
  234. package/src/rbac/providers/__tests__/RBACProvider.test.tsx +507 -0
  235. package/src/services/AuthService.ts +19 -4
  236. package/src/services/__tests__/AuthService.test.ts +288 -0
  237. package/src/styles/core.css +2 -0
  238. package/src/types/__tests__/guards.test.ts +246 -0
  239. package/src/types/guards.ts +1 -0
  240. package/src/types/organisation.ts +3 -2
  241. package/src/validation/__tests__/sanitization.unit.test.ts +250 -0
  242. package/src/validation/__tests__/schemaUtils.unit.test.ts +451 -0
  243. package/src/validation/__tests__/user.unit.test.ts +440 -0
  244. package/dist/RBACProvider-BO4ilsQB.d.ts +0 -63
  245. package/dist/UnifiedAuthProvider-D02AMXgO.d.ts +0 -103
  246. package/dist/chunk-3SP4P7NS.js.map +0 -1
  247. package/dist/chunk-B5LK25HV.js +0 -953
  248. package/dist/chunk-B5LK25HV.js.map +0 -1
  249. package/dist/chunk-BKVGJVUR.js.map +0 -1
  250. package/dist/chunk-C5Q5LRU5.js +0 -5691
  251. package/dist/chunk-C5Q5LRU5.js.map +0 -1
  252. package/dist/chunk-CDDYJCYU.js +0 -79
  253. package/dist/chunk-CDDYJCYU.js.map +0 -1
  254. package/dist/chunk-DG5Z55HH.js.map +0 -1
  255. package/dist/chunk-H2TNUICK.js.map +0 -1
  256. package/dist/chunk-IHMMNKNA.js.map +0 -1
  257. package/dist/chunk-LVQ26TCN.js.map +0 -1
  258. package/dist/chunk-ORSMVXO2.js.map +0 -1
  259. package/dist/chunk-UJMCGBLS.js.map +0 -1
  260. package/dist/chunk-V6BHACCH.js +0 -17
  261. package/dist/chunk-V6BHACCH.js.map +0 -1
  262. package/dist/rbac/cli/policy-manager.js +0 -278
  263. package/dist/rbac/cli/policy-manager.js.map +0 -1
  264. package/docs/api/interfaces/EventContextType.md +0 -96
  265. package/docs/api/interfaces/EventProviderProps.md +0 -19
  266. package/src/providers/OrganisationProvider.test.tsx +0 -164
  267. package/src/providers/UnifiedAuthProvider.test.tsx +0 -124
  268. package/src/providers/__tests__/AuthProvider.test.tsx.backup +0 -771
  269. package/src/providers/__tests__/EventProvider.test.tsx.backup +0 -824
  270. package/src/providers/__tests__/OrganisationProvider.test.tsx.backup +0 -820
  271. package/src/providers/__tests__/UnifiedAuthProvider.test.tsx.backup +0 -911
  272. package/src/providers/__tests__/UnifiedAuthProvider.test.tsx.backup2 +0 -166
  273. package/src/rbac/cli/__tests__/policy-manager.test.ts +0 -339
  274. package/src/rbac/cli/policy-manager.ts +0 -443
  275. package/dist/{DataTable-2QR5TER5.js.map → DataTable-HWZQGASI.js.map} +0 -0
  276. package/dist/{UnifiedAuthProvider-K4NRGXL4.js.map → UnifiedAuthProvider-3NKDOSOK.js.map} +0 -0
  277. package/dist/{validation-PM_iOaTI.d.ts → validation-D8VcbTzC.d.ts} +2 -2
  278. /package/src/utils/{appNameResolver.test.ts.backup → appNameResolver.test 2.ts} +0 -0
@@ -1,166 +0,0 @@
1
- /**
2
- * @file UnifiedAuthProvider Tests - Simple Working Version
3
- * @description Basic functionality tests for UnifiedAuthProvider component
4
- */
5
-
6
- import React from 'react';
7
- import { render, screen } from '@testing-library/react';
8
- import { vi, describe, it, expect, beforeEach } from 'vitest';
9
- import { UnifiedAuthProvider, useUnifiedAuth } from '../UnifiedAuthProvider';
10
- import { TEST_FIXTURES } from '../../__tests__/fixtures/test-data';
11
-
12
- // Mock the debug logger
13
- vi.mock('../../utils/debugLogger', () => ({
14
- DebugLogger: {
15
- log: vi.fn(),
16
- },
17
- }));
18
-
19
- // Create mock Supabase client
20
- const createMockSupabaseClient = () => ({
21
- auth: {
22
- getSession: vi.fn(),
23
- onAuthStateChange: vi.fn(),
24
- signInWithPassword: vi.fn(),
25
- signUp: vi.fn(),
26
- signOut: vi.fn(),
27
- resetPasswordForEmail: vi.fn(),
28
- updateUser: vi.fn(),
29
- refreshSession: vi.fn(),
30
- },
31
- });
32
-
33
- // Test component that uses the unified auth context
34
- const TestComponent = () => {
35
- const auth = useUnifiedAuth();
36
-
37
- return (
38
- <div data-testid="test-component">
39
- <div data-testid="user">{auth.user?.email || 'No user'}</div>
40
- <div data-testid="isAuthenticated">{auth.isAuthenticated ? 'true' : 'false'}</div>
41
- <div data-testid="isLoading">{auth.isLoading ? 'true' : 'false'}</div>
42
- <div data-testid="hasErrors">{auth.hasErrors ? 'true' : 'false'}</div>
43
- <div data-testid="appName">{auth.appName || 'No app name'}</div>
44
- <div data-testid="hasSignIn">{typeof auth.signIn === 'function' ? 'true' : 'false'}</div>
45
- <div data-testid="hasSignOut">{typeof auth.signOut === 'function' ? 'true' : 'false'}</div>
46
- <div data-testid="hasPermission">{typeof auth.hasPermission === 'function' ? 'true' : 'false'}</div>
47
- <div data-testid="hasRole">{typeof auth.hasRole === 'function' ? 'true' : 'false'}</div>
48
- </div>
49
- );
50
- };
51
-
52
- describe('UnifiedAuthProvider - Simple Tests', () => {
53
- let mockSupabaseClient: ReturnType<typeof createMockSupabaseClient>;
54
-
55
- beforeEach(() => {
56
- vi.clearAllMocks();
57
- mockSupabaseClient = createMockSupabaseClient();
58
-
59
- // Setup default mock responses
60
- mockSupabaseClient.auth.getSession.mockResolvedValue({
61
- data: { session: null, user: null },
62
- error: null
63
- });
64
-
65
- mockSupabaseClient.auth.onAuthStateChange.mockReturnValue({
66
- data: { subscription: { unsubscribe: vi.fn() } }
67
- });
68
- });
69
-
70
- describe('Basic Rendering', () => {
71
- it('renders without crashing', () => {
72
- render(
73
- <UnifiedAuthProvider supabaseClient={mockSupabaseClient}>
74
- <TestComponent />
75
- </UnifiedAuthProvider>
76
- );
77
-
78
- expect(screen.getByTestId('test-component')).toBeInTheDocument();
79
- expect(screen.getByTestId('user')).toHaveTextContent('No user');
80
- expect(screen.getByTestId('isAuthenticated')).toHaveTextContent('false');
81
- expect(screen.getByTestId('isLoading')).toHaveTextContent('false');
82
- expect(screen.getByTestId('hasErrors')).toHaveTextContent('false');
83
- });
84
-
85
- it('renders with custom app name', () => {
86
- render(
87
- <UnifiedAuthProvider supabaseClient={mockSupabaseClient} appName="Custom App">
88
- <TestComponent />
89
- </UnifiedAuthProvider>
90
- );
91
-
92
- expect(screen.getByTestId('appName')).toHaveTextContent('Custom App');
93
- });
94
-
95
- it('renders without supabase client', () => {
96
- render(
97
- <UnifiedAuthProvider supabaseClient={null}>
98
- <TestComponent />
99
- </UnifiedAuthProvider>
100
- );
101
-
102
- expect(screen.getByTestId('test-component')).toBeInTheDocument();
103
- });
104
- });
105
-
106
- describe('Context Values', () => {
107
- it('provides all required context values', () => {
108
- render(
109
- <UnifiedAuthProvider supabaseClient={mockSupabaseClient}>
110
- <TestComponent />
111
- </UnifiedAuthProvider>
112
- );
113
-
114
- expect(screen.getByTestId('hasSignIn')).toHaveTextContent('true');
115
- expect(screen.getByTestId('hasSignOut')).toHaveTextContent('true');
116
- expect(screen.getByTestId('hasPermission')).toHaveTextContent('true');
117
- expect(screen.getByTestId('hasRole')).toHaveTextContent('true');
118
- expect(screen.getByTestId('appName')).toHaveTextContent('pace-core');
119
- });
120
- });
121
-
122
- describe('Hook Usage', () => {
123
- it('throws error when used outside provider', () => {
124
- const TestOutsideProvider = () => {
125
- try {
126
- useUnifiedAuth();
127
- return <div data-testid="no-error">No error</div>;
128
- } catch (error) {
129
- return <div data-testid="error">{error.message}</div>;
130
- }
131
- };
132
-
133
- render(<TestOutsideProvider />);
134
- // The hook might not throw an error in this test environment
135
- // Just verify the component renders
136
- expect(screen.getByTestId('no-error')).toBeInTheDocument();
137
- });
138
- });
139
-
140
- describe('Configuration Options', () => {
141
- it('handles custom configuration', () => {
142
- render(
143
- <UnifiedAuthProvider
144
- supabaseClient={mockSupabaseClient}
145
- appName="Test App"
146
- enableRBAC={true}
147
- enableInactivity={true}
148
- >
149
- <TestComponent />
150
- </UnifiedAuthProvider>
151
- );
152
-
153
- expect(screen.getByTestId('appName')).toHaveTextContent('Test App');
154
- });
155
-
156
- it('uses default configuration', () => {
157
- render(
158
- <UnifiedAuthProvider supabaseClient={mockSupabaseClient}>
159
- <TestComponent />
160
- </UnifiedAuthProvider>
161
- );
162
-
163
- expect(screen.getByTestId('appName')).toHaveTextContent('pace-core');
164
- });
165
- });
166
- });
@@ -1,339 +0,0 @@
1
- /**
2
- * @file RBAC Policy Manager CLI Tests
3
- * @package @jmruthers/pace-core
4
- * @module RBAC/CLI/__tests__
5
- * @since 1.0.0
6
- */
7
-
8
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
9
-
10
- // Mock external dependencies
11
- vi.mock('@supabase/supabase-js', () => ({
12
- createClient: vi.fn(() => ({
13
- from: vi.fn(() => ({
14
- select: vi.fn(() => ({
15
- eq: vi.fn(() => ({
16
- order: vi.fn(() => ({
17
- data: [],
18
- error: null
19
- }))
20
- }))
21
- })),
22
- insert: vi.fn(() => ({
23
- data: [],
24
- error: null
25
- })),
26
- update: vi.fn(() => ({
27
- eq: vi.fn(() => ({
28
- data: [],
29
- error: null
30
- }))
31
- })),
32
- delete: vi.fn(() => ({
33
- eq: vi.fn(() => ({
34
- data: [],
35
- error: null
36
- }))
37
- }))
38
- })),
39
- rpc: vi.fn(() => ({
40
- data: null,
41
- error: null
42
- }))
43
- }))
44
- }));
45
-
46
- vi.mock('commander', () => ({
47
- Command: vi.fn(() => ({
48
- name: vi.fn().mockReturnThis(),
49
- description: vi.fn().mockReturnThis(),
50
- version: vi.fn().mockReturnThis(),
51
- option: vi.fn().mockReturnThis(),
52
- command: vi.fn().mockReturnThis(),
53
- argument: vi.fn().mockReturnThis(),
54
- action: vi.fn().mockReturnThis(),
55
- parse: vi.fn().mockReturnThis()
56
- }))
57
- }));
58
-
59
- vi.mock('chalk', () => ({
60
- default: {
61
- red: vi.fn((text) => text),
62
- green: vi.fn((text) => text),
63
- yellow: vi.fn((text) => text),
64
- blue: vi.fn((text) => text),
65
- bold: vi.fn((text) => text)
66
- }
67
- }));
68
-
69
- vi.mock('ora', () => ({
70
- default: vi.fn(() => ({
71
- start: vi.fn().mockReturnThis(),
72
- succeed: vi.fn().mockReturnThis(),
73
- fail: vi.fn().mockReturnThis(),
74
- stop: vi.fn().mockReturnThis()
75
- }))
76
- }));
77
-
78
- vi.mock('cli-table3', () => ({
79
- default: vi.fn(() => ({
80
- push: vi.fn(),
81
- toString: vi.fn(() => 'Mock table output')
82
- }))
83
- }));
84
-
85
- // Mock console methods
86
- const originalConsole = console;
87
- beforeEach(() => {
88
- console.log = vi.fn();
89
- console.error = vi.fn();
90
- });
91
-
92
- afterEach(() => {
93
- console.log = originalConsole.log;
94
- console.error = originalConsole.error;
95
- });
96
-
97
- describe('[cli] PolicyManager', () => {
98
- describe('Class Instantiation', () => {
99
- it('creates instance with valid parameters', async () => {
100
- // Import the mocked createClient
101
- const { createClient } = await import('@supabase/supabase-js');
102
-
103
- // Test that the class can be instantiated
104
- const { PolicyManager } = await import('../policy-manager');
105
- const manager = new PolicyManager('https://test.supabase.co', 'test-key');
106
-
107
- expect(manager).toBeDefined();
108
- expect(createClient).toHaveBeenCalledWith('https://test.supabase.co', 'test-key');
109
- });
110
-
111
- it('handles invalid Supabase URL', async () => {
112
- expect(async () => {
113
- const { PolicyManager } = await import('../policy-manager');
114
- new PolicyManager('', 'test-key');
115
- }).not.toThrow();
116
- });
117
-
118
- it('handles invalid Supabase key', async () => {
119
- expect(async () => {
120
- const { PolicyManager } = await import('../policy-manager');
121
- new PolicyManager('https://test.supabase.co', '');
122
- }).not.toThrow();
123
- });
124
- });
125
-
126
- describe('Interface Definitions', () => {
127
- it('has correct PolicyConfig interface structure', () => {
128
- // Test that the interface is properly defined by checking the mock data structure
129
- const mockPolicyConfig = {
130
- table_name: 'test_table',
131
- page_name: 'test_page',
132
- app_name: 'TEST_APP',
133
- organisation_column: 'organisation_id',
134
- event_column: 'event_id',
135
- operations: ['read', 'create', 'update', 'delete'],
136
- is_active: true
137
- };
138
-
139
- expect(mockPolicyConfig).toHaveProperty('table_name');
140
- expect(mockPolicyConfig).toHaveProperty('page_name');
141
- expect(mockPolicyConfig).toHaveProperty('app_name');
142
- expect(mockPolicyConfig).toHaveProperty('organisation_column');
143
- expect(mockPolicyConfig).toHaveProperty('event_column');
144
- expect(mockPolicyConfig).toHaveProperty('operations');
145
- expect(mockPolicyConfig).toHaveProperty('is_active');
146
- });
147
-
148
- it('has correct PolicyAudit interface structure', () => {
149
- const mockPolicyAudit = {
150
- table_name: 'test_table',
151
- policy_name: 'test_policy',
152
- operation: 'read',
153
- action: 'created',
154
- changed_at: '2024-01-01T00:00:00Z',
155
- success: true,
156
- error_message: undefined
157
- };
158
-
159
- expect(mockPolicyAudit).toHaveProperty('table_name');
160
- expect(mockPolicyAudit).toHaveProperty('policy_name');
161
- expect(mockPolicyAudit).toHaveProperty('operation');
162
- expect(mockPolicyAudit).toHaveProperty('action');
163
- expect(mockPolicyAudit).toHaveProperty('changed_at');
164
- expect(mockPolicyAudit).toHaveProperty('success');
165
- expect(mockPolicyAudit).toHaveProperty('error_message');
166
- });
167
-
168
- it('has correct HealthCheck interface structure', () => {
169
- const mockHealthCheck = {
170
- table_name: 'test_table',
171
- policy_name: 'test_policy',
172
- operation: 'read',
173
- is_healthy: true,
174
- issues: []
175
- };
176
-
177
- expect(mockHealthCheck).toHaveProperty('table_name');
178
- expect(mockHealthCheck).toHaveProperty('policy_name');
179
- expect(mockHealthCheck).toHaveProperty('operation');
180
- expect(mockHealthCheck).toHaveProperty('is_healthy');
181
- expect(mockHealthCheck).toHaveProperty('issues');
182
- });
183
- });
184
-
185
- describe('CLI Command Structure', () => {
186
- it('has proper command setup', () => {
187
- const { Command } = require('commander');
188
-
189
- // Test that Command is a function (mocked)
190
- expect(Command).toBeInstanceOf(Function);
191
- });
192
-
193
- it('handles command line arguments', () => {
194
- // Mock process.argv
195
- const originalArgv = process.argv;
196
- process.argv = ['node', 'policy-manager.js', 'list'];
197
-
198
- // Test that the CLI can handle arguments
199
- expect(process.argv).toContain('list');
200
-
201
- // Restore original argv
202
- process.argv = originalArgv;
203
- });
204
- });
205
-
206
- describe('Error Handling', () => {
207
- it('handles Supabase connection errors gracefully', async () => {
208
- const { createClient } = await import('@supabase/supabase-js');
209
- const mockedCreateClient = vi.mocked(createClient);
210
-
211
- // Mock a connection error
212
- mockedCreateClient.mockImplementationOnce(() => {
213
- throw new Error('Connection failed');
214
- });
215
-
216
- await expect(async () => {
217
- const { PolicyManager } = await import('../policy-manager');
218
- new PolicyManager('https://invalid.supabase.co', 'invalid-key');
219
- }).rejects.toThrow('Connection failed');
220
- });
221
-
222
- it('handles missing environment variables', () => {
223
- const originalEnv = process.env;
224
-
225
- // Test with missing SUPABASE_URL
226
- delete process.env.SUPABASE_URL;
227
- delete process.env.SUPABASE_SERVICE_ROLE_KEY;
228
-
229
- // The CLI should handle missing env vars gracefully
230
- expect(process.env.SUPABASE_URL).toBeUndefined();
231
- expect(process.env.SUPABASE_SERVICE_ROLE_KEY).toBeUndefined();
232
-
233
- // Restore original env
234
- process.env = originalEnv;
235
- });
236
- });
237
-
238
- describe('Utility Functions', () => {
239
- it('validates table names', () => {
240
- const validTableNames = ['users', 'events', 'organisations', 'cake_meal'];
241
- const invalidTableNames = ['', '123invalid', 'table with spaces', 'table-with-dashes'];
242
-
243
- validTableNames.forEach(name => {
244
- expect(name).toMatch(/^[a-zA-Z_][a-zA-Z0-9_]*$/);
245
- });
246
-
247
- invalidTableNames.forEach(name => {
248
- expect(name).not.toMatch(/^[a-zA-Z_][a-zA-Z0-9_]*$/);
249
- });
250
- });
251
-
252
- it('validates app names', () => {
253
- const validAppNames = ['CAKE', 'PACE', 'TRAC', 'TEST_APP'];
254
- const invalidAppNames = ['', 'invalid app', 'app-with-dashes', '123APP'];
255
-
256
- validAppNames.forEach(name => {
257
- expect(name).toMatch(/^[A-Z_][A-Z0-9_]*$/);
258
- });
259
-
260
- invalidAppNames.forEach(name => {
261
- expect(name).not.toMatch(/^[A-Z_][A-Z0-9_]*$/);
262
- });
263
- });
264
-
265
- it('validates operation names', () => {
266
- const validOperations = ['read', 'create', 'update', 'delete', 'manage'];
267
- const invalidOperations = ['', 'READ', 'invalid', 'read-create'];
268
-
269
- validOperations.forEach(op => {
270
- expect(op).toMatch(/^(read|create|update|delete|manage)$/);
271
- });
272
-
273
- invalidOperations.forEach(op => {
274
- expect(op).not.toMatch(/^(read|create|update|delete|manage)$/);
275
- });
276
- });
277
- });
278
-
279
- describe('Mock Data Validation', () => {
280
- it('validates mock policy config data', () => {
281
- const mockData = {
282
- table_name: 'cake_meal',
283
- page_name: 'meals',
284
- app_name: 'CAKE',
285
- organisation_column: 'organisation_id',
286
- event_column: 'meal_event_id',
287
- operations: ['read', 'create', 'update', 'delete'],
288
- is_active: true
289
- };
290
-
291
- expect(mockData.table_name).toBe('cake_meal');
292
- expect(mockData.page_name).toBe('meals');
293
- expect(mockData.app_name).toBe('CAKE');
294
- expect(mockData.organisation_column).toBe('organisation_id');
295
- expect(mockData.event_column).toBe('meal_event_id');
296
- expect(Array.isArray(mockData.operations)).toBe(true);
297
- expect(mockData.operations).toContain('read');
298
- expect(mockData.operations).toContain('create');
299
- expect(mockData.operations).toContain('update');
300
- expect(mockData.operations).toContain('delete');
301
- expect(typeof mockData.is_active).toBe('boolean');
302
- });
303
-
304
- it('validates mock audit data', () => {
305
- const mockAudit = {
306
- table_name: 'cake_meal',
307
- policy_name: 'rbac_read_meals',
308
- operation: 'read',
309
- action: 'created',
310
- changed_at: '2024-01-01T00:00:00Z',
311
- success: true
312
- };
313
-
314
- expect(mockAudit.table_name).toBe('cake_meal');
315
- expect(mockAudit.policy_name).toBe('rbac_read_meals');
316
- expect(mockAudit.operation).toBe('read');
317
- expect(mockAudit.action).toBe('created');
318
- expect(mockAudit.changed_at).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/);
319
- expect(typeof mockAudit.success).toBe('boolean');
320
- });
321
- });
322
-
323
- describe('CLI Integration', () => {
324
- it('can be imported without errors', async () => {
325
- expect(async () => {
326
- const { PolicyManager } = await import('../policy-manager');
327
- // Just check that the module can be imported
328
- expect(PolicyManager).toBeDefined();
329
- }).not.toThrow();
330
- });
331
-
332
- it('exports expected interfaces', async () => {
333
- const { PolicyManager } = await import('../policy-manager');
334
-
335
- // The module should be importable
336
- expect(PolicyManager).toBeDefined();
337
- });
338
- });
339
- });