ensure correct url is built for inventory hosts page

This commit is contained in:
Jake McDermott
2018-02-24 20:08:51 -05:00
parent 434cd31df8
commit 59e278a648
2 changed files with 30 additions and 24 deletions

View File

@@ -10,24 +10,17 @@ import {
const session = `e2e-${uuid().substr(0, 8)}`; const session = `e2e-${uuid().substr(0, 8)}`;
const store = {}; const store = {};
const getOrCreate = (endpoint, data, unique = ['name', 'username', 'id']) => { const getOrCreate = (endpoint, data, unique = ['name']) => {
const identifier = Object.keys(data).find(key => unique.includes(key)); const identifiers = Object.keys(data).filter(key => unique.indexOf(key) > -1);
if (identifier === undefined) { if (identifiers.length < 1) {
throw new Error('A unique key value must be provided.'); throw new Error('A unique key value must be provided.');
} }
const identity = data[identifier]; const lookup = `${endpoint}/${identifiers.map(key => data[key]).join('-')}`;
const params = Object.assign(...identifiers.map(key => ({ [key]: data[key] })));
store[endpoint] = store[endpoint] || {}; store[lookup] = store[lookup] || get(endpoint, { params })
if (store[endpoint][identity]) {
return store[endpoint][identity].then(created => created.data);
}
const query = { params: { [identifier]: identity } };
store[endpoint][identity] = get(endpoint, query)
.then(res => { .then(res => {
if (res.data.results.length > 1) { if (res.data.results.length > 1) {
return Promise.reject(new Error('More than one matching result.')); return Promise.reject(new Error('More than one matching result.'));
@@ -44,7 +37,7 @@ const getOrCreate = (endpoint, data, unique = ['name', 'username', 'id']) => {
return Promise.reject(new Error(`unexpected response: ${res}`)); return Promise.reject(new Error(`unexpected response: ${res}`));
}); });
return store[endpoint][identity].then(created => created.data); return store[lookup].then(created => created.data);
}; };
const getOrganization = (namespace = session) => getOrCreate('/organizations/', { const getOrganization = (namespace = session) => getOrCreate('/organizations/', {
@@ -57,7 +50,12 @@ const getInventory = (namespace = session) => getOrganization(namespace)
name: `${namespace}-inventory`, name: `${namespace}-inventory`,
description: namespace, description: namespace,
organization: organization.id organization: organization.id
})); }).then(inventory => getOrCreate('/hosts/', {
name: `${namespace}-host`,
description: namespace,
inventory: inventory.id,
variables: JSON.stringify({ ansible_connection: 'local' }),
}, ['name', 'inventory']).then(() => inventory)));
const getHost = (namespace = session) => getInventory(namespace) const getHost = (namespace = session) => getInventory(namespace)
.then(inventory => getOrCreate('/hosts/', { .then(inventory => getOrCreate('/hosts/', {
@@ -65,7 +63,7 @@ const getHost = (namespace = session) => getInventory(namespace)
description: namespace, description: namespace,
inventory: inventory.id, inventory: inventory.id,
variables: JSON.stringify({ ansible_connection: 'local' }), variables: JSON.stringify({ ansible_connection: 'local' }),
})); }, ['name', 'inventory']));
const getInventoryScript = (namespace = session) => getOrganization(namespace) const getInventoryScript = (namespace = session) => getOrganization(namespace)
.then(organization => getOrCreate('/inventory_scripts/', { .then(organization => getOrCreate('/inventory_scripts/', {
@@ -265,8 +263,8 @@ const getWorkflowTemplate = (namespace = session) => {
]; ];
const createSuccessNodes = ([projectNode, jobNode, sourceNode]) => Promise.all([ const createSuccessNodes = ([projectNode, jobNode, sourceNode]) => Promise.all([
getOrCreate(projectNode.related.success_nodes, { id: jobNode.id }), getOrCreate(projectNode.related.success_nodes, { id: jobNode.id }, ['id']),
getOrCreate(jobNode.related.success_nodes, { id: sourceNode.id }), getOrCreate(jobNode.related.success_nodes, { id: sourceNode.id }, ['id']),
]); ]);
return Promise.all(nodes) return Promise.all(nodes)
@@ -287,7 +285,7 @@ const getAuditor = (namespace = session) => getOrganization(namespace)
is_superuser: false, is_superuser: false,
is_system_auditor: true, is_system_auditor: true,
password: AWX_E2E_PASSWORD password: AWX_E2E_PASSWORD
})); }, ['username']));
const getUser = (namespace = session) => getOrganization(namespace) const getUser = (namespace = session) => getOrganization(namespace)
.then(organization => getOrCreate('/users/', { .then(organization => getOrCreate('/users/', {
@@ -299,7 +297,7 @@ const getUser = (namespace = session) => getOrganization(namespace)
is_superuser: false, is_superuser: false,
is_system_auditor: false, is_system_auditor: false,
password: AWX_E2E_PASSWORD password: AWX_E2E_PASSWORD
})); }, ['username']));
const getJobTemplateAdmin = (namespace = session) => { const getJobTemplateAdmin = (namespace = session) => {
const rolePromise = getJobTemplate(namespace) const rolePromise = getJobTemplate(namespace)
@@ -315,7 +313,7 @@ const getJobTemplateAdmin = (namespace = session) => {
is_superuser: false, is_superuser: false,
is_system_auditor: false, is_system_auditor: false,
password: AWX_E2E_PASSWORD password: AWX_E2E_PASSWORD
})); }, ['username']));
const assignRolePromise = Promise.all([userPromise, rolePromise]) const assignRolePromise = Promise.all([userPromise, rolePromise])
.then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id })); .then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id }));
@@ -338,7 +336,7 @@ const getProjectAdmin = (namespace = session) => {
is_superuser: false, is_superuser: false,
is_system_auditor: false, is_system_auditor: false,
password: AWX_E2E_PASSWORD password: AWX_E2E_PASSWORD
})); }, ['username']));
const assignRolePromise = Promise.all([userPromise, rolePromise]) const assignRolePromise = Promise.all([userPromise, rolePromise])
.then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id })); .then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id }));

