n8n-nodes-awx
Version:
n8n node to interact with Ansible AWX/Tower with improved type safety
284 lines • 12.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
describe('AWX Job Template Operations - Data Structures', () => {
test('should have the correct job template data structure', () => {
const jobTemplateData = {
id: 42,
name: 'Deploy Web Application',
description: 'Deploy the web application to production',
job_type: 'run',
inventory: 15,
project: 10,
playbook: 'deploy.yml',
ask_variables_on_launch: true,
ask_limit_on_launch: true,
ask_tags_on_launch: true,
ask_skip_tags_on_launch: true,
ask_job_type_on_launch: false,
ask_inventory_on_launch: false,
ask_credential_on_launch: false,
survey_enabled: true,
become_enabled: true,
diff_mode: false,
allow_simultaneous: false,
status: 'successful',
last_job_run: '2023-04-15T10:30:00Z',
summary_fields: {
inventory: { id: 15, name: 'Production Servers' },
project: { id: 10, name: 'Web App Project' },
last_job: { id: 100, status: 'successful' },
created_by: { username: 'admin', id: 1 },
credentials: [
{ id: 5, name: 'AWS Production', credential_type: 1 }
]
}
};
expect(jobTemplateData).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
description: expect.any(String),
job_type: expect.any(String),
inventory: expect.any(Number),
project: expect.any(Number),
playbook: expect.any(String),
ask_variables_on_launch: expect.any(Boolean),
survey_enabled: expect.any(Boolean),
status: expect.any(String)
}));
expect(jobTemplateData).toHaveProperty('id');
expect(jobTemplateData).toHaveProperty('name');
expect(jobTemplateData).toHaveProperty('job_type');
expect(jobTemplateData).toHaveProperty('inventory');
expect(jobTemplateData).toHaveProperty('project');
expect(jobTemplateData).toHaveProperty('playbook');
expect(jobTemplateData).toHaveProperty('ask_variables_on_launch');
expect(jobTemplateData).toHaveProperty('ask_limit_on_launch');
expect(jobTemplateData).toHaveProperty('ask_tags_on_launch');
expect(jobTemplateData).toHaveProperty('ask_skip_tags_on_launch');
expect(jobTemplateData).toHaveProperty('ask_job_type_on_launch');
expect(jobTemplateData).toHaveProperty('summary_fields');
expect(jobTemplateData.summary_fields).toHaveProperty('inventory');
expect(jobTemplateData.summary_fields.inventory).toHaveProperty('name', 'Production Servers');
expect(jobTemplateData.summary_fields).toHaveProperty('project');
expect(jobTemplateData.summary_fields.project).toHaveProperty('name', 'Web App Project');
});
test('should have the correct job template list response format', () => {
const jobTemplateListResponse = {
count: 2,
next: null,
previous: null,
results: [
{
id: 42,
name: 'Deploy Web Application',
description: 'Deploy the web application to production',
job_type: 'run',
status: 'successful',
last_job_run: '2023-04-15T10:30:00Z'
},
{
id: 43,
name: 'Run Database Migrations',
description: 'Run database schema migrations',
job_type: 'run',
inventory: 16,
project: 11,
playbook: 'migrate.yml',
ask_variables_on_launch: true,
ask_limit_on_launch: true,
ask_tags_on_launch: true,
ask_skip_tags_on_launch: true,
ask_job_type_on_launch: false,
ask_inventory_on_launch: false,
ask_credential_on_launch: false,
survey_enabled: true,
become_enabled: true,
diff_mode: false,
allow_simultaneous: false,
status: 'successful',
last_job_run: '2023-04-14T09:15:00Z',
summary_fields: {
inventory: { id: 16, name: 'Database Servers' },
project: { id: 11, name: 'Database Project' },
last_job: { id: 101, status: 'successful' },
created_by: { username: 'admin', id: 1 },
credentials: [
{ id: 6, name: 'AWS Database', credential_type: 1 }
]
}
}
]
};
expect(jobTemplateListResponse).toHaveProperty('count');
expect(jobTemplateListResponse).toHaveProperty('next');
expect(jobTemplateListResponse).toHaveProperty('previous');
expect(jobTemplateListResponse).toHaveProperty('results');
expect(Array.isArray(jobTemplateListResponse.results)).toBe(true);
expect(jobTemplateListResponse.results).toHaveLength(2);
const firstTemplate = jobTemplateListResponse.results[0];
expect(firstTemplate).toEqual(expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
description: expect.any(String),
job_type: expect.any(String),
status: expect.any(String),
last_job_run: expect.any(String)
}));
expect(firstTemplate.id).toBe(42);
expect(firstTemplate.name).toBe('Deploy Web Application');
expect(firstTemplate.description).toBe('Deploy the web application to production');
expect(firstTemplate.job_type).toBe('run');
expect(firstTemplate.status).toBe('successful');
});
test('should have the correct job template launch response format', () => {
const launchResponse = {
id: 100,
type: 'job',
url: '/api/v2/jobs/100/',
related: {
job_template: '/api/v2/job_templates/42/'
},
job: 42,
status: 'pending',
name: 'Deploy Web Application',
started: null,
finished: null,
elapsed: 0,
ignored_fields: {},
summary_fields: {
job_template: {
id: 42,
name: 'Deploy Web Application',
description: 'Deploy the web application to production'
}
}
};
expect(launchResponse).toEqual(expect.objectContaining({
id: expect.any(Number),
type: expect.any(String),
status: expect.any(String),
job: expect.any(Number),
ignored_fields: expect.any(Object)
}));
expect(launchResponse.id).toBe(100);
expect(launchResponse.type).toBe('job');
expect(launchResponse.status).toBe('pending');
expect(launchResponse.job).toBe(42);
expect(launchResponse.ignored_fields).toEqual({});
});
it('should have the correct AI-friendly job template format', () => {
const aiFriendlyJobTemplate = {
id: 42,
name: 'Deploy Web Application',
description: 'Deploy the web application to production',
job_type: 'run',
inventory_name: 'Production Servers',
project_name: 'Web App Project',
playbook: 'deploy.yml',
status: 'successful',
last_job_status: 'successful',
last_job_id: 100,
created_by: 'admin',
ui_url: 'https://awx.example.com/#/templates/job_template/42',
survey_enabled: true,
allow_simultaneous: false,
ask_variables_on_launch: true
};
expect(aiFriendlyJobTemplate).toMatchObject({
id: expect.any(Number),
name: 'Deploy Web Application',
job_type: expect.any(String),
inventory_name: 'Production Servers',
project_name: 'Web App Project',
playbook: 'deploy.yml',
status: 'successful',
last_job_status: 'successful',
last_job_id: expect.any(Number),
created_by: 'admin',
ui_url: 'https://awx.example.com/#/templates/job_template/42',
survey_enabled: true,
allow_simultaneous: false,
ask_variables_on_launch: true
});
expect(aiFriendlyJobTemplate.last_job_id).toBe(100);
});
it('should correctly format job template parameters for operations', () => {
const getJobTemplateParams = {
resource: 'jobTemplate',
action: 'get',
templateId: null,
jobTemplateName: 'Deploy Web Application'
};
const launchJobTemplateParams = {
resource: 'jobTemplate',
action: 'launch',
jobTemplateName: 'Deploy Web Application',
extraVars: '{"environment": "production"}',
limit: 'web_servers',
tags: 'deploy,web',
skipTags: 'migrations',
jobType: 'run'
};
expect(getJobTemplateParams).toHaveProperty('jobTemplateName');
expect(getJobTemplateParams.jobTemplateName).toBe('Deploy Web Application');
expect(getJobTemplateParams).not.toHaveProperty('name');
expect(launchJobTemplateParams).toHaveProperty('jobTemplateName');
expect(launchJobTemplateParams.jobTemplateName).toBe('Deploy Web Application');
expect(launchJobTemplateParams).toHaveProperty('extraVars');
expect(launchJobTemplateParams).toHaveProperty('limit');
expect(launchJobTemplateParams).toHaveProperty('tags');
expect(launchJobTemplateParams).toHaveProperty('skipTags');
expect(launchJobTemplateParams).toHaveProperty('jobType');
});
test('should have the correct job template with survey structure', () => {
const jobTemplateWithSurvey = {
id: 42,
name: 'Deploy Web Application',
description: 'Deploy the web application to production',
survey_enabled: true,
survey: {
name: 'Deployment Options',
description: 'Options for deploying the web application',
spec: [
{
question_name: 'Environment',
question_description: 'Select the environment to deploy to',
required: true,
type: 'multiplechoice',
variable: 'environment',
choices: ['staging', 'production'],
default: 'staging'
},
{
question_name: 'Version',
question_description: 'Version to deploy',
required: true,
type: 'text',
variable: 'app_version'
}
]
},
summary_fields: {
last_job: { id: 100, status: 'successful' },
created_by: { username: 'admin' }
}
};
expect(jobTemplateWithSurvey).toHaveProperty('survey_enabled', true);
expect(jobTemplateWithSurvey).toHaveProperty('survey');
expect(jobTemplateWithSurvey.survey).toMatchObject({
name: 'Deployment Options',
description: 'Options for deploying the web application'
});
expect(Array.isArray(jobTemplateWithSurvey.survey.spec)).toBe(true);
expect(jobTemplateWithSurvey.survey.spec[0]).toMatchObject({
question_name: 'Environment',
question_description: 'Select the environment to deploy to',
required: true,
type: 'multiplechoice',
variable: 'environment',
choices: ['staging', 'production'],
default: 'staging'
});
});
});
//# sourceMappingURL=JobTemplateStandalone.test.js.map