|
| 1 | +const { expect } = require('chai'); |
| 2 | +const { MockRuntime } = require('@axway/api-builder-test-utils'); |
| 3 | +const getPlugin = require('../src'); |
| 4 | +const path = require('path'); |
| 5 | +const fs = require('fs'); |
| 6 | +const nock = require('nock'); |
| 7 | +const envLoader = require('dotenv'); |
| 8 | +const decache = require('decache'); |
| 9 | + |
| 10 | +describe('Test Get custom properties from API-Manager', () => { |
| 11 | + let plugin; |
| 12 | + let flowNode; |
| 13 | + |
| 14 | + // Loads environment variables from .env if the file exists |
| 15 | + const envFilePath = path.join(__dirname, '.env'); |
| 16 | + if (fs.existsSync(envFilePath)) { |
| 17 | + delete process.env.API_MANAGER; // Otherwise it is not overwritten |
| 18 | + envLoader.config({ path: envFilePath }); |
| 19 | + } |
| 20 | + // Delete the cached module |
| 21 | + decache('../config/axway-api-utils.default.js'); |
| 22 | + decache('../../../conf/elasticsearch.default.js'); |
| 23 | + var pluginConfig = require('../config/axway-api-utils.default.js').pluginConfig['api-builder-plugin-axway-api-management']; |
| 24 | + |
| 25 | + beforeEach(async () => { |
| 26 | + plugin = await MockRuntime.loadPlugin(getPlugin,pluginConfig); |
| 27 | + plugin.setOptions({ validateOutputs: true }); |
| 28 | + flowNode = plugin.getFlowNode('axway-api-management'); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('#getCustomPropertiesSingleAPIManager', () => { |
| 32 | + |
| 33 | + it('should return custom properties from a single API-Manager.', async () => { |
| 34 | + nock.cleanAll(); |
| 35 | + nock('https://mocked-api-gateway:8175').get(`/api/portal/v1.3/config/customproperties`).replyWithFile(200, './test/testReplies/apimanager/customPropertiesConfig.json'); |
| 36 | + |
| 37 | + const { value, output } = await flowNode.getCustomPropertiesConfig({ }); |
| 38 | + |
| 39 | + expect(value).to.deep.equal( |
| 40 | + { |
| 41 | + "customProperty1": { |
| 42 | + "label": "Custom Property #1", |
| 43 | + "type": "custom", |
| 44 | + "disabled": false, |
| 45 | + "required": false, |
| 46 | + "permissions": { |
| 47 | + "user": { |
| 48 | + "read": true, |
| 49 | + "write": true, |
| 50 | + "visible": true |
| 51 | + }, |
| 52 | + "admin": { |
| 53 | + "read": true, |
| 54 | + "write": true, |
| 55 | + "visible": true |
| 56 | + }, |
| 57 | + "oadmin": { |
| 58 | + "read": true, |
| 59 | + "write": true, |
| 60 | + "visible": true |
| 61 | + } |
| 62 | + } |
| 63 | + }, |
| 64 | + "customProperty2": { |
| 65 | + "label": "Custom Property #2", |
| 66 | + "type": "select", |
| 67 | + "disabled": false, |
| 68 | + "required": false, |
| 69 | + "permissions": { |
| 70 | + "user": { |
| 71 | + "read": true, |
| 72 | + "write": true, |
| 73 | + "visible": true |
| 74 | + }, |
| 75 | + "admin": { |
| 76 | + "read": true, |
| 77 | + "write": true, |
| 78 | + "visible": true |
| 79 | + }, |
| 80 | + "oadmin": { |
| 81 | + "read": true, |
| 82 | + "write": true, |
| 83 | + "visible": true |
| 84 | + } |
| 85 | + }, |
| 86 | + "options": [ |
| 87 | + { |
| 88 | + "value": "1", |
| 89 | + "label": "Value 1" |
| 90 | + }, |
| 91 | + { |
| 92 | + "value": "2", |
| 93 | + "label": "Value 2" |
| 94 | + }, |
| 95 | + { |
| 96 | + "value": "3", |
| 97 | + "label": "Value 3" |
| 98 | + } |
| 99 | + ] |
| 100 | + }, |
| 101 | + "customProperty3": { |
| 102 | + "label": "Custom Property #3", |
| 103 | + "type": "switch", |
| 104 | + "disabled": false, |
| 105 | + "required": false, |
| 106 | + "permissions": { |
| 107 | + "user": { |
| 108 | + "read": true, |
| 109 | + "write": true, |
| 110 | + "visible": true |
| 111 | + }, |
| 112 | + "admin": { |
| 113 | + "read": true, |
| 114 | + "write": true, |
| 115 | + "visible": true |
| 116 | + }, |
| 117 | + "oadmin": { |
| 118 | + "read": true, |
| 119 | + "write": true, |
| 120 | + "visible": true |
| 121 | + } |
| 122 | + }, |
| 123 | + "options": [ |
| 124 | + { |
| 125 | + "value": true, |
| 126 | + "label": "ON" |
| 127 | + }, |
| 128 | + { |
| 129 | + "value": false, |
| 130 | + "label": "OFF" |
| 131 | + } |
| 132 | + ] |
| 133 | + } |
| 134 | + } |
| 135 | + ); |
| 136 | + expect(output).to.equal('next'); |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments