@latte-macchiat-io/latte-payload 1.0.1
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/.claude/settings.local.json +9 -0
- package/.env.example +29 -0
- package/.github/workflows/ci.yml +160 -0
- package/.github/workflows/publish.yml +126 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc +11 -0
- package/CHANGELOG.md +87 -0
- package/README.md +364 -0
- package/TESTING_AND_DOCUMENTATION_SETUP.md +348 -0
- package/dist/access/adminAccessOnly.d.ts +25 -0
- package/dist/access/adminAccessOnly.d.ts.map +1 -0
- package/dist/access/adminAccessOnly.js +11 -0
- package/dist/access/adminAccessOnly.js.map +1 -0
- package/dist/access/admins.d.ts +72 -0
- package/dist/access/admins.d.ts.map +1 -0
- package/dist/access/admins.js +76 -0
- package/dist/access/admins.js.map +1 -0
- package/dist/access/anyone.d.ts +35 -0
- package/dist/access/anyone.d.ts.map +1 -0
- package/dist/access/anyone.js +34 -0
- package/dist/access/anyone.js.map +1 -0
- package/dist/access/authenticated.d.ts +63 -0
- package/dist/access/authenticated.d.ts.map +1 -0
- package/dist/access/authenticated.js +68 -0
- package/dist/access/authenticated.js.map +1 -0
- package/dist/access/authenticatedAccessOnly.d.ts +13 -0
- package/dist/access/authenticatedAccessOnly.d.ts.map +1 -0
- package/dist/access/authenticatedAccessOnly.js +11 -0
- package/dist/access/authenticatedAccessOnly.js.map +1 -0
- package/dist/access/index.d.ts +7 -0
- package/dist/access/index.d.ts.map +1 -0
- package/dist/access/index.js +7 -0
- package/dist/access/index.js.map +1 -0
- package/dist/access/publicReadAuthenticatedAccess.d.ts +13 -0
- package/dist/access/publicReadAuthenticatedAccess.d.ts.map +1 -0
- package/dist/access/publicReadAuthenticatedAccess.js +12 -0
- package/dist/access/publicReadAuthenticatedAccess.js.map +1 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts +31 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.d.ts.map +1 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.js +29 -0
- package/dist/collections/ContactMessages/hooks/sendEmailNotification.js.map +1 -0
- package/dist/collections/ContactMessages/index.d.ts +27 -0
- package/dist/collections/ContactMessages/index.d.ts.map +1 -0
- package/dist/collections/ContactMessages/index.js +81 -0
- package/dist/collections/ContactMessages/index.js.map +1 -0
- package/dist/collections/EmailTemplates/index.d.ts +26 -0
- package/dist/collections/EmailTemplates/index.d.ts.map +1 -0
- package/dist/collections/EmailTemplates/index.js +74 -0
- package/dist/collections/EmailTemplates/index.js.map +1 -0
- package/dist/collections/Media/index.d.ts +3 -0
- package/dist/collections/Media/index.d.ts.map +1 -0
- package/dist/collections/Media/index.js +22 -0
- package/dist/collections/Media/index.js.map +1 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts +3 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.js +11 -0
- package/dist/collections/QueuedEmails/components/HtmlViewer.js.map +1 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts +2 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.js +79 -0
- package/dist/collections/QueuedEmails/components/RetryEmailButtons.js.map +1 -0
- package/dist/collections/QueuedEmails/index.d.ts +3 -0
- package/dist/collections/QueuedEmails/index.d.ts.map +1 -0
- package/dist/collections/QueuedEmails/index.js +245 -0
- package/dist/collections/QueuedEmails/index.js.map +1 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.d.ts +51 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.d.ts.map +1 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.js +90 -0
- package/dist/collections/Users/auth-emails/forgot-password-email.js.map +1 -0
- package/dist/collections/Users/auth-emails/verify-email.d.ts +51 -0
- package/dist/collections/Users/auth-emails/verify-email.d.ts.map +1 -0
- package/dist/collections/Users/auth-emails/verify-email.js +80 -0
- package/dist/collections/Users/auth-emails/verify-email.js.map +1 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts +3 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.d.ts.map +1 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js +19 -0
- package/dist/collections/Users/hooks/ensureFirstUserIsAdmin.js.map +1 -0
- package/dist/collections/Users/index.d.ts +76 -0
- package/dist/collections/Users/index.d.ts.map +1 -0
- package/dist/collections/Users/index.js +116 -0
- package/dist/collections/Users/index.js.map +1 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/index.js +14 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/forms/states.d.ts +8 -0
- package/dist/forms/states.d.ts.map +1 -0
- package/dist/forms/states.js +16 -0
- package/dist/forms/states.js.map +1 -0
- package/dist/forms/translate-errors.d.ts +8 -0
- package/dist/forms/translate-errors.d.ts.map +1 -0
- package/dist/forms/translate-errors.js +11 -0
- package/dist/forms/translate-errors.js.map +1 -0
- package/dist/forms/validators.d.ts +10 -0
- package/dist/forms/validators.d.ts.map +1 -0
- package/dist/forms/validators.js +23 -0
- package/dist/forms/validators.js.map +1 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts +2 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.d.ts.map +1 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js +5 -0
- package/dist/globals/PrivacyPolicy/hooks/revalidate-cache.js.map +1 -0
- package/dist/globals/PrivacyPolicy/index.d.ts +3 -0
- package/dist/globals/PrivacyPolicy/index.d.ts.map +1 -0
- package/dist/globals/PrivacyPolicy/index.js +31 -0
- package/dist/globals/PrivacyPolicy/index.js.map +1 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts +2 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.d.ts.map +1 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.js +5 -0
- package/dist/globals/TermsOfUse/hooks/revalidate-cache.js.map +1 -0
- package/dist/globals/TermsOfUse/index.d.ts +3 -0
- package/dist/globals/TermsOfUse/index.d.ts.map +1 -0
- package/dist/globals/TermsOfUse/index.js +31 -0
- package/dist/globals/TermsOfUse/index.js.map +1 -0
- package/dist/globals/index.d.ts +3 -0
- package/dist/globals/index.d.ts.map +1 -0
- package/dist/globals/index.js +3 -0
- package/dist/globals/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/process-email-queue.d.ts +46 -0
- package/dist/tasks/process-email-queue.d.ts.map +1 -0
- package/dist/tasks/process-email-queue.js +199 -0
- package/dist/tasks/process-email-queue.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/slug.d.ts +2 -0
- package/dist/types/slug.d.ts.map +1 -0
- package/dist/types/slug.js +11 -0
- package/dist/types/slug.js.map +1 -0
- package/dist/utils/database-dates.d.ts +3 -0
- package/dist/utils/database-dates.d.ts.map +1 -0
- package/dist/utils/database-dates.js +6 -0
- package/dist/utils/database-dates.js.map +1 -0
- package/dist/utils/email/generate-email-html.d.ts +23 -0
- package/dist/utils/email/generate-email-html.d.ts.map +1 -0
- package/dist/utils/email/generate-email-html.js +42 -0
- package/dist/utils/email/generate-email-html.js.map +1 -0
- package/dist/utils/email/get-email-template.d.ts +8 -0
- package/dist/utils/email/get-email-template.d.ts.map +1 -0
- package/dist/utils/email/get-email-template.js +14 -0
- package/dist/utils/email/get-email-template.js.map +1 -0
- package/dist/utils/email/index.d.ts +4 -0
- package/dist/utils/email/index.d.ts.map +1 -0
- package/dist/utils/email/index.js +4 -0
- package/dist/utils/email/index.js.map +1 -0
- package/dist/utils/email/queue-email.d.ts +29 -0
- package/dist/utils/email/queue-email.d.ts.map +1 -0
- package/dist/utils/email/queue-email.js +79 -0
- package/dist/utils/email/queue-email.js.map +1 -0
- package/dist/utils/get-global.d.ts +6 -0
- package/dist/utils/get-global.d.ts.map +1 -0
- package/dist/utils/get-global.js +20 -0
- package/dist/utils/get-global.js.map +1 -0
- package/dist/utils/id-from-payload.d.ts +4 -0
- package/dist/utils/id-from-payload.d.ts.map +1 -0
- package/dist/utils/id-from-payload.js +10 -0
- package/dist/utils/id-from-payload.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/migrations.d.ts +2 -0
- package/dist/utils/migrations.d.ts.map +1 -0
- package/dist/utils/migrations.js +18 -0
- package/dist/utils/migrations.js.map +1 -0
- package/dist/utils/payload-client.d.ts +10 -0
- package/dist/utils/payload-client.d.ts.map +1 -0
- package/dist/utils/payload-client.js +14 -0
- package/dist/utils/payload-client.js.map +1 -0
- package/dist/utils/slugify.d.ts +8 -0
- package/dist/utils/slugify.d.ts.map +1 -0
- package/dist/utils/slugify.js +15 -0
- package/dist/utils/slugify.js.map +1 -0
- package/eslint.config.mjs +90 -0
- package/package.json +139 -0
- package/pnpm-workspace.yaml +4 -0
- package/src/access/adminAccessOnly.ts +13 -0
- package/src/access/admins.ts +78 -0
- package/src/access/anyone.ts +35 -0
- package/src/access/authenticated.ts +70 -0
- package/src/access/authenticatedAccessOnly.ts +13 -0
- package/src/access/index.ts +6 -0
- package/src/access/publicReadAuthenticatedAccess.ts +14 -0
- package/src/collections/ContactMessages/hooks/sendEmailNotification.ts +58 -0
- package/src/collections/ContactMessages/index.ts +100 -0
- package/src/collections/EmailTemplates/index.ts +89 -0
- package/src/collections/Media/index.ts +24 -0
- package/src/collections/QueuedEmails/components/HtmlViewer.tsx +16 -0
- package/src/collections/QueuedEmails/components/RetryEmailButtons.tsx +115 -0
- package/src/collections/QueuedEmails/index.ts +246 -0
- package/src/collections/Users/auth-emails/forgot-password-email.ts +135 -0
- package/src/collections/Users/auth-emails/verify-email.ts +123 -0
- package/src/collections/Users/hooks/ensureFirstUserIsAdmin.ts +22 -0
- package/src/collections/Users/index.ts +201 -0
- package/src/collections/index.ts +23 -0
- package/src/components/index.ts +3 -0
- package/src/forms/states.ts +23 -0
- package/src/forms/translate-errors.ts +13 -0
- package/src/forms/validators.ts +33 -0
- package/src/globals/PrivacyPolicy/hooks/revalidate-cache.ts +5 -0
- package/src/globals/PrivacyPolicy/index.ts +33 -0
- package/src/globals/TermsOfUse/hooks/revalidate-cache.ts +5 -0
- package/src/globals/TermsOfUse/index.ts +33 -0
- package/src/globals/index.ts +2 -0
- package/src/index.ts +26 -0
- package/src/tasks/index.ts +7 -0
- package/src/tasks/process-email-queue.ts +261 -0
- package/src/types/index.ts +15 -0
- package/src/types/slug.ts +11 -0
- package/src/utils/database-dates.ts +6 -0
- package/src/utils/email/generate-email-html.ts +63 -0
- package/src/utils/email/get-email-template.ts +18 -0
- package/src/utils/email/index.ts +3 -0
- package/src/utils/email/queue-email.ts +109 -0
- package/src/utils/get-global.ts +25 -0
- package/src/utils/id-from-payload.ts +11 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/migrations.ts +18 -0
- package/src/utils/payload-client.ts +16 -0
- package/src/utils/slugify.ts +21 -0
- package/tests/fixtures/email-template.html +58 -0
- package/tests/fixtures/sample-data.ts +56 -0
- package/tests/helpers/create-test-user.ts +37 -0
- package/tests/helpers/init-payload.ts +59 -0
- package/tests/setup.integration.ts +9 -0
- package/tests/setup.ts +4 -0
- package/tests/unit/access/adminAccessOnly.spec.ts +117 -0
- package/tests/unit/access/admins.spec.ts +68 -0
- package/tests/unit/access/anyone.spec.ts +28 -0
- package/tests/unit/access/authenticated.spec.ts +53 -0
- package/tests/unit/access/authenticatedAccessOnly.spec.ts +112 -0
- package/tests/unit/access/publicReadAuthenticatedAccess.spec.ts +112 -0
- package/tests/unit/forms/validators.spec.ts +348 -0
- package/tests/unit/utils/database-dates.spec.ts +97 -0
- package/tests/unit/utils/id-from-payload.spec.ts +142 -0
- package/tests/unit/utils/slugify.spec.ts +185 -0
- package/tsconfig.json +31 -0
- package/typedoc.json +40 -0
- package/vitest.config.ts +31 -0
- package/vitest.integration.config.ts +27 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { admins, adminsFieldLevel } from '@/access/admins';
|
|
3
|
+
|
|
4
|
+
describe('admins access control', () => {
|
|
5
|
+
describe('admins', () => {
|
|
6
|
+
it('should return true for users with admin role', () => {
|
|
7
|
+
const req = { user: { roles: ['admin'] } } as any;
|
|
8
|
+
expect(admins({ req })).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false for users without admin role', () => {
|
|
12
|
+
const req = { user: { roles: ['user'] } } as any;
|
|
13
|
+
expect(admins({ req })).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for users with empty roles array', () => {
|
|
17
|
+
const req = { user: { roles: [] } } as any;
|
|
18
|
+
expect(admins({ req })).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return false for unauthenticated users (null user)', () => {
|
|
22
|
+
const req = { user: null } as any;
|
|
23
|
+
expect(admins({ req })).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return false for unauthenticated users (undefined user)', () => {
|
|
27
|
+
const req = { user: undefined } as any;
|
|
28
|
+
expect(admins({ req })).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should handle users with multiple roles including admin', () => {
|
|
32
|
+
const req = { user: { roles: ['user', 'admin', 'editor'] } } as any;
|
|
33
|
+
expect(admins({ req })).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return false when user has no roles property', () => {
|
|
37
|
+
const req = { user: {} } as any;
|
|
38
|
+
expect(admins({ req })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return false when roles is null', () => {
|
|
42
|
+
const req = { user: { roles: null } } as any;
|
|
43
|
+
expect(admins({ req })).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('adminsFieldLevel', () => {
|
|
48
|
+
it('should return true for users with admin role', () => {
|
|
49
|
+
const params = { req: { user: { roles: ['admin'] } } } as any;
|
|
50
|
+
expect(adminsFieldLevel(params)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return false for users without admin role', () => {
|
|
54
|
+
const params = { req: { user: { roles: ['user'] } } } as any;
|
|
55
|
+
expect(adminsFieldLevel(params)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return false for unauthenticated users', () => {
|
|
59
|
+
const params = { req: { user: null } } as any;
|
|
60
|
+
expect(adminsFieldLevel(params)).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should handle users with multiple roles including admin', () => {
|
|
64
|
+
const params = { req: { user: { roles: ['user', 'admin'] } } } as any;
|
|
65
|
+
expect(adminsFieldLevel(params)).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { anyone } from '@/access/anyone';
|
|
3
|
+
|
|
4
|
+
describe('anyone access control', () => {
|
|
5
|
+
it('should return true for authenticated users', () => {
|
|
6
|
+
const req = { user: { id: 1 } } as any;
|
|
7
|
+
expect(anyone({ req })).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should return true for unauthenticated users (null)', () => {
|
|
11
|
+
const req = { user: null } as any;
|
|
12
|
+
expect(anyone({ req })).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return true for unauthenticated users (undefined)', () => {
|
|
16
|
+
const req = { user: undefined } as any;
|
|
17
|
+
expect(anyone({ req })).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return true with no arguments', () => {
|
|
21
|
+
expect(anyone({} as any)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return true for admin users', () => {
|
|
25
|
+
const req = { user: { roles: ['admin'] } } as any;
|
|
26
|
+
expect(anyone({ req })).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { authenticated, authenticatedFieldLevel } from '@/access/authenticated';
|
|
3
|
+
|
|
4
|
+
describe('authenticated access control', () => {
|
|
5
|
+
describe('authenticated', () => {
|
|
6
|
+
it('should return true for authenticated users', () => {
|
|
7
|
+
const req = { user: { id: 1, email: 'test@example.com' } } as any;
|
|
8
|
+
expect(authenticated({ req })).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false for null user', () => {
|
|
12
|
+
const req = { user: null } as any;
|
|
13
|
+
expect(authenticated({ req })).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for undefined user', () => {
|
|
17
|
+
const req = { user: undefined } as any;
|
|
18
|
+
expect(authenticated({ req })).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return true for user with minimal properties', () => {
|
|
22
|
+
const req = { user: {} } as any;
|
|
23
|
+
expect(authenticated({ req })).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return true for user with roles', () => {
|
|
27
|
+
const req = { user: { roles: ['admin'] } } as any;
|
|
28
|
+
expect(authenticated({ req })).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('authenticatedFieldLevel', () => {
|
|
33
|
+
it('should return true for authenticated users', () => {
|
|
34
|
+
const params = { req: { user: { id: 1 } } } as any;
|
|
35
|
+
expect(authenticatedFieldLevel(params)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return false for null user', () => {
|
|
39
|
+
const params = { req: { user: null } } as any;
|
|
40
|
+
expect(authenticatedFieldLevel(params)).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return false for undefined user', () => {
|
|
44
|
+
const params = { req: { user: undefined } } as any;
|
|
45
|
+
expect(authenticatedFieldLevel(params)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should return true for user object (even empty)', () => {
|
|
49
|
+
const params = { req: { user: {} } } as any;
|
|
50
|
+
expect(authenticatedFieldLevel(params)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { authenticatedAccessOnly } from '@/access/authenticatedAccessOnly';
|
|
3
|
+
|
|
4
|
+
describe('authenticatedAccessOnly access control', () => {
|
|
5
|
+
describe('admin property', () => {
|
|
6
|
+
it('should return true for authenticated users', () => {
|
|
7
|
+
const req = { user: { id: 1 } } as any;
|
|
8
|
+
expect(authenticatedAccessOnly.admin({ req })).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false for unauthenticated users (null)', () => {
|
|
12
|
+
const req = { user: null } as any;
|
|
13
|
+
expect(authenticatedAccessOnly.admin({ req })).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for unauthenticated users (undefined)', () => {
|
|
17
|
+
const req = { user: undefined } as any;
|
|
18
|
+
expect(authenticatedAccessOnly.admin({ req })).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return true for empty user object', () => {
|
|
22
|
+
const req = { user: {} } as any;
|
|
23
|
+
expect(authenticatedAccessOnly.admin({ req })).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('create property', () => {
|
|
28
|
+
it('should return true for authenticated users', () => {
|
|
29
|
+
const req = { user: { id: 1 } } as any;
|
|
30
|
+
expect(authenticatedAccessOnly.create({ req })).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should return false for unauthenticated users', () => {
|
|
34
|
+
const req = { user: null } as any;
|
|
35
|
+
expect(authenticatedAccessOnly.create({ req })).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('read property', () => {
|
|
40
|
+
it('should return true for authenticated users', () => {
|
|
41
|
+
const req = { user: { id: 1 } } as any;
|
|
42
|
+
expect(authenticatedAccessOnly.read({ req })).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should return false for unauthenticated users', () => {
|
|
46
|
+
const req = { user: null } as any;
|
|
47
|
+
expect(authenticatedAccessOnly.read({ req })).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('update property', () => {
|
|
52
|
+
it('should return true for authenticated users', () => {
|
|
53
|
+
const req = { user: { id: 1 } } as any;
|
|
54
|
+
expect(authenticatedAccessOnly.update({ req })).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should return false for unauthenticated users', () => {
|
|
58
|
+
const req = { user: null } as any;
|
|
59
|
+
expect(authenticatedAccessOnly.update({ req })).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('delete property', () => {
|
|
64
|
+
it('should return true for authenticated users', () => {
|
|
65
|
+
const req = { user: { id: 1 } } as any;
|
|
66
|
+
expect(authenticatedAccessOnly.delete({ req })).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should return false for unauthenticated users', () => {
|
|
70
|
+
const req = { user: null } as any;
|
|
71
|
+
expect(authenticatedAccessOnly.delete({ req })).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('readVersions property', () => {
|
|
76
|
+
it('should return true for authenticated users', () => {
|
|
77
|
+
const req = { user: { id: 1 } } as any;
|
|
78
|
+
expect(authenticatedAccessOnly.readVersions({ req })).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should return false for unauthenticated users', () => {
|
|
82
|
+
const req = { user: null } as any;
|
|
83
|
+
expect(authenticatedAccessOnly.readVersions({ req })).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('unlock property', () => {
|
|
88
|
+
it('should return true for authenticated users', () => {
|
|
89
|
+
const req = { user: { id: 1 } } as any;
|
|
90
|
+
expect(authenticatedAccessOnly.unlock({ req })).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should return false for unauthenticated users', () => {
|
|
94
|
+
const req = { user: null } as any;
|
|
95
|
+
expect(authenticatedAccessOnly.unlock({ req })).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('all properties work consistently', () => {
|
|
100
|
+
it('should allow all operations for authenticated users', () => {
|
|
101
|
+
const req = { user: { roles: ['user'] } } as any;
|
|
102
|
+
|
|
103
|
+
expect(authenticatedAccessOnly.admin({ req })).toBe(true);
|
|
104
|
+
expect(authenticatedAccessOnly.create({ req })).toBe(true);
|
|
105
|
+
expect(authenticatedAccessOnly.read({ req })).toBe(true);
|
|
106
|
+
expect(authenticatedAccessOnly.update({ req })).toBe(true);
|
|
107
|
+
expect(authenticatedAccessOnly.delete({ req })).toBe(true);
|
|
108
|
+
expect(authenticatedAccessOnly.readVersions({ req })).toBe(true);
|
|
109
|
+
expect(authenticatedAccessOnly.unlock({ req })).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { publicReadAuthenticatedAccess } from '@/access/publicReadAuthenticatedAccess';
|
|
3
|
+
|
|
4
|
+
describe('publicReadAuthenticatedAccess access control', () => {
|
|
5
|
+
describe('admin property', () => {
|
|
6
|
+
it('should return true for authenticated users', () => {
|
|
7
|
+
const req = { user: { id: 1 } } as any;
|
|
8
|
+
expect(publicReadAuthenticatedAccess.admin({ req })).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false for unauthenticated users', () => {
|
|
12
|
+
const req = { user: null } as any;
|
|
13
|
+
expect(publicReadAuthenticatedAccess.admin({ req })).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('read property (public access)', () => {
|
|
18
|
+
it('should return true for authenticated users', () => {
|
|
19
|
+
const req = { user: { id: 1 } } as any;
|
|
20
|
+
expect(publicReadAuthenticatedAccess.read({ req })).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return true for unauthenticated users (public read)', () => {
|
|
24
|
+
const req = { user: null } as any;
|
|
25
|
+
expect(publicReadAuthenticatedAccess.read({ req })).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return true with no user property', () => {
|
|
29
|
+
const req = {} as any;
|
|
30
|
+
expect(publicReadAuthenticatedAccess.read({ req })).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('create property (authenticated only)', () => {
|
|
35
|
+
it('should return true for authenticated users', () => {
|
|
36
|
+
const req = { user: { id: 1 } } as any;
|
|
37
|
+
expect(publicReadAuthenticatedAccess.create({ req })).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should return false for unauthenticated users', () => {
|
|
41
|
+
const req = { user: null } as any;
|
|
42
|
+
expect(publicReadAuthenticatedAccess.create({ req })).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('update property (authenticated only)', () => {
|
|
47
|
+
it('should return true for authenticated users', () => {
|
|
48
|
+
const req = { user: { id: 1 } } as any;
|
|
49
|
+
expect(publicReadAuthenticatedAccess.update({ req })).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should return false for unauthenticated users', () => {
|
|
53
|
+
const req = { user: null } as any;
|
|
54
|
+
expect(publicReadAuthenticatedAccess.update({ req })).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('delete property (authenticated only)', () => {
|
|
59
|
+
it('should return true for authenticated users', () => {
|
|
60
|
+
const req = { user: { id: 1 } } as any;
|
|
61
|
+
expect(publicReadAuthenticatedAccess.delete({ req })).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should return false for unauthenticated users', () => {
|
|
65
|
+
const req = { user: null } as any;
|
|
66
|
+
expect(publicReadAuthenticatedAccess.delete({ req })).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('readVersions property (authenticated only)', () => {
|
|
71
|
+
it('should return true for authenticated users', () => {
|
|
72
|
+
const req = { user: { id: 1 } } as any;
|
|
73
|
+
expect(publicReadAuthenticatedAccess.readVersions({ req })).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should return false for unauthenticated users', () => {
|
|
77
|
+
const req = { user: null } as any;
|
|
78
|
+
expect(publicReadAuthenticatedAccess.readVersions({ req })).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('unlock property (authenticated only)', () => {
|
|
83
|
+
it('should return true for authenticated users', () => {
|
|
84
|
+
const req = { user: { id: 1 } } as any;
|
|
85
|
+
expect(publicReadAuthenticatedAccess.unlock({ req })).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should return false for unauthenticated users', () => {
|
|
89
|
+
const req = { user: null } as any;
|
|
90
|
+
expect(publicReadAuthenticatedAccess.unlock({ req })).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('access pattern verification', () => {
|
|
95
|
+
it('should allow read to everyone and other operations to authenticated users only', () => {
|
|
96
|
+
const authenticatedReq = { user: { id: 1 } } as any;
|
|
97
|
+
const unauthenticatedReq = { user: null } as any;
|
|
98
|
+
|
|
99
|
+
// Authenticated user can do everything
|
|
100
|
+
expect(publicReadAuthenticatedAccess.read({ req: authenticatedReq })).toBe(true);
|
|
101
|
+
expect(publicReadAuthenticatedAccess.create({ req: authenticatedReq })).toBe(true);
|
|
102
|
+
expect(publicReadAuthenticatedAccess.update({ req: authenticatedReq })).toBe(true);
|
|
103
|
+
expect(publicReadAuthenticatedAccess.delete({ req: authenticatedReq })).toBe(true);
|
|
104
|
+
|
|
105
|
+
// Unauthenticated user can only read
|
|
106
|
+
expect(publicReadAuthenticatedAccess.read({ req: unauthenticatedReq })).toBe(true);
|
|
107
|
+
expect(publicReadAuthenticatedAccess.create({ req: unauthenticatedReq })).toBe(false);
|
|
108
|
+
expect(publicReadAuthenticatedAccess.update({ req: unauthenticatedReq })).toBe(false);
|
|
109
|
+
expect(publicReadAuthenticatedAccess.delete({ req: unauthenticatedReq })).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|