Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Oct 25, 2021
1 parent 71896d4 commit b3c4044
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,37 @@ describe('create()', () => {
);
});

test('validates connector: config and secrets', async () => {
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
validate: {
connector: schema.object({
config: schema.object({
param1: schema.string(),
}),
secrets: schema.object({
param2: schema.string(),
}),
}),
},
executor,
});
await expect(
actionsClient.create({
action: {
name: 'my name',
actionTypeId: 'my-action-type',
config: {},
secrets: {},
},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"error validating action type config: [param1]: expected value of type [string] but got [undefined]"`
);
});

test(`throws an error when an action type doesn't exist`, async () => {
await expect(
actionsClient.create({
Expand Down Expand Up @@ -1539,6 +1570,48 @@ describe('update()', () => {
);
});

test('validates connector: config and secrets', async () => {
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
validate: {
config: schema.object({
param1: schema.string(),
}),
connector: schema.object({
config: schema.object({
param1: schema.string(),
}),
secrets: schema.object({
param2: schema.string(),
}),
}),
},
executor,
});
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
id: 'my-action',
type: 'action',
attributes: {
actionTypeId: 'my-action-type',
},
references: [],
});
await expect(
actionsClient.update({
id: 'my-action',
action: {
name: 'my name',
config: {},
secrets: {},
},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"error validating action type config: [param1]: expected value of type [string] but got [undefined]"`
);
});

test('encrypts action type options unless specified not to', async () => {
actionTypeRegistry.register({
id: 'my-action-type',
Expand Down

0 comments on commit b3c4044

Please sign in to comment.