Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/contentstack-audit/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import GlobalField from './global-fields';
import ContentType from './content-types';
import Workflows from './workflows';
import Extensions from './extensions';
import CustomRoles from './custom-roles';
import Assets from './assets';
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets };
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets, CustomRoles };
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"uidcs1123": {
"urlPath": "/roles/uid123",
"stackHeaders": { "api_key": "uid123", "branch": "main" },
"name": "Test role 1",
"description": "",
"rules": [
{ "module": "environment", "environments": ["uidenv123"], "acl": { "read": true } },
{ "module": "locale", "locales": ["uidloc123"], "acl": { "read": true } },
{ "module": "content_type", "content_types": ["$all"], "acl": { "read": true, "sub_acl": { "read": true } } },
{ "module": "entry", "content_type": "about", "entries": ["uident123"], "acl": { "read": true } },
{ "module": "branch", "branches": ["main"], "acl": { "read": true } }
],
"users": [],
"uid": "uid123",
"owner": "vikram@contentstack.com",
"stack": {
"created_at": "2024-11-14T23:18:46.087Z",
"updated_at": "2025-02-28T00:38:09.298Z",
"uid": "uid123",
"name": "Datasync-manager",
"org_uid": "uid123",
"api_key": "uid123",
"master_locale": "en-us",
"is_asset_download_public": true,
"owner_uid": "uid123",
"user_uids": ["uid123", "uid123"],
"master_key": "uid123"
},
"permissions": {
"content_types": [
{ "uid": "about", "SYS_ACL": { "read": true } },
{ "uid": "about", "SYS_ACL": { "read": true } },
{ "uid": "header", "SYS_ACL": { "read": true, "sub_acl": { "read": true } } },
{ "uid": "header", "SYS_ACL": { "read": true, "sub_acl": { "read": true } } }
],
"environments": [{ "uid": "uid123", "SYS_ACL": { "read": true } }],
"locales": [{ "uid": "uid123", "SYS_ACL": { "read": true } }]
},
"SYS_ACL": {}
},
"uidcs2123": {
"urlPath": "/roles/uid123",
"stackHeaders": { "api_key": "uid123", "branch": "main" },
"name": "Role 2",
"description": "",
"rules": [
{ "module": "environment", "environments": ["uid123"], "acl": { "read": true } },
{ "module": "locale", "locales": ["uid123"], "acl": { "read": true } },
{ "module": "content_type", "content_types": ["$all"], "acl": { "read": true, "sub_acl": { "read": true } } },
{ "module": "entry", "content_type": "header", "entries": ["uid123"], "acl": { "read": true } },
{ "module": "branch", "branches": ["dev"], "acl": { "read": true } }
],
"users": [],
"uid": "uid123",
"created_at": "2025-03-02T16:22:56.080Z",
"updated_at": "2025-03-02T16:22:56.080Z",
"owner": "vikram@contentstack.com",
"stack": {
"created_at": "2024-11-14T23:18:46.087Z",
"updated_at": "2025-02-28T00:38:09.298Z",
"uid": "uid123",
"name": "Datasync-manager",
"org_uid": "uid123",
"api_key": "uid123",
"master_locale": "en-us",
"is_asset_download_public": true,
"owner_uid": "uid123",
"user_uids": ["uid123", "uid123"],
"master_key": "uid123"
},
"permissions": {
"content_types": [
{ "uid": "about", "SYS_ACL": { "read": true, "sub_acl": { "read": true } } },
{ "uid": "about", "SYS_ACL": { "read": true, "sub_acl": { "read": true } } },
{ "uid": "header", "SYS_ACL": { "read": true } },
{ "uid": "header", "SYS_ACL": { "read": true } }
],
"environments": [{ "uid": "uid123", "SYS_ACL": { "read": true } }],
"locales": [{ "uid": "uid123", "SYS_ACL": { "read": true } }]
},
"SYS_ACL": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { resolve } from 'path';
import { expect } from 'chai';
import cloneDeep from 'lodash/cloneDeep';
import fancy from 'fancy-test';
import Sinon from 'sinon';
import config from '../../../src/config';
import { CustomRoles } from '../../../src/modules';
import { CtConstructorParam, ModuleConstructorParam } from '../../../src/types';

describe('Custom roles module', () => {
let constructorParam: ModuleConstructorParam & Pick<CtConstructorParam, 'ctSchema'>;

beforeEach(() => {
constructorParam = {
log: () => {},
moduleName: 'custom-roles',
config: Object.assign(config, { basePath: resolve(__dirname, '..', 'mock', 'contents'), flags: {} }),
ctSchema: cloneDeep(require('../mock/contents/content_types/schema.json')),
};
});

describe('run method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.it('should have missingFieldsInCustomRoles length equals to 2', async () => {
const customRoleInstance = new CustomRoles({
...constructorParam,
config: { ...constructorParam.config, branch: 'test' },
});
await customRoleInstance.run();
expect(customRoleInstance.missingFieldsInCustomRoles).length(2);
expect(JSON.stringify(customRoleInstance.missingFieldsInCustomRoles)).includes('"branches":["main"]');
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(CustomRoles.prototype, 'fixCustomRoleSchema', async () => {})
.it('should call fixCustomRoleSchema', async () => {
const customRoleInstance = new CustomRoles({
...constructorParam,
config: { ...constructorParam.config, branch: 'test' },
fix: true,
});
const logSpy = Sinon.spy(customRoleInstance, 'fixCustomRoleSchema');
await customRoleInstance.run();
expect(logSpy.callCount).to.be.equals(1);
});

fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(CustomRoles.prototype, 'writeFixContent', async () => {})
.it('should call writeFixContent', async () => {
const customRoleInstance = new CustomRoles({
...constructorParam,
config: { ...constructorParam.config, branch: 'test' },
fix: true,
});
const logSpy = Sinon.spy(customRoleInstance, 'writeFixContent');
await customRoleInstance.run();
expect(logSpy.callCount).to.be.equals(1);
});
});

after(() => {
Sinon.restore(); // Clears Sinon spies/stubs/mocks
});
});
Loading