Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 1, 2024
1 parent eb96022 commit 763e05f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,6 @@ function getAlwaysFiringRuleWithSystemAction(reference: string) {
actions: [
{
id: 'system-connector-test.system-action-connector-adapter',
actionTypeId: 'test.system-action-connector-adapter',
uuid: '123',
/**
* The injected param required by the action will be set by the corresponding
* connector adapter. Setting it here it will lead to a 400 error by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ const findTestUtils = (
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ const getTestUtils = (
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import expect from '@kbn/expect';
import { RULE_SAVED_OBJECT_TYPE } from '@kbn/alerting-plugin/server';
import { UserAtSpaceScenarios } from '../../../scenarios';
import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios';
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

Expand Down Expand Up @@ -525,5 +525,66 @@ export default function getAllActionTests({ getService }: FtrProviderContext) {
});
});
}

describe('References', () => {
const systemAction = {
id: 'system-connector-test.system-action',
params: {},
};

it('calculates the references correctly', async () => {
const { user, space } = SuperuserAtSpace1;

const { body: createdAction } = await supertest
.post(`${getUrlPrefix(space.id)}/api/actions/connector`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.send({
name: 'My action',
connector_type_id: 'test.index-record',
config: {
unencrypted: `This value shouldn't get encrypted`,
},
secrets: {
encrypted: 'This value should be encrypted',
},
})
.expect(200);

objectRemover.add(space.id, createdAction.id, 'action', 'actions');

const ruleRes = await supertest
.post(`${getUrlPrefix(space.id)}/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.send(
getTestRuleData({
actions: [
systemAction,
{
id: createdAction.id,
group: 'default',
params: {},
},
],
})
)
.expect(200);

objectRemover.add(space.id, ruleRes.body.id, 'rule', 'alerting');

const response = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/internal/actions/connectors`)
.auth(user.username, user.password)
.expect(200);

const connectors = response.body as Array<{ id: string; referenced_by_count: number }>;

const createdConnector = connectors.find((connector) => connector.id === createdAction.id);
const systemConnector = connectors.find((connector) => connector.id === systemAction.id);

expect(createdConnector?.referenced_by_count).to.be(1);
expect(systemConnector?.referenced_by_count).to.be(0);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ export default ({ getService }: FtrProviderContext) => {
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ export default ({ getService }: FtrProviderContext) => {
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ export default ({ getService }: FtrProviderContext) => {
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default ({ getService }: FtrProviderContext) => {
},
{
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
describe('system actions', () => {
const systemAction = {
id: 'system-connector-test.system-action',
actionTypeId: 'test.system-action',
params: {},
};

Expand Down

0 comments on commit 763e05f

Please sign in to comment.