2021-08-10 06:51:09 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2021-08-10 06:51:09 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-10 06:51:09 -05:00
|
|
|
import PgaJobStepSchema from '../../../pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.ui';
|
2022-01-28 05:50:34 -06:00
|
|
|
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2021-08-10 06:51:09 -05:00
|
|
|
|
|
|
|
describe('PgaJobStepSchema', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-10 06:51:09 -05:00
|
|
|
let schemaObj = new PgaJobStepSchema(
|
|
|
|
{
|
|
|
|
databases: ()=>[],
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
{
|
|
|
|
jstdbname: 'postgres',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
|
2021-08-10 06:51:09 -05:00
|
|
|
|
|
|
|
beforeEach(()=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-08-10 06:51:09 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create', async ()=>{
|
|
|
|
await getCreateView(schemaObj);
|
2021-08-10 06:51:09 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('edit', async ()=>{
|
|
|
|
await getEditView(schemaObj, getInitData);
|
2021-08-10 06:51:09 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('properties', async ()=>{
|
|
|
|
await getPropertiesView(schemaObj, getInitData);
|
2021-08-10 06:51:09 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('validate', ()=>{
|
|
|
|
let state = {};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-08-10 06:51:09 -05:00
|
|
|
|
|
|
|
state.name = 'my_step';
|
|
|
|
state.jstkind = true;
|
|
|
|
state.jstconntype = true;
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstdbname', 'Please select a database.');
|
|
|
|
|
|
|
|
state.jstdbname = 'postgres';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstdbname', null);
|
|
|
|
|
|
|
|
state.jstconntype = false;
|
|
|
|
state.jstconnstr = null;
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', 'Please enter a connection string.');
|
|
|
|
|
|
|
|
state.jstconnstr = '**!!';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
2023-10-23 07:13:17 -05:00
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', 'Please enter a valid connection string.');
|
2021-08-10 06:51:09 -05:00
|
|
|
|
|
|
|
state.jstconnstr = 'host:\'192.168.1.7\'';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', 'Please enter a valid connection string.');
|
|
|
|
|
|
|
|
state.jstconnstr = 'host:\'192.168.1.7\'';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', 'Please enter a valid connection string.');
|
|
|
|
|
|
|
|
state.jstconnstr = 'hostaddrtest=\'192.168.1.7\'';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', 'Invalid parameter in the connection string - hostaddrtest.');
|
|
|
|
|
|
|
|
state.jstconnstr = 'host=\'192.168.1.7\' port=5432';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstconnstr', null);
|
|
|
|
|
|
|
|
state.jstcode = null;
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstcode', 'Please specify code to execute.');
|
|
|
|
|
|
|
|
state.jstcode = 'PERFORM 1;';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstcode', null);
|
|
|
|
|
|
|
|
state.jstonerror = null;
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstonerror', 'Please select valid on error option.');
|
|
|
|
|
|
|
|
state.jstonerror = 'f';
|
2023-10-23 07:13:17 -05:00
|
|
|
setError.mockClear();
|
2021-08-10 06:51:09 -05:00
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('jstonerror', null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|