n8n-nodes-awx
Version:
n8n node to interact with Ansible AWX/Tower with improved type safety
254 lines • 9.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
describe('AWX Inventory Operations - Data Structures', () => {
test('should have the correct inventory data structure', () => {
const inventoryData = {
id: 15,
name: 'Production Servers',
description: 'Production environment servers',
kind: '',
host_filter: null,
variables: '---\nsome_var: some_val\n',
has_active_failures: false,
total_hosts: 25,
hosts_with_active_failures: 0,
total_groups: 5,
has_inventory_sources: true,
organization: 1,
summary_fields: {
organization: { name: 'Default', id: 1 },
created_by: { username: 'admin', id: 1 }
}
};
expect(inventoryData).toHaveProperty('id');
expect(inventoryData).toHaveProperty('name');
expect(inventoryData).toHaveProperty('description');
expect(inventoryData).toHaveProperty('organization');
expect(inventoryData).toHaveProperty('kind');
expect(inventoryData).toHaveProperty('host_filter');
expect(inventoryData).toHaveProperty('variables');
expect(inventoryData).toHaveProperty('has_active_failures');
expect(inventoryData).toHaveProperty('total_hosts');
expect(inventoryData).toHaveProperty('hosts_with_active_failures');
expect(inventoryData).toHaveProperty('total_groups');
expect(inventoryData).toHaveProperty('has_inventory_sources');
expect(inventoryData).toHaveProperty('summary_fields');
expect(inventoryData.summary_fields).toHaveProperty('organization');
expect(inventoryData.summary_fields.organization.name).toBe('Default');
});
it('should have the correct inventory list response format', () => {
const inventoryListResponse = {
count: 2,
next: null,
previous: null,
results: [
{
id: 15,
name: 'Production Servers',
description: 'Production environment servers',
total_hosts: 25,
total_groups: 5
},
{
id: 16,
name: 'Development Servers',
description: 'Development environment servers',
total_hosts: 10,
total_groups: 3
}
]
};
expect(inventoryListResponse).toHaveProperty('count', 2);
expect(inventoryListResponse).toHaveProperty('next', null);
expect(inventoryListResponse).toHaveProperty('previous', null);
expect(inventoryListResponse).toHaveProperty('results');
expect(Array.isArray(inventoryListResponse.results)).toBe(true);
expect(inventoryListResponse.results).toHaveLength(2);
const firstInventory = inventoryListResponse.results[0];
expect(firstInventory).toMatchObject({
id: 15,
name: 'Production Servers',
description: 'Production environment servers',
total_hosts: 25,
total_groups: 5
});
expect(firstInventory.id).toBe(15);
expect(firstInventory.name).toBe('Production Servers');
expect(firstInventory.total_hosts).toBe(25);
});
it('should have the correct host data structure', () => {
const hostData = {
id: 42,
name: 'web01.example.com',
description: 'Web server 01',
enabled: true,
inventory: 15,
variables: '---\nansible_host: 192.168.1.101\nhttp_port: 80\n',
has_active_failures: false,
has_inventory_sources: false,
last_job: 123,
last_job_host_summary: 456,
summary_fields: {
inventory: { id: 15, name: 'Production Servers' },
last_job: { id: 123, name: 'System Update', status: 'successful' },
created_by: { username: 'admin', id: 1 }
}
};
expect(hostData).toMatchObject({
id: 42,
name: 'web01.example.com',
description: 'Web server 01',
inventory: 15,
enabled: true,
variables: expect.any(String),
has_active_failures: false,
has_inventory_sources: false,
last_job: 123,
last_job_host_summary: 456
});
expect(hostData).toHaveProperty('summary_fields');
expect(hostData.summary_fields).toMatchObject({
inventory: {
id: 15,
name: 'Production Servers'
},
last_job: {
id: 123,
name: 'System Update',
status: 'successful'
},
created_by: {
username: 'admin',
id: 1
}
});
});
it('should have the correct group data structure', () => {
const groupData = {
id: 101,
name: 'web_servers',
description: 'Web server group',
inventory: 15,
variables: '---\nhttp_port: 80\n',
has_active_failures: false,
total_hosts: 5,
hosts_with_active_failures: 0,
total_groups: 0,
summary_fields: {
inventory: { id: 15, name: 'Production Servers' },
created_by: { username: 'admin', id: 1 }
}
};
expect(groupData).toMatchObject({
id: 101,
name: 'web_servers',
description: 'Web server group',
inventory: 15,
variables: expect.any(String),
has_active_failures: false,
total_hosts: 5,
hosts_with_active_failures: 0,
total_groups: 0
});
expect(groupData.id).toBe(101);
expect(groupData.name).toBe('web_servers');
expect(groupData.inventory).toBe(15);
expect(groupData.total_hosts).toBe(5);
expect(groupData).toHaveProperty('summary_fields');
expect(groupData.summary_fields).toMatchObject({
inventory: {
id: 15,
name: 'Production Servers'
},
created_by: {
username: 'admin',
id: 1
}
});
});
it('should correctly format hosts response when filtering by group', () => {
const groupHostsResponse = {
count: 2,
next: null,
previous: null,
results: [
{
id: 42,
name: 'web01.example.com',
description: 'Web server 01',
inventory: 15
},
{
id: 43,
name: 'web02.example.com',
description: 'Web server 02',
inventory: 15
}
]
};
expect(groupHostsResponse).toMatchObject({
count: 2,
next: null,
previous: null,
results: expect.arrayContaining([
expect.objectContaining({
id: 42,
name: 'web01.example.com',
description: 'Web server 01',
inventory: 15
}),
expect.objectContaining({
id: 43,
name: 'web02.example.com',
description: 'Web server 02',
inventory: 15
})
])
});
expect(groupHostsResponse.results).toHaveLength(2);
const firstHost = groupHostsResponse.results[0];
expect(firstHost).toMatchObject({
id: 42,
name: 'web01.example.com',
description: 'Web server 01',
inventory: 15
});
expect(firstHost.name).toBe('web01.example.com');
expect(firstHost.inventory).toBe(15);
});
it('should correctly format inventory parameters for operations', () => {
const listHostsParams = {
resource: 'host',
inventoryName: 'Production Servers',
returnAll: true
};
const getHostParams = {
resource: 'host',
action: 'get',
inventoryName: 'Production Servers',
hostName: 'web01.example.com'
};
const listGroupsParams = {
resource: 'group',
inventoryName: 'Production Servers',
returnAll: true
};
const getGroupParams = {
resource: 'group',
action: 'get',
inventoryName: 'Production Servers',
groupName: 'web_servers'
};
expect(listHostsParams).toHaveProperty('inventoryName');
expect(listHostsParams.inventoryName).toBe('Production Servers');
expect(getHostParams).toHaveProperty('inventoryName');
expect(getHostParams.inventoryName).toBe('Production Servers');
expect(getHostParams).toHaveProperty('hostName');
expect(listGroupsParams).toHaveProperty('inventoryName');
expect(listGroupsParams.inventoryName).toBe('Production Servers');
expect(getGroupParams).toHaveProperty('inventoryName');
expect(getGroupParams.inventoryName).toBe('Production Servers');
expect(getGroupParams).toHaveProperty('groupName');
});
});
//# sourceMappingURL=InventoryStandalone.test.js.map