UNPKG

n8n-nodes-awx

Version:

n8n node to interact with Ansible AWX/Tower with improved type safety

82 lines 3.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mockGlobalRequest = mockGlobalRequest; const nock_1 = __importDefault(require("nock")); const testDataFactory_1 = require("./testDataFactory"); const mockInventories = [ (0, testDataFactory_1.inventoryFactory)({ id: 1, name: 'Test Inventory 1' }), (0, testDataFactory_1.inventoryFactory)({ id: 2, name: 'Test Inventory 2' }) ]; function mockGlobalRequest() { const awxBaseUrl = 'http://localhost:8052'; const mockApiResponse = (path, method, response) => { (0, nock_1.default)(awxBaseUrl) .intercept(path, method) .reply(200, response); }; (0, nock_1.default)(awxBaseUrl) .persist() .get('/api/v2/inventories/') .reply(200, { count: mockInventories.length, next: null, previous: null, results: mockInventories }); (0, nock_1.default)(awxBaseUrl) .persist() .get(/\/api\/v2\/inventories\/\d+\/$/) .reply(200, (uri) => { const id = parseInt(uri.split('/').filter(Boolean).pop() || '0', 10); const inventory = mockInventories.find(i => i.id === id); return inventory || { status: 404, message: 'Not found' }; }); (0, nock_1.default)(awxBaseUrl) .persist() .post('/api/v2/inventories/') .reply(201, (_uri, requestBody) => { const body = requestBody; const newId = Math.max(0, ...mockInventories.map(i => i.id)) + 1; const newInventory = (0, testDataFactory_1.inventoryFactory)({ id: newId, name: body.name, description: body.description || '', organization: body.organization || 1 }); mockInventories.push(newInventory); return newInventory; }); (0, nock_1.default)(awxBaseUrl) .persist() .put(/\/api\/v2\/inventories\/\d+\/$/) .reply(200, (uri, requestBody) => { const id = parseInt(uri.split('/').filter(Boolean).pop() || '0', 10); const index = mockInventories.findIndex(i => i.id === id); if (index === -1) { return { status: 404, message: 'Not found' }; } const body = requestBody; const updatedInventory = { ...mockInventories[index], ...body }; mockInventories[index] = updatedInventory; return updatedInventory; }); (0, nock_1.default)(awxBaseUrl) .persist() .delete(/\/api\/v2\/inventories\/\d+\/$/) .reply(204, (uri) => { const id = parseInt(uri.split('/').filter(Boolean).pop() || '0', 10); const index = mockInventories.findIndex(i => i.id === id); if (index !== -1) { mockInventories.splice(index, 1); } return {}; }); mockApiResponse('/api/v2/projects/', 'GET', { count: 1, results: [(0, testDataFactory_1.projectFactory)()] }); } //# sourceMappingURL=globalRequestMock.js.map