@open-mercato/core 0.4.9-develop-e55592929f → 0.4.9-develop-97d4cca067

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 (86) hide show
  1. package/dist/helpers/integration/api.js +66 -0
  2. package/dist/helpers/integration/api.js.map +7 -0
  3. package/dist/helpers/integration/apiKeysFixtures.js +16 -0
  4. package/dist/helpers/integration/apiKeysFixtures.js.map +7 -0
  5. package/dist/helpers/integration/attachmentsFixtures.js +61 -0
  6. package/dist/helpers/integration/attachmentsFixtures.js.map +7 -0
  7. package/dist/helpers/integration/auth.js +190 -0
  8. package/dist/helpers/integration/auth.js.map +7 -0
  9. package/dist/helpers/integration/authFixtures.js +39 -0
  10. package/dist/helpers/integration/authFixtures.js.map +7 -0
  11. package/dist/helpers/integration/authUi.js +31 -0
  12. package/dist/helpers/integration/authUi.js.map +7 -0
  13. package/dist/helpers/integration/businessRulesFixtures.js +40 -0
  14. package/dist/helpers/integration/businessRulesFixtures.js.map +7 -0
  15. package/dist/helpers/integration/catalogFixtures.js +49 -0
  16. package/dist/helpers/integration/catalogFixtures.js.map +7 -0
  17. package/dist/helpers/integration/crmFixtures.js +91 -0
  18. package/dist/helpers/integration/crmFixtures.js.map +7 -0
  19. package/dist/helpers/integration/currenciesFixtures.js +39 -0
  20. package/dist/helpers/integration/currenciesFixtures.js.map +7 -0
  21. package/dist/helpers/integration/dictionariesFixtures.js +16 -0
  22. package/dist/helpers/integration/dictionariesFixtures.js.map +7 -0
  23. package/dist/helpers/integration/featureTogglesFixtures.js +23 -0
  24. package/dist/helpers/integration/featureTogglesFixtures.js.map +7 -0
  25. package/dist/helpers/integration/generalFixtures.js +56 -0
  26. package/dist/helpers/integration/generalFixtures.js.map +7 -0
  27. package/dist/helpers/integration/inboxFixtures.js +67 -0
  28. package/dist/helpers/integration/inboxFixtures.js.map +7 -0
  29. package/dist/helpers/integration/notificationsFixtures.js +48 -0
  30. package/dist/helpers/integration/notificationsFixtures.js.map +7 -0
  31. package/dist/helpers/integration/salesFixtures.js +63 -0
  32. package/dist/helpers/integration/salesFixtures.js.map +7 -0
  33. package/dist/helpers/integration/salesUi.js +827 -0
  34. package/dist/helpers/integration/salesUi.js.map +7 -0
  35. package/dist/helpers/integration/sseEventCollector.js +27 -0
  36. package/dist/helpers/integration/sseEventCollector.js.map +7 -0
  37. package/dist/helpers/integration/staffFixtures.js +47 -0
  38. package/dist/helpers/integration/staffFixtures.js.map +7 -0
  39. package/dist/modules/auth/lib/setup-app.js +17 -1
  40. package/dist/modules/auth/lib/setup-app.js.map +2 -2
  41. package/dist/testing/integration/api.js +2 -0
  42. package/dist/testing/integration/api.js.map +7 -0
  43. package/dist/testing/integration/auth.js +2 -0
  44. package/dist/testing/integration/auth.js.map +7 -0
  45. package/dist/testing/integration/authFixtures.js +2 -0
  46. package/dist/testing/integration/authFixtures.js.map +7 -0
  47. package/dist/testing/integration/authUi.js +2 -0
  48. package/dist/testing/integration/authUi.js.map +7 -0
  49. package/dist/testing/integration/crmFixtures.js +2 -0
  50. package/dist/testing/integration/crmFixtures.js.map +7 -0
  51. package/dist/testing/integration/dictionariesFixtures.js +2 -0
  52. package/dist/testing/integration/dictionariesFixtures.js.map +7 -0
  53. package/dist/testing/integration/generalFixtures.js +2 -0
  54. package/dist/testing/integration/generalFixtures.js.map +7 -0
  55. package/dist/testing/integration/index.js +48 -0
  56. package/dist/testing/integration/index.js.map +7 -0
  57. package/package.json +11 -3
  58. package/src/helpers/integration/api.ts +87 -0
  59. package/src/helpers/integration/apiKeysFixtures.ts +17 -0
  60. package/src/helpers/integration/attachmentsFixtures.ts +114 -0
  61. package/src/helpers/integration/auth.ts +208 -0
  62. package/src/helpers/integration/authFixtures.ts +52 -0
  63. package/src/helpers/integration/authUi.ts +33 -0
  64. package/src/helpers/integration/businessRulesFixtures.ts +53 -0
  65. package/src/helpers/integration/catalogFixtures.ts +73 -0
  66. package/src/helpers/integration/crmFixtures.ts +132 -0
  67. package/src/helpers/integration/currenciesFixtures.ts +49 -0
  68. package/src/helpers/integration/dictionariesFixtures.ts +17 -0
  69. package/src/helpers/integration/featureTogglesFixtures.ts +28 -0
  70. package/src/helpers/integration/generalFixtures.ts +71 -0
  71. package/src/helpers/integration/inboxFixtures.ts +94 -0
  72. package/src/helpers/integration/notificationsFixtures.ts +67 -0
  73. package/src/helpers/integration/salesFixtures.ts +89 -0
  74. package/src/helpers/integration/salesUi.ts +936 -0
  75. package/src/helpers/integration/sseEventCollector.ts +30 -0
  76. package/src/helpers/integration/staffFixtures.ts +61 -0
  77. package/src/modules/auth/lib/setup-app.ts +22 -0
  78. package/src/testing/integration/api.ts +1 -0
  79. package/src/testing/integration/auth.ts +1 -0
  80. package/src/testing/integration/authFixtures.ts +1 -0
  81. package/src/testing/integration/authUi.ts +1 -0
  82. package/src/testing/integration/crmFixtures.ts +1 -0
  83. package/src/testing/integration/dictionariesFixtures.ts +1 -0
  84. package/src/testing/integration/generalFixtures.ts +1 -0
  85. package/src/testing/integration/index.ts +22 -0
  86. package/tsconfig.json +3 -0
