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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ describe('resolveRuleRoute', () => {
outcome: 'aliasMatch',
alias_target_id: '2',
revision: 0,
artifacts: {
dashboards: [
{
id: '123',
},
],
},
};

const resolveResult = {
Expand Down Expand Up @@ -116,6 +123,7 @@ describe('resolveRuleRoute', () => {
},
],
outcome: 'aliasMatch',
artifacts: mockedRule.artifacts,
};

it('resolves a rule with proper parameters', async () => {
Expand Down Expand Up @@ -253,4 +261,48 @@ describe('resolveRuleRoute', () => {
},
]);
});

it('returns the artifacts if defined', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();

resolveRuleRoute(router, licenseState);

const [, handler] = router.get.mock.calls[0];

// TODO (http-versioning): Remove this cast, this enables us to move forward
// without fixing all of other solution types
rulesClient.resolve.mockResolvedValueOnce({
...mockedRule,
artifacts: {
dashboards: [
{
id: '123',
},
],
},
} as ResolvedSanitizedRule);

const [context, req, res] = mockHandlerArguments(
{ rulesClient },
{
params: { id: '1' },
},
['ok']
);

const routeRes = await handler(context, req, res);

// @ts-expect-error: body exists
expect(routeRes.body.artifacts).not.toBeUndefined();

// @ts-expect-error: body exists
expect(routeRes.body.artifacts).toEqual({
dashboards: [
{
id: '123',
},
],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const transformResolveResponse = <Params extends RuleParams = never>(
...transformRuleToRuleResponseV1<Params>(rule),
outcome: rule.outcome,
alias_target_id: rule.alias_target_id,
...(rule.artifacts !== undefined ? { artifacts: rule.artifacts } : {}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,50 @@ export default ({ getService }: FtrProviderContext) => {
]);
});
});

describe('Artifacts', () => {
const { user, space } = SuperuserAtSpace1;

it('should return the artifacts correctly', async () => {
const { body: createdRule1 } = await supertest
.post(`${getUrlPrefix(space.id)}/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.send(
getTestRuleData({
enabled: true,
artifacts: {
dashboards: [
{
id: '123',
},
{
id: '456',
},
],
},
})
)
.expect(200);

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

const response = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/internal/alerting/rule/${createdRule1.id}/_resolve`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password);
const { artifacts } = response.body;

expect(artifacts).to.eql({
dashboards: [
{
id: '123',
},
{
id: '456',
},
],
});
});
});
});
};