View File

@@ -40,7 +40,7 @@ module.exports = {
getTeam(namespace).then(obj => { data.team = obj; }), getTeam(namespace).then(obj => { data.team = obj; }),
getProjectAdmin(namespace).then(obj => { data.user = obj; }), getProjectAdmin(namespace).then(obj => { data.user = obj; }),
getNotificationTemplate(namespace).then(obj => { data.notification = obj; }), getNotificationTemplate(namespace).then(obj => { data.notification = obj; }),
getJob(namespaceShort).then(obj => { data.job = obj; }), getJob(namespace).then(obj => { data.job = obj; }),
]; ];
Promise.all(resources) Promise.all(resources)
@@ -58,7 +58,6 @@ module.exports = {
urls.organization = `${pages.organizations.url()}/${data.organization.id}`; urls.organization = `${pages.organizations.url()}/${data.organization.id}`;
urls.inventory = `${pages.inventories.url()}/inventory/${data.inventory.id}`; urls.inventory = `${pages.inventories.url()}/inventory/${data.inventory.id}`;
urls.inventoryHosts = `${urls.inventory}/hosts`;
urls.inventoryScript = `${pages.inventoryScripts.url()}/${data.inventoryScript.id}`; urls.inventoryScript = `${pages.inventoryScripts.url()}/${data.inventoryScript.id}`;
urls.inventorySource = `${urls.inventory}/inventory_sources/edit/${data.inventorySource.id}`; urls.inventorySource = `${urls.inventory}/inventory_sources/edit/${data.inventorySource.id}`;
urls.sourceSchedule = `${urls.inventorySource}/schedules/${data.sourceSchedule.id}`; urls.sourceSchedule = `${urls.inventorySource}/schedules/${data.sourceSchedule.id}`;
@@ -72,6 +71,7 @@ module.exports = {
urls.notification = `${pages.notificationTemplates.url()}/${data.notification.id}`; urls.notification = `${pages.notificationTemplates.url()}/${data.notification.id}`;
urls.jobs = `${pages.jobs.url()}`; urls.jobs = `${pages.jobs.url()}`;
urls.jobsSchedules = `${pages.jobs.url()}/schedules`; urls.jobsSchedules = `${pages.jobs.url()}/schedules`;
urls.inventoryHosts = `${pages.inventories.url()}/inventory/${data.host.summary_fields.inventory.id}/hosts`;
client.useCss(); client.useCss();
client.login(); client.login();
@@ -691,6 +691,14 @@ module.exports = {
const popOver = `${itemRow} td[class*="active_failures-"] div[class*="popover"]`; const popOver = `${itemRow} td[class*="active_failures-"] div[class*="popover"]`;
client.navigateTo(urls.inventoryHosts); client.navigateTo(urls.inventoryHosts);
client.expect.element('div[class^="Panel"] smart-search').visible;
client.expect.element('div[class^="Panel"] smart-search input').enabled;
client.sendKeys('div[class^="Panel"] smart-search input', `id:>${data.host.id - 1} id:<${data.host.id + 1}`);
client.sendKeys('div[class^="Panel"] smart-search input', client.Keys.ENTER);
client.expect.element('div.spinny').visible;
client.expect.element('div.spinny').not.visible;
client.click(itemName); client.click(itemName);
client.expect.element(popOver).present; client.expect.element(popOver).present;