n8n-nodes-awx
Version:
n8n node to interact with Ansible AWX/Tower with improved type safety
288 lines • 12.4 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nock_1 = __importDefault(require("nock"));
jest.setTimeout(10000);
const debug = (message, ...args) => {
console.log(`[DEBUG] ${message}`, ...args);
};
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
describe('AWX Workflow Job Template Operations - Data Structures', () => {
afterEach(() => {
debug('Cleaning up after test');
nock_1.default.cleanAll();
nock_1.default.enableNetConnect();
});
beforeAll(() => {
nock_1.default.disableNetConnect();
nock_1.default.enableNetConnect('127.0.0.1');
});
afterAll(() => {
debug('All tests completed');
});
test('should have the correct workflow job template data structure', () => {
const workflowJobTemplateData = {
id: 33,
name: 'CI/CD Pipeline',
description: 'Complete CI/CD pipeline for application deployment',
inventory: 15,
ask_variables_on_launch: true,
survey_enabled: false,
status: 'successful',
last_job_run: '2023-04-15T10:30:00Z',
summary_fields: {
inventory: { id: 15, name: 'Production Servers' },
last_job: { id: 200, status: 'successful' },
created_by: { username: 'admin', id: 1 }
}
};
expect(workflowJobTemplateData).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
description: expect.any(String),
inventory: expect.any(Number),
ask_variables_on_launch: expect.any(Boolean),
survey_enabled: expect.any(Boolean)
}));
expect(workflowJobTemplateData.id).toBe(33);
expect(workflowJobTemplateData.name).toBe('CI/CD Pipeline');
expect(workflowJobTemplateData.ask_variables_on_launch).toBe(true);
expect(workflowJobTemplateData).toHaveProperty('summary_fields');
expect(workflowJobTemplateData.summary_fields).toHaveProperty('inventory');
expect(workflowJobTemplateData.summary_fields.inventory).toHaveProperty('name', 'Production Servers');
});
test('should have the correct workflow job template list response format', () => {
const workflowJobTemplateList = {
count: 2,
next: null,
previous: null,
results: [
{
id: 33,
name: 'CI/CD Pipeline',
description: 'Complete CI/CD pipeline for application deployment',
status: 'successful'
},
{
id: 34,
name: 'Infrastructure Setup',
description: 'Setup complete infrastructure',
status: 'successful'
}
]
};
expect(workflowJobTemplateList).toHaveProperty('count');
expect(workflowJobTemplateList).toHaveProperty('next');
expect(workflowJobTemplateList).toHaveProperty('previous');
expect(workflowJobTemplateList).toHaveProperty('results');
expect(Array.isArray(workflowJobTemplateList.results)).toBe(true);
expect(workflowJobTemplateList.results).toHaveLength(2);
const firstTemplate = workflowJobTemplateList.results[0];
expect(firstTemplate).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
description: expect.any(String),
status: expect.any(String)
}));
expect(firstTemplate.id).toBe(33);
expect(firstTemplate.name).toBe('CI/CD Pipeline');
expect(firstTemplate.description).toBe('Complete CI/CD pipeline for application deployment');
expect(firstTemplate.status).toBe('successful');
});
it('should have the correct workflow job template launch response format', () => {
const launchResponse = {
id: 200,
type: 'workflow_job',
url: '/api/v2/workflow_jobs/200/',
related: {
workflow_job_template: '/api/v2/workflow_job_templates/33/'
},
workflow_job_template: 33,
name: 'CI/CD Pipeline',
status: 'pending',
started: null,
finished: null,
elapsed: 0
};
expect(launchResponse).toEqual(expect.objectContaining({
id: expect.any(Number),
type: expect.any(String),
status: expect.any(String),
workflow_job_template: expect.any(Number)
}));
expect(launchResponse.id).toBe(200);
expect(launchResponse.type).toBe('workflow_job');
expect(launchResponse.status).toBe('pending');
expect(launchResponse.workflow_job_template).toBe(33);
});
test('should have the correct AI-friendly workflow job template format', () => {
const aiFriendlyWorkflowJobTemplate = {
id: 33,
name: 'CI/CD Pipeline',
description: 'Complete CI/CD pipeline for application deployment',
status: 'successful',
inventory_name: 'Production Servers',
last_job_status: 'successful',
last_job_id: 200,
created_by: 'admin',
ui_url: 'https://awx.example.com/#/templates/workflow_job_template/33'
};
expect(aiFriendlyWorkflowJobTemplate).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
description: expect.any(String),
status: expect.any(String),
inventory_name: expect.any(String),
last_job_status: expect.any(String),
last_job_id: expect.any(Number),
created_by: expect.any(String),
ui_url: expect.any(String)
}));
expect(aiFriendlyWorkflowJobTemplate.name).toBe('CI/CD Pipeline');
expect(aiFriendlyWorkflowJobTemplate.description).toBe('Complete CI/CD pipeline for application deployment');
expect(aiFriendlyWorkflowJobTemplate.status).toBe('successful');
expect(aiFriendlyWorkflowJobTemplate.inventory_name).toBe('Production Servers');
expect(aiFriendlyWorkflowJobTemplate.last_job_status).toBe('successful');
expect(aiFriendlyWorkflowJobTemplate.last_job_id).toBe(200);
expect(aiFriendlyWorkflowJobTemplate.created_by).toBe('admin');
expect(aiFriendlyWorkflowJobTemplate.ui_url).toBe('https://awx.example.com/#/templates/workflow_job_template/33');
});
it('should have the correct workflow job data structure', () => {
const workflowJobData = {
id: 200,
name: 'CI/CD Pipeline',
description: 'Complete CI/CD pipeline for application deployment',
workflow_job_template: 33,
status: 'successful',
started: '2023-04-15T10:30:00Z',
finished: '2023-04-15T10:45:00Z',
elapsed: 900,
summary_fields: {
workflow_job_template: { id: 33, name: 'CI/CD Pipeline' },
inventory: { id: 15, name: 'Production Servers' },
created_by: { username: 'admin', id: 1 }
}
};
expect(workflowJobData).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
status: expect.any(String),
started: expect.any(String),
finished: expect.any(String)
}));
expect(workflowJobData.id).toBe(200);
expect(workflowJobData.name).toBe('CI/CD Pipeline');
expect(workflowJobData.status).toBe('successful');
expect(workflowJobData).toHaveProperty('summary_fields');
expect(workflowJobData.summary_fields).toHaveProperty('workflow_job_template');
expect(workflowJobData.summary_fields.workflow_job_template).toHaveProperty('name', 'CI/CD Pipeline');
});
it('should correctly format workflow job template parameters for operations', async () => {
debug('Starting workflow job template parameters test');
(0, nock_1.default)('http://localhost:8052')
.get('/api/v2/workflow_job_templates')
.reply(200, { results: [] });
const getWorkflowTemplateParams = {
resource: 'workflowJobTemplate',
action: 'get',
templateId: null,
workflowTemplateName: 'CI/CD Pipeline'
};
const launchWorkflowTemplateParams = {
resource: 'workflowJobTemplate',
action: 'launch',
templateId: null,
workflowTemplateName: 'CI/CD Pipeline',
extraVars: '{"environment": "production"}'
};
expect(getWorkflowTemplateParams).toMatchObject({
resource: 'workflowJobTemplate',
action: 'get',
workflowTemplateName: 'CI/CD Pipeline'
});
expect(getWorkflowTemplateParams.templateId).toBeNull();
expect(launchWorkflowTemplateParams).toMatchObject({
resource: 'workflowJobTemplate',
action: 'launch',
workflowTemplateName: 'CI/CD Pipeline',
extraVars: '{"environment": "production"}'
});
expect(launchWorkflowTemplateParams.templateId).toBeNull();
debug('Completed workflow job template parameters test');
});
it('should have the correct workflow job with nodes structure', () => {
const workflowJobWithNodes = {
id: 200,
name: 'CI/CD Pipeline',
status: 'successful',
started: '2023-04-15T10:30:00Z',
finished: '2023-04-15T10:45:00Z',
workflow_job_template: 33,
workflow_nodes: [
{
id: 1001,
job: 201,
summary_fields: {
job: {
id: 201,
name: 'Run Tests',
status: 'successful',
type: 'job'
}
}
},
{
id: 1002,
job: 202,
summary_fields: {
job: {
id: 202,
name: 'Build Application',
status: 'successful',
type: 'job'
}
}
},
{
id: 1003,
job: 203,
summary_fields: {
job: {
id: 203,
name: 'Deploy Application',
status: 'successful',
type: 'job'
}
}
}
]
};
expect(workflowJobWithNodes).toHaveProperty('id');
expect(workflowJobWithNodes).toHaveProperty('name');
expect(workflowJobWithNodes).toHaveProperty('status');
expect(workflowJobWithNodes).toHaveProperty('workflow_nodes');
expect(Array.isArray(workflowJobWithNodes.workflow_nodes)).toBe(true);
expect(workflowJobWithNodes.workflow_nodes).toHaveLength(3);
const firstNode = workflowJobWithNodes.workflow_nodes[0];
expect(firstNode).toEqual(expect.objectContaining({
id: expect.any(Number),
job: expect.any(Number),
summary_fields: {
job: expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
status: expect.any(String),
type: expect.any(String)
})
}
}));
expect(firstNode.job).toBe(201);
expect(firstNode.summary_fields.job).toHaveProperty('status', 'successful');
});
});
//# sourceMappingURL=WorkflowJobTemplateStandalone.test.js.map