Skip to content

Commit

Permalink
Fixed functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Mar 17, 2020
1 parent eba4f70 commit 935d8e0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ describe('index connector validation', () => {
index: [],
},
});

delete actionConnector.config.index;
expect(actionTypeModel.validateConnector(actionConnector)).toEqual({
errors: {
index: ['Index is required.'],
},
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,23 @@ export default function indexTest({ getService }: FtrProviderContext) {
});

it('should execute successly when expected for a single body', async () => {
const { body: result } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
const { body: createdAction } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
name: 'An index action',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
refresh: false,
refresh: true,
},
secrets: {},
})
.expect(200);
const { body: result } = await supertest
.post(`/api/action/${createdAction.id}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: {
documents: [{ testing: [1, 2, 3] }],
},
Expand All @@ -147,13 +156,23 @@ export default function indexTest({ getService }: FtrProviderContext) {
});

it('should execute successly when expected for with multiple bodies', async () => {
const { body: result } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
const { body: createdAction } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
name: 'An index action',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
refresh: true,
},
secrets: {},
})
.expect(200);
const { body: result } = await supertest
.post(`/api/action/${createdAction.id}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: {
documents: [{ testing: [1, 2, 3] }, { Testing: [4, 5, 6] }],
},
Expand Down Expand Up @@ -181,13 +200,24 @@ export default function indexTest({ getService }: FtrProviderContext) {
});

it('should execute successly with refresh false', async () => {
const { body: result } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
const { body: createdAction } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
name: 'An index action',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
refresh: false,
executionTimeField: 'test',
},
secrets: {},
})
.expect(200);
const { body: result } = await supertest
.post(`/api/action/${createdAction.id}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: {
documents: [{ refresh: 'not set' }],
},
Expand All @@ -199,64 +229,32 @@ export default function indexTest({ getService }: FtrProviderContext) {
items = await getTestIndexItems(es);
expect(items.length).to.be.lessThan(2);

const { body: result2 } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
const { body: createdActionWithRefresh } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
name: 'An index action',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
refresh: true,
},
params: {
documents: [{ refresh: 'true' }],
},
secrets: {},
})
.expect(200);
expect(result2.status).to.eql('ok');

items = await getTestIndexItems(es);
expect(items.length).to.eql(2);
});

it('should execute unsuccessfully when expected', async () => {
let response;
let result;

response = await supertest
.post(`/api/action/${createdActionID}/_execute`)
const { body: result2 } = await supertest
.post(`/api/action/${createdActionWithRefresh.id}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
config: {
index: ES_TEST_INDEX_NAME,
},
params: {
documents: [{ testing: [1, 2, 3] }],
documents: [{ refresh: 'true' }],
},
})
.expect(200);
result = response.body;
expect(result.status).to.equal('error');
expect(result.message).to.eql(
'error validating action params: [index]: definition for this key is missing'
);
expect(result2.status).to.eql('ok');

response = await supertest
.post(`/api/action/${createdActionID}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
config: {
index: ES_TEST_INDEX_NAME,
},
params: {
documents: [{ testing: [1, 2, 3] }],
},
})
.expect(200);
result = response.body;
expect(result.status).to.equal('error');
expect(result.message).to.eql(
'index param needs to be set because not set in config for action'
);
items = await getTestIndexItems(es);
expect(items.length).to.eql(2);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function indexTest({ getService }: FtrProviderContext) {
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
refresh: false,
},
});
createdActionID = createdAction.id;
Expand All @@ -55,7 +56,7 @@ export default function indexTest({ getService }: FtrProviderContext) {
id: fetchedAction.id,
name: 'An index action',
actionTypeId: '.index',
config: { index: ES_TEST_INDEX_NAME },
config: { index: ES_TEST_INDEX_NAME, refresh: false },
});

// create action with all config props
Expand Down Expand Up @@ -103,8 +104,18 @@ export default function indexTest({ getService }: FtrProviderContext) {
});

it('should execute successly when expected for a single body', async () => {
const { body: createdAction } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
name: 'An index action',
actionTypeId: '.index',
config: { index: ES_TEST_INDEX_NAME },
secrets: {},
})
.expect(200);
const { body: result } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
.post(`/api/action/${createdAction.id}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: {
Expand Down

0 comments on commit 935d8e0

Please sign in to comment.