@@ -0,0 +1,30 @@
1
+ import type { Page } from '@playwright/test'
2
+
3
+ const OM_EVENT_NAME = 'om:event'
4
+ const CAPTURED_EVENTS_KEY = '__capturedOmEvents'
5
+
6
+ export type CapturedEvent = {
7
+ id: string
8
+ payload?: Record<string, unknown>
9
+ }
10
+
11
+ export async function installOmEventCollector(page: Page): Promise<void> {
12
+ await page.evaluate(({ eventName, storageKey }) => {
13
+ ;(window as unknown as Record<string, unknown>)[storageKey] = []
14
+ window.addEventListener(eventName, (event: Event) => {
15
+ const detail = (event as CustomEvent<CapturedEvent>).detail
16
+ if (!detail || typeof detail !== 'object') return
17
+ const store = (window as unknown as Record<string, unknown>)[storageKey]
18
+ if (!Array.isArray(store)) return
19
+ store.push(detail)
20
+ })
21
+ }, { eventName: OM_EVENT_NAME, storageKey: CAPTURED_EVENTS_KEY })
22
+ }
23
+
24
+ export async function getCapturedOmEvents(page: Page): Promise<CapturedEvent[]> {
25
+ return page.evaluate((storageKey) => {
26
+ const store = (window as unknown as Record<string, unknown>)[storageKey]
27
+ if (!Array.isArray(store)) return []
28
+ return store as CapturedEvent[]
29
+ }, CAPTURED_EVENTS_KEY)
30
+ }
@@ -0,0 +1,61 @@
1
+ import { expect, type APIRequestContext } from '@playwright/test';
2
+ import { apiRequest } from './api';
3
+
4
+ export async function createStaffTeamFixture(
5
+ request: APIRequestContext,
6
+ token: string,
7
+ name?: string,
8
+ ): Promise<string> {
9
+ const response = await apiRequest(request, 'POST', '/api/staff/teams', {
10
+ token,
11
+ data: { name: name ?? `QA Team ${Date.now()}` },
12
+ });
13
+ expect(response.ok(), `Failed to create staff team fixture: ${response.status()}`).toBeTruthy();
14
+ const body = (await response.json()) as { id?: string };
15
+ expect(typeof body.id === 'string' && body.id.length > 0).toBeTruthy();
16
+ return body.id as string;
17
+ }
18
+
19
+ export async function createStaffTeamMemberFixture(
20
+ request: APIRequestContext,
21
+ token: string,
22
+ input?: { displayName?: string },
23
+ ): Promise<string> {
24
+ const response = await apiRequest(request, 'POST', '/api/staff/team-members', {
25
+ token,
26
+ data: { displayName: input?.displayName ?? `QA Member ${Date.now()}` },
27
+ });
28
+ expect(response.ok(), `Failed to create staff team member fixture: ${response.status()}`).toBeTruthy();
29
+ const body = (await response.json()) as { id?: string };
30
+ expect(typeof body.id === 'string' && body.id.length > 0).toBeTruthy();
31
+ return body.id as string;
32
+ }
33
+
34
+ export async function createStaffTeamRoleFixture(
35
+ request: APIRequestContext,
36
+ token: string,
37
+ input?: { name?: string },
38
+ ): Promise<string> {
39
+ const response = await apiRequest(request, 'POST', '/api/staff/team-roles', {
40
+ token,
41
+ data: { name: input?.name ?? `QA Role ${Date.now()}` },
42
+ });
43
+ expect(response.ok(), `Failed to create staff team role fixture: ${response.status()}`).toBeTruthy();
44
+ const body = (await response.json()) as { id?: string };
45
+ expect(typeof body.id === 'string' && body.id.length > 0).toBeTruthy();
46
+ return body.id as string;
47
+ }
48
+
49
+ export async function deleteStaffEntityIfExists(
50
+ request: APIRequestContext,
51
+ token: string | null,
52
+ path: string,
53
+ id: string | null,
54
+ ): Promise<void> {
55
+ if (!token || !id) return;
56
+ try {
57
+ await apiRequest(request, 'DELETE', `${path}?id=${encodeURIComponent(id)}`, { token });
58
+ } catch {
59
+ return;
60
+ }
61
+ }
@@ -411,9 +411,11 @@ async function ensureDefaultRoleAcls(
411
411
  const employeeRole = await findRoleByName(em, 'employee', roleTenantId)
412
412
 
413
413
  // Merge features from all enabled modules' setup configs
414
+ const builtInRoles = ['superadmin', 'admin', 'employee'] as const
414
415
  const superadminFeatures: string[] = []
415
416
  const adminFeatures: string[] = []
416
417
  const employeeFeatures: string[] = []
418
+ const customRoleFeatures = new Map<string, string[]>()
417
419
 
418
420
  for (const mod of modules) {
419
421
  const roleFeatures = mod.setup?.defaultRoleFeatures
@@ -421,12 +423,24 @@ async function ensureDefaultRoleAcls(
421
423
  if (roleFeatures.superadmin) superadminFeatures.push(...roleFeatures.superadmin)
422
424
  if (roleFeatures.admin) adminFeatures.push(...roleFeatures.admin)
423
425
  if (roleFeatures.employee) employeeFeatures.push(...roleFeatures.employee)
426
+
427
+ // Collect features for custom roles (any key not in builtInRoles)
428
+ for (const [roleName, features] of Object.entries(roleFeatures)) {
429
+ if ((builtInRoles as readonly string[]).includes(roleName)) continue
430
+ if (!Array.isArray(features)) continue
431
+ const existing = customRoleFeatures.get(roleName) ?? []
432
+ existing.push(...features)
433
+ customRoleFeatures.set(roleName, existing)
434
+ }
424
435
  }
425
436
 
426
437
  console.log('✅ Seeded default role features', {
427
438
  superadmin: superadminFeatures,
428
439
  admin: adminFeatures,
429
440
  employee: employeeFeatures,
441
+ ...(customRoleFeatures.size > 0
442
+ ? Object.fromEntries(customRoleFeatures)
443
+ : {}),
430
444
  })
431
445
 
432
446
  if (includeSuperadminRole && superadminRole) {
@@ -438,6 +452,14 @@ async function ensureDefaultRoleAcls(
438
452
  if (employeeRole) {
439
453
  await ensureRoleAclFor(em, employeeRole, tenantId, employeeFeatures)
440
454
  }
455
+
456
+ // Seed ACLs for custom roles defined by app modules
457
+ for (const [roleName, features] of customRoleFeatures) {
458
+ const role = await findRoleByName(em, roleName, roleTenantId)
459
+ if (role) {
460
+ await ensureRoleAclFor(em, role, tenantId, features)
461
+ }
462
+ }
441
463
  }
442
464
 
443
465
  async function ensureRoleAclFor(
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/api'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/auth'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/authFixtures'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/authUi'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/crmFixtures'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/dictionariesFixtures'
@@ -0,0 +1 @@
1
+ export * from '../../helpers/integration/generalFixtures'
@@ -0,0 +1,22 @@
1
+ export { getAuthToken, apiRequest, postForm } from '../../helpers/integration/api'
2
+ export { DEFAULT_CREDENTIALS, type Role } from '../../helpers/integration/auth'
3
+ export { createUserViaUi } from '../../helpers/integration/authUi'
4
+ export {
5
+ createCompanyFixture,
6
+ createPersonFixture,
7
+ createDealFixture,
8
+ createPipelineFixture,
9
+ createPipelineStageFixture,
10
+ deleteEntityByBody,
11
+ deleteEntityIfExists,
12
+ } from '../../helpers/integration/crmFixtures'
13
+ export {
14
+ readJsonSafe,
15
+ getTokenContext,
16
+ getTokenScope,
17
+ expectId,
18
+ deleteEntityByPathIfExists,
19
+ deleteGeneralEntityIfExists,
20
+ } from '../../helpers/integration/generalFixtures'
21
+ export { createDictionaryFixture } from '../../helpers/integration/dictionariesFixtures'
22
+ export { createRoleFixture, deleteRoleIfExists, createUserFixture, deleteUserIfExists } from '../../helpers/integration/authFixtures'
package/tsconfig.json CHANGED
@@ -7,6 +7,9 @@
7
7
  "paths": {
8
8
  "@open-mercato/core/modules/core/__integration__/helpers/*": [
9
9
  "./src/modules/core/__integration__/helpers/*"
10
+ ],
11
+ "@open-mercato/core/helpers/integration/*": [
12
+ "./src/helpers/integration/*"
10
13
  ]
11
14
  }
12
15
  },