2021-06-29 04:03:36 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2021-06-29 04:03:36 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-06-29 04:03:36 -05:00
|
|
|
import PrivilegeRoleSchema, {getNodePrivilegeRoleSchema} from '../../../pgadmin/browser/server_groups/servers/static/js/privilege.ui';
|
|
|
|
import {DefaultPrivSchema} from '../../../pgadmin/browser/server_groups/servers/databases/static/js/database.ui';
|
|
|
|
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
2023-10-23 07:13:17 -05:00
|
|
|
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2021-06-29 04:03:36 -05:00
|
|
|
|
|
|
|
describe('PrivilegeSchema', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-06-29 04:03:36 -05:00
|
|
|
let schemaObj = new PrivilegeRoleSchema(
|
|
|
|
()=>[],
|
|
|
|
()=>[],
|
|
|
|
null,
|
|
|
|
{server: {user: {name: 'postgres'}}},
|
|
|
|
['X']
|
|
|
|
);
|
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
|
2021-06-29 04:03:36 -05:00
|
|
|
|
|
|
|
beforeEach(()=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-06-29 04:03:36 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create', async ()=>{
|
|
|
|
await getCreateView(schemaObj);
|
2021-06-29 04:03:36 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('edit', async ()=>{
|
|
|
|
await getEditView(schemaObj, getInitData);
|
2021-06-29 04:03:36 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('properties', async ()=>{
|
|
|
|
await getPropertiesView(schemaObj, getInitData);
|
2021-06-29 04:03:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('validate', ()=>{
|
|
|
|
let state = {};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-06-29 04:03:36 -05:00
|
|
|
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('privileges', 'At least one privilege should be selected.');
|
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('DefaultPrivSchema', async ()=>{
|
|
|
|
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue([]);
|
2021-06-29 04:03:36 -05:00
|
|
|
let defPrivObj = new DefaultPrivSchema((privileges)=>getNodePrivilegeRoleSchema({}, {server: {user: {name: 'postgres'}}}, {}, privileges));
|
2023-10-23 07:13:17 -05:00
|
|
|
let {ctrl, user} = await getCreateView(defPrivObj);
|
|
|
|
await addNewDatagridRow(user, ctrl);
|
2021-06-29 04:03:36 -05:00
|
|
|
});
|
|
|
|
});
|