Skip to content

Commit

Permalink
Update API integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed May 29, 2020
1 parent a687422 commit 22f9b26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { API_BASE_PATH, INDEX_PATTERNS } from './constants';
export const registerHelpers = ({ supertest }) => {
const getAllTemplates = () => supertest.get(`${API_BASE_PATH}/templates`);

const getOneTemplate = (name, formatVersion = 1) =>
supertest.get(`${API_BASE_PATH}/templates/${name}?v=${formatVersion}`);
const getOneTemplate = (name, isLegacy = true) =>
supertest.get(`${API_BASE_PATH}/templates/${name}?legacy=${isLegacy}`);

const getTemplatePayload = (name, formatVersion = 1) => ({
const getTemplatePayload = (name, isLegacy = true) => ({
name,
order: 1,
indexPatterns: INDEX_PATTERNS,
Expand Down Expand Up @@ -45,12 +45,12 @@ export const registerHelpers = ({ supertest }) => {
},
},
_kbnMeta: {
formatVersion,
isLegacy,
},
});

const createTemplate = (payload) =>
supertest.put(`${API_BASE_PATH}/templates`).set('kbn-xsrf', 'xxx').send(payload);
supertest.post(`${API_BASE_PATH}/templates`).set('kbn-xsrf', 'xxx').send(payload);

const deleteTemplates = (templates) =>
supertest.post(`${API_BASE_PATH}/delete-templates`).set('kbn-xsrf', 'xxx').send({ templates });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,31 @@ export default function ({ getService }) {
await createTemplate(payload).expect(200);
});

// TODO: When the "Create" API handler is added for V2 template,
// update this test to list composable templates.
it('should list all the index templates with the expected parameters', async () => {
const { body: templates } = await getAllTemplates().expect(200);
const { body: allTemplates } = await getAllTemplates().expect(200);

const createdTemplate = templates.find((template) => template.name === payload.name);
// Composable templates
expect(allTemplates.templates).to.eql([]);

// Legacy templates
const legacyTemplate = allTemplates.legacyTemplates.find(
(template) => template.name === payload.name
);
const expectedKeys = [
'name',
'indexPatterns',
'hasSettings',
'hasAliases',
'hasMappings',
'ilmPolicy',
'isManaged',
'order',
'version',
'_kbnMeta',
].sort();

expect(Object.keys(createdTemplate).sort()).to.eql(expectedKeys);
expect(Object.keys(legacyTemplate).sort()).to.eql(expectedKeys);
});
});

Expand All @@ -71,7 +78,6 @@ export default function ({ getService }) {
'indexPatterns',
'template',
'ilmPolicy',
'isManaged',
'order',
'version',
'_kbnMeta',
Expand Down Expand Up @@ -155,7 +161,7 @@ export default function ({ getService }) {
).to.equal(templateName);

const { body } = await deleteTemplates([
{ name: templateName, formatVersion: payload._kbnMeta.formatVersion },
{ name: templateName, isLegacy: payload._kbnMeta.isLegacy },
]).expect(200);

expect(body.errors).to.be.empty;
Expand Down

0 comments on commit 22f9b26

Please sign in to comment.