From cc5bf97e83e9a7d13eedee2d3b27bd1f6c3f096c Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 15 Feb 2020 19:25:32 +0200 Subject: [PATCH 01/14] apack deep parsing wip --- lib/apack.js | 43 ++++++++++++++++++++++++++++++++++++++++--- lib/apack.test.js | 43 +++++++++++++++++++++++++++++++++++++++++-- package-lock.json | 5 +++++ package.json | 1 + 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/lib/apack.js b/lib/apack.js index f2f93f1..fb5b5fb 100644 --- a/lib/apack.js +++ b/lib/apack.js @@ -2,14 +2,16 @@ const xml = require('xml-parse'); const APACK_FILENAME = '.apack-manifest.xml'; const { xmlGetChildrenOf } = require('./utils'); -function getVersionFromApack(str) { - let parsedXML; +function parseXml(xmlStr) { try { - parsedXML = xml.parse(str); + return xml.parse(xmlStr); } catch (error) { throw Error('apack xml parsing error'); } +} +function getVersionFromApack(xmlStr) { + const parsedXML = parseXml(xmlStr); const versionNodeChildren = xmlGetChildrenOf(parsedXML, 'DATA/VERSION'); if (!versionNodeChildren) throw Error('wrong apack xml structure'); const versionText = versionNodeChildren.find(node => node.type === 'text'); @@ -17,7 +19,42 @@ function getVersionFromApack(str) { return versionText.text; } +function xmlElemToDependency(xmlElem) { + if (!xmlElem.childNodes) throw Error('incorrect dependency element'); + console.log(xmlElem.childNodes); + + const expectedTags = new Set(['GROUP_ID', 'ARTIFACT_ID', 'VERSION', 'GIT_URL']); + const tags = xmlElem.childNodes + .filter(n => n.type === 'element' && expectedTags.has(n.tagName) ) + .map(n => [n.tagName, n]); + const depDescription = {}; + for (let [tag, value] of tags) depDescription[tag] = value; + return depDescription; +} + +function getDependencyVersionFromApack(xmlStr, depName) { + const parsedXML = parseXml(xmlStr); + + // Get deps node + let dependencies = xmlGetChildrenOf(parsedXML, 'DATA/DEPENDENCIES'); + if (!dependencies) throw Error('dependency not found'); + + // only elements, remove texts + dependencies = dependencies.filter(n => n.type === 'element'); + if (!dependencies) throw Error('dependency not found'); + + dependencies = dependencies.map(xmlElemToDependency); + console.log(dependencies); + + + // if (!versionNodeChildren) throw Error('wrong apack xml structure'); + // const versionText = versionNodeChildren.find(node => node.type === 'text'); + // if (!versionText) throw Error('wrong apack xml structure'); + return versionText.text; +} + module.exports = { APACK_FILENAME, getVersionFromApack, + getDependencyVersionFromApack, }; diff --git a/lib/apack.test.js b/lib/apack.test.js index fdfee0e..d3d5b5e 100644 --- a/lib/apack.test.js +++ b/lib/apack.test.js @@ -1,4 +1,7 @@ -const { getVersionFromApack } = require('./apack'); +const { + getVersionFromApack, + getDependencyVersionFromApack, +} = require('./apack'); const XML_SAMPLE = ` @@ -14,8 +17,15 @@ const XML_SAMPLE = ` sap.com abap-platform-yy + 1.1.0 https://github.com/SAP/abap-platform-yy.git + + sap.com + abap-platform-XX + 1.2.0 + https://github.com/SAP/abap-platform-xx.git + @@ -27,5 +37,34 @@ test('should getVersionFromApack', () => { }); test('should fail on incorrect XML', () => { - expect(() => getVersionFromApack(XML_SAMPLE.replace('VERSION', 'NOTVERSION'))).toThrow('wrong apack xml structure'); + const malformedXml = XML_SAMPLE.replace('VERSION', 'NOTVERSION'); + expect(() => getVersionFromApack(malformedXml)) + .toThrow('wrong apack xml structure'); +}); + +test('should get version of a dependency', () => { + expect(getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-xx')).toBe('1.2.0'); +}); + +test('should fail on incorrect XML with dependency', () => { + const malformedXml = XML_SAMPLE.replace(/VERSION/g, 'NOTVERSION'); + expect(() => getDependencyVersionFromApack(malformedXml, 'sap.com/abap-platform-xx')) + .toThrow('wrong apack xml structure'); +}); + +test('should fail on missing dependency', () => { + expect(() => getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-zz')) + .toThrow('dependency not found'); +}); + +var parser = require('fast-xml-parser'); +test.only('should parse XML', () => { + var jsonObj = parser.parse(XML_SAMPLE, { + parseNodeValue : false, + arrayMode: false, + }); + console.log(JSON.stringify(jsonObj, null, 2)); + var tObj = parser.getTraversalObj(XML_SAMPLE); + console.log(tObj); + console.log(tObj.child); }); diff --git a/package-lock.json b/package-lock.json index 86fb18d..db0d0c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1739,6 +1739,11 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fast-xml-parser": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.16.0.tgz", + "integrity": "sha512-U+bpScacfgnfNfIKlWHDu4u6rtOaCyxhblOLJ8sZPkhsjgGqdZmVPBhdOyvdMGCDt8CsAv+cssOP3NzQptNt2w==" + }, "fb-watchman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.1.tgz", diff --git a/package.json b/package.json index 9acf9b2..ec5d66e 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "serverless-domain-manager": "^3.3.1" }, "dependencies": { + "fast-xml-parser": "^3.16.0", "xml-parse": "^0.4.0" } } From be5df6bb0bd33553eef49dc4d9a782032fdd0fee Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Tue, 18 Feb 2020 07:44:22 +0200 Subject: [PATCH 02/14] move to another xml parser --- lib/apack.js | 15 +++++----- lib/apack.test.js | 12 -------- lib/utils.js | 7 ++--- lib/utils.test.js | 73 ++++++++++++++++++++++++++++------------------- package-lock.json | 5 ---- package.json | 4 +-- 6 files changed, 56 insertions(+), 60 deletions(-) diff --git a/lib/apack.js b/lib/apack.js index fb5b5fb..ea5a85f 100644 --- a/lib/apack.js +++ b/lib/apack.js @@ -1,10 +1,13 @@ -const xml = require('xml-parse'); +var parser = require('fast-xml-parser'); const APACK_FILENAME = '.apack-manifest.xml'; const { xmlGetChildrenOf } = require('./utils'); function parseXml(xmlStr) { try { - return xml.parse(xmlStr); + return parser.parse(xmlStr, { + parseNodeValue : false, + arrayMode: false, + }); } catch (error) { throw Error('apack xml parsing error'); } @@ -12,11 +15,9 @@ function parseXml(xmlStr) { function getVersionFromApack(xmlStr) { const parsedXML = parseXml(xmlStr); - const versionNodeChildren = xmlGetChildrenOf(parsedXML, 'DATA/VERSION'); - if (!versionNodeChildren) throw Error('wrong apack xml structure'); - const versionText = versionNodeChildren.find(node => node.type === 'text'); - if (!versionText) throw Error('wrong apack xml structure'); - return versionText.text; + const versionNode = xmlGetChildrenOf(parsedXML, 'asx:abap/asx:values/DATA/VERSION'); + if (!versionNode || typeof versionNode !== 'string') throw Error('wrong apack xml structure'); + return versionNode; } function xmlElemToDependency(xmlElem) { diff --git a/lib/apack.test.js b/lib/apack.test.js index d3d5b5e..d766481 100644 --- a/lib/apack.test.js +++ b/lib/apack.test.js @@ -56,15 +56,3 @@ test('should fail on missing dependency', () => { expect(() => getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-zz')) .toThrow('dependency not found'); }); - -var parser = require('fast-xml-parser'); -test.only('should parse XML', () => { - var jsonObj = parser.parse(XML_SAMPLE, { - parseNodeValue : false, - arrayMode: false, - }); - console.log(JSON.stringify(jsonObj, null, 2)); - var tObj = parser.getTraversalObj(XML_SAMPLE); - console.log(tObj); - console.log(tObj.child); -}); diff --git a/lib/utils.js b/lib/utils.js index b8b015d..a2cdca6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -36,12 +36,11 @@ function buildResponse(body, code = 200) { } function xmlGetChildrenOf(xml, path) { - const segments = path.split('/'); + const segments = path.split('/').filter(i => !!i); if (segments.length === 0) throw Error('Unexpected xml drilldown path'); for (const seg of segments) { - const nextNode = xml.find(node => node.type === 'element' && node.tagName === seg); - if (!nextNode || !nextNode.childNodes) return; - xml = nextNode.childNodes; + if (typeof xml !== 'object') throw Error('XML path not found'); + xml = xml[seg]; } return xml; } diff --git a/lib/utils.test.js b/lib/utils.test.js index e32fb57..e8f5733 100644 --- a/lib/utils.test.js +++ b/lib/utils.test.js @@ -31,38 +31,51 @@ test('should buildResponse', () => { }); }); -test('should xmlGetChildrenOf', () => { - const xml = [ +test('should xmlGetChildrenOf new', () => { + const xml = { + 'asx:abap': { + 'asx:values': { + 'DATA': { + 'GROUP_ID': 'sap.com', + 'ARTIFACT_ID': 'abap-platform-jak', + 'VERSION': '0.2', + 'REPOSITORY_TYPE': 'abapGit', + 'GIT_URL': 'https://github.com/SAP/abap-platform-jak.git', + 'DEPENDENCIES': { + 'item': [ + { + 'GROUP_ID': 'sap.com', + 'ARTIFACT_ID': 'abap-platform-yy', + 'VERSION': '1.1.0', + 'GIT_URL': 'https://github.com/SAP/abap-platform-yy.git' + }, + { + 'GROUP_ID': 'sap.com', + 'ARTIFACT_ID': 'abap-platform-XX', + 'VERSION': '1.2.0', + 'GIT_URL': 'https://github.com/SAP/abap-platform-xx.git' + } + ] + } + } + } + } + }; + expect(xmlGetChildrenOf(xml, 'asx:abap/asx:values/DATA/VERSION')).toEqual('0.2'); + expect(xmlGetChildrenOf(xml, 'asx:abap/asx:values/DATA/DEPENDENCIES/item')).toEqual([ { - type: 'element', - tagName: '?xml', + 'GROUP_ID': 'sap.com', + 'ARTIFACT_ID': 'abap-platform-yy', + 'VERSION': '1.1.0', + 'GIT_URL': 'https://github.com/SAP/abap-platform-yy.git' }, { - type: 'element', - tagName: 'DATA', - childNodes: [ - { - type: 'text', - text: 'blah blah', - }, - { - type: 'element', - tagName: 'VERSION', - childNodes: [ - { - type: 'text', - text: 'target', - }, - ], - }, - ], - }, - ]; - expect(xmlGetChildrenOf(xml, 'DATA/VERSION')).toEqual([ - { - type: 'text', - text: 'target', - }, + 'GROUP_ID': 'sap.com', + 'ARTIFACT_ID': 'abap-platform-XX', + 'VERSION': '1.2.0', + 'GIT_URL': 'https://github.com/SAP/abap-platform-xx.git' + } ]); - expect(xmlGetChildrenOf(xml, 'DATA/OTHER')).toBeUndefined(); + expect(() => xmlGetChildrenOf(xml, 'DATA/OTHER')).toThrow('XML path not found'); + expect(() => xmlGetChildrenOf(xml, '')).toThrow('Unexpected xml drilldown path'); }); diff --git a/package-lock.json b/package-lock.json index db0d0c4..48c7166 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5529,11 +5529,6 @@ "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", "dev": true }, - "xml-parse": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/xml-parse/-/xml-parse-0.4.0.tgz", - "integrity": "sha512-+wgw8F9dPiBEOD91RnzJ+s9HJcW5jNR8fgtmqqTpa2YEC22TnExMJPnE5tzEbfyPyjeVZqLdLPj6M0k6oqPM0g==" - }, "xml2js": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", diff --git a/package.json b/package.json index ec5d66e..2937a98 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "playground.js", "scripts": { "test": "jest", + "test:watch": "jest --watch", "lint": "eslint . lib", "deploy-dev": "bash ./bin/deploy-dev.sh", "deploy-prod": "bash ./bin/deploy-dev.sh", @@ -18,7 +19,6 @@ "serverless-domain-manager": "^3.3.1" }, "dependencies": { - "fast-xml-parser": "^3.16.0", - "xml-parse": "^0.4.0" + "fast-xml-parser": "^3.16.0" } } From 515e8cbbb4818d35575b88e66f1b495e357626f5 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Tue, 18 Feb 2020 08:00:14 +0200 Subject: [PATCH 03/14] dependency apack logic --- lib/apack.js | 42 ++++++++++++++---------------------------- lib/apack.test.js | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/apack.js b/lib/apack.js index ea5a85f..4a8a42b 100644 --- a/lib/apack.js +++ b/lib/apack.js @@ -20,38 +20,24 @@ function getVersionFromApack(xmlStr) { return versionNode; } -function xmlElemToDependency(xmlElem) { - if (!xmlElem.childNodes) throw Error('incorrect dependency element'); - console.log(xmlElem.childNodes); - - const expectedTags = new Set(['GROUP_ID', 'ARTIFACT_ID', 'VERSION', 'GIT_URL']); - const tags = xmlElem.childNodes - .filter(n => n.type === 'element' && expectedTags.has(n.tagName) ) - .map(n => [n.tagName, n]); - const depDescription = {}; - for (let [tag, value] of tags) depDescription[tag] = value; - return depDescription; -} - function getDependencyVersionFromApack(xmlStr, depName) { + if (!depName || typeof depName !== 'string') throw Error('Incorrect dependency name'); + depName = depName.toLowerCase(); const parsedXML = parseXml(xmlStr); // Get deps node - let dependencies = xmlGetChildrenOf(parsedXML, 'DATA/DEPENDENCIES'); - if (!dependencies) throw Error('dependency not found'); - - // only elements, remove texts - dependencies = dependencies.filter(n => n.type === 'element'); - if (!dependencies) throw Error('dependency not found'); - - dependencies = dependencies.map(xmlElemToDependency); - console.log(dependencies); - - - // if (!versionNodeChildren) throw Error('wrong apack xml structure'); - // const versionText = versionNodeChildren.find(node => node.type === 'text'); - // if (!versionText) throw Error('wrong apack xml structure'); - return versionText.text; + const data = xmlGetChildrenOf(parsedXML, 'asx:abap/asx:values/DATA'); + if (!data.DEPENDENCIES + || !data.DEPENDENCIES.item + || !Array.isArray(data.DEPENDENCIES.item)) throw Error('dependency not found'); + const dependencies = data.DEPENDENCIES.item.filter(i => typeof i === 'object'); + + // Find target + const target = dependencies.find(i => [i.GROUP_ID, i.ARTIFACT_ID].join('/').toLowerCase() === depName); + if (!target) throw Error('dependency not found'); + if (!target.VERSION) throw Error('dependency version not found'); + + return target.VERSION; } module.exports = { diff --git a/lib/apack.test.js b/lib/apack.test.js index d766481..6bbf063 100644 --- a/lib/apack.test.js +++ b/lib/apack.test.js @@ -46,13 +46,31 @@ test('should get version of a dependency', () => { expect(getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-xx')).toBe('1.2.0'); }); -test('should fail on incorrect XML with dependency', () => { +test('should fail on dependency without version', () => { const malformedXml = XML_SAMPLE.replace(/VERSION/g, 'NOTVERSION'); expect(() => getDependencyVersionFromApack(malformedXml, 'sap.com/abap-platform-xx')) - .toThrow('wrong apack xml structure'); + .toThrow('dependency version not found'); }); test('should fail on missing dependency', () => { expect(() => getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-zz')) .toThrow('dependency not found'); }); + +test('should fail on missing dependencies node', () => { + expect(() => getDependencyVersionFromApack(` + + + + + sap.com + abap-platform-jak + 0.2 + abapGit + https://github.com/SAP/abap-platform-jak.git + + + + `, 'sap.com/abap-platform-zz')) + .toThrow('dependency not found'); +}); From 7ea61ece1ca8b893fe47c8c67e244aa26e6f5df5 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 10:13:48 +0200 Subject: [PATCH 04/14] remove comments --- lib/params.test.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/params.test.js b/lib/params.test.js index 4ef9a15..f93baf3 100644 --- a/lib/params.test.js +++ b/lib/params.test.js @@ -71,8 +71,6 @@ test('should fail on incorrect symbols', () => { test('should parse correct path', () => { expect(parsePathParams({ - // resource: '/version-shield-json/{sourcePath}', - // path: '/version-shield-json/github/sbcgua/repo_name/src/zif.abap/attr_name', pathParameters: { sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name' }, @@ -84,8 +82,6 @@ test('should parse correct path', () => { attr: 'attr_name', }); expect(parsePathParams({ - // resource: '/version-shield-json/{sourcePath}', - // path: '/version-shield-json/github/sbcgua/repo_name/src/zif.abap', pathParameters: { sourcePath: 'github/sbcgua/repo_name/src/zif.abap' }, @@ -99,15 +95,11 @@ test('should parse correct path', () => { test('should throw on incorrect path', () => { expect(() => parsePathParams({ - // resource: '/version-shield-json/{sourcePath}', - // path: '/version-shield-json/', pathParameters: { sourcePath: '' }, })).toThrow('Unexpected source path'); expect(() => parsePathParams({ - // resource: '/version-shield-json/{sourcePath}', - // path: '/version-shield-json/github/sbcgua/repo_name/src/zif.abap/attr_name/extra', pathParameters: { sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name/extra' }, From a54e03fe79c63a928fdc6f8ac0212952814f8db8 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:10:44 +0200 Subject: [PATCH 05/14] params parsing/validation supports apack deps --- lib/params.js | 41 ++++--- lib/params.test.js | 266 +++++++++++++++++++++++++++++---------------- package-lock.json | 5 + package.json | 3 +- 4 files changed, 210 insertions(+), 105 deletions(-) diff --git a/lib/params.js b/lib/params.js index bcfb9c9..a39a5b1 100644 --- a/lib/params.js +++ b/lib/params.js @@ -1,6 +1,8 @@ const { enumify, } = require('./utils'); +const { APACK_FILENAME } = require('./apack'); +const pick = require('lodash.pick'); function parsePathParams({pathParameters}) { if (!pathParameters) throw Error('Unexpected path'); @@ -12,6 +14,7 @@ function parsePathParams({pathParameters}) { let expected = STATES.TYPE; let params = {}; for (const seg of segments) { + const appendSeg = (param) => param ? (param + '/' + seg) : seg; switch (expected) { case STATES.TYPE: params.type = seg; @@ -26,13 +29,17 @@ function parsePathParams({pathParameters}) { expected++; break; case STATES.FILE: - if (/\.abap$/i.test(seg)) expected++; - params.file ? (params.file += '/') : (params.file = ''); - params.file += seg; + params.file = appendSeg(params.file); + if (/\.abap$/i.test(seg) || seg === APACK_FILENAME) expected++; break; case STATES.ATTR: - params.attr = seg; - expected++; + if (params.file === APACK_FILENAME) { + if (!params.apackExtra) params.apackExtra = seg; + else params.apackExtraParam = appendSeg(params.apackExtraParam); + } else { + params.attr = seg; + expected++; + } break; case STATES.END: throw Error('Unexpect path segment'); @@ -43,6 +50,12 @@ function parsePathParams({pathParameters}) { return params; } +function applyDefaults(params) { + const final = {...params}; + if (!final.attr && final.file !== APACK_FILENAME) final.attr = 'version'; + return final; +} + function validateQueryParams(params) { if (!params.type) throw Error('Repository type not specified'); // 400 bad request if (!params.owner) throw Error('Owner not specified'); @@ -52,19 +65,21 @@ function validateQueryParams(params) { const supportedTypes = ['github']; if (!supportedTypes.includes(params.type)) throw Error('Repository type not supported'); + if ((params.apackExtra || params.apackExtraParam) && params.file !== APACK_FILENAME) throw Error('Apack params consistency failed'); + + const supportedApackExtraActions = ['dependencies']; + if (params.apackExtra && !supportedApackExtraActions.includes(params.apackExtra)) throw Error('Wrong apack extra action'); + + const allAttrs = ['type', 'owner', 'repo', 'file', 'attr', 'apackExtra', 'apackExtraParam']; const allowedSymbols = /^[-_.,0-9a-zA-Z/]+$/; - for (const attr of ['owner', 'repo', 'file', 'attr']) { + for (const attr of allAttrs) { if (!Object.prototype.hasOwnProperty.call(params, attr)) continue; if (!allowedSymbols.test(params[attr])) throw Error(`[${attr}] has disallowed symbols`); } - return { - type: params.type, - owner: params.owner, - repo: params.repo, - file: params.file, - attr: params.attr || 'version', - }; + if (params.apackExtra === 'dependencies' && !params.apackExtraParam) throw Error('dependencies action expect params'); + + return applyDefaults(pick(params, allAttrs)); } module.exports = { diff --git a/lib/params.test.js b/lib/params.test.js index f93baf3..1dbcd87 100644 --- a/lib/params.test.js +++ b/lib/params.test.js @@ -3,105 +3,189 @@ const { validateQueryParams, } = require('./params'); -test('should validate correct params', () => { - const params = { - type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - attr: 'version_attr', - }; - const validated = validateQueryParams(params); - expect(validated).toEqual(params); -}); +describe('regular Validator tests', () => { + test('should validate correct params', () => { + const params = { + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + attr: 'version_attr', + }; + const validated = validateQueryParams(params); + expect(validated).toEqual(params); + }); -test('should validate correct params without version', () => { - const params = { - type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - }; - const validated = validateQueryParams(params); - expect(validated).toEqual({...params, attr: 'version'}); -}); + test('should validate correct params without version', () => { + const params = { + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + }; + const validated = validateQueryParams(params); + expect(validated).toEqual({...params, attr: 'version'}); + }); -test('should fail on incorrect params', () => { - expect(() => validateQueryParams({ - // type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - })).toThrow('Repository type not specified'); - expect(() => validateQueryParams({ - type: 'github', - // owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - })).toThrow('Owner'); - expect(() => validateQueryParams({ - type: 'github', - owner: 'sbcgua', - // repo: 'repo_name', - file: 'src/zif.abap', - })).toThrow('Repository name'); - expect(() => validateQueryParams({ - type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - // file: 'src/zif.abap', - })).toThrow('Source file'); - expect(() => validateQueryParams({ - type: 'xxx', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - })).toThrow('Repository type not supported'); + test('should fail on incorrect params', () => { + expect(() => validateQueryParams({ + // type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + })).toThrow('Repository type not specified'); + expect(() => validateQueryParams({ + type: 'github', + // owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + })).toThrow('Owner'); + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua', + // repo: 'repo_name', + file: 'src/zif.abap', + })).toThrow('Repository name'); + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + // file: 'src/zif.abap', + })).toThrow('Source file'); + expect(() => validateQueryParams({ + type: 'xxx', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + })).toThrow('Repository type not supported'); -}); + }); -test('should fail on incorrect symbols', () => { - expect(() => validateQueryParams({ - type: 'github', - owner: 'sbcgua?', - repo: 'repo_name', - file: 'src/zif.abap', - })).toThrow('[owner] has disallowed symbols'); + test('should fail on incorrect symbols', () => { + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua?', + repo: 'repo_name', + file: 'src/zif.abap', + })).toThrow('[owner] has disallowed symbols'); + }); }); -test('should parse correct path', () => { - expect(parsePathParams({ - pathParameters: { - sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name' - }, - })).toEqual({ - type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', - attr: 'attr_name', + +describe('Regular Parser tests', () => { + test('should parse correct path', () => { + expect(parsePathParams({ + pathParameters: { + sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name' + }, + })).toEqual({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + attr: 'attr_name', + }); + expect(parsePathParams({ + pathParameters: { + sourcePath: 'github/sbcgua/repo_name/src/zif.abap' + }, + })).toEqual({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'src/zif.abap', + }); }); - expect(parsePathParams({ - pathParameters: { - sourcePath: 'github/sbcgua/repo_name/src/zif.abap' - }, - })).toEqual({ - type: 'github', - owner: 'sbcgua', - repo: 'repo_name', - file: 'src/zif.abap', + + test('should throw on incorrect path', () => { + expect(() => parsePathParams({ + pathParameters: { + sourcePath: '' + }, + })).toThrow('Unexpected source path'); + expect(() => parsePathParams({ + pathParameters: { + sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name/extra' + }, + })).toThrow('Unexpect path segment'); }); }); -test('should throw on incorrect path', () => { - expect(() => parsePathParams({ - pathParameters: { - sourcePath: '' - }, - })).toThrow('Unexpected source path'); - expect(() => parsePathParams({ - pathParameters: { - sourcePath: 'github/sbcgua/repo_name/src/zif.abap/attr_name/extra' - }, - })).toThrow('Unexpect path segment'); +describe('apack Parser tests', () => { + test('should parse apack path', () => { + expect(parsePathParams({ + pathParameters: { + sourcePath: 'github/sbcgua/repo_name/.apack-manifest.xml' + }, + })).toEqual({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + }); + }); + test('should parse apack path with Extras', () => { + expect(parsePathParams({ + pathParameters: { + sourcePath: 'github/sbcgua/repo_name/.apack-manifest.xml/extra/extrap1/extrap2' + }, + })).toEqual({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + apackExtra: 'extra', + apackExtraParam: 'extrap1/extrap2', + }); + }); }); + +describe('apack Validator tests', () => { + test('should validate correct apack path', () => { + const params = { + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + }; + const validated = validateQueryParams(params); + expect(validated).toEqual(params); + }); + test('should validate correct apack path with Deps', () => { + const params = { + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + apackExtra: 'dependencies', + apackExtraParam: 'group/artifact' + }; + const validated = validateQueryParams(params); + expect(validated).toEqual(params); + }); + test('should fail on wrong extra', () => { + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + apackExtra: 'xyz', + apackExtraParam: 'group/artifact' + })).toThrow('Wrong apack extra action'); + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: 'somefile.abap', + apackExtra: 'xyz', + apackExtraParam: 'group/artifact' + })).toThrow('Apack params consistency failed'); + expect(() => validateQueryParams({ + type: 'github', + owner: 'sbcgua', + repo: 'repo_name', + file: '.apack-manifest.xml', + apackExtra: 'dependencies', + })).toThrow('dependencies action expect params'); + }); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 48c7166..3f22c6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3623,6 +3623,11 @@ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, + "lodash.pick": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz", + "integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM=" + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", diff --git a/package.json b/package.json index 2937a98..984dd23 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "serverless-domain-manager": "^3.3.1" }, "dependencies": { - "fast-xml-parser": "^3.16.0" + "fast-xml-parser": "^3.16.0", + "lodash.pick": "^4.4.0" } } From 4936f14b3ef6224d07ff8933618d7469e6f92bc4 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:26:55 +0200 Subject: [PATCH 06/14] fix but with one dep item --- lib/apack.js | 3 ++- lib/apack.test.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/apack.js b/lib/apack.js index 4a8a42b..1f5f143 100644 --- a/lib/apack.js +++ b/lib/apack.js @@ -29,7 +29,8 @@ function getDependencyVersionFromApack(xmlStr, depName) { const data = xmlGetChildrenOf(parsedXML, 'asx:abap/asx:values/DATA'); if (!data.DEPENDENCIES || !data.DEPENDENCIES.item - || !Array.isArray(data.DEPENDENCIES.item)) throw Error('dependency not found'); + || typeof data.DEPENDENCIES.item !== 'object' ) throw Error('dependency not found'); + if (!Array.isArray(data.DEPENDENCIES.item)) data.DEPENDENCIES.item = [data.DEPENDENCIES.item]; // for a case of one item const dependencies = data.DEPENDENCIES.item.filter(i => typeof i === 'object'); // Find target diff --git a/lib/apack.test.js b/lib/apack.test.js index 6bbf063..7e599e4 100644 --- a/lib/apack.test.js +++ b/lib/apack.test.js @@ -46,6 +46,27 @@ test('should get version of a dependency', () => { expect(getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-xx')).toBe('1.2.0'); }); +test('should get version of a dependency where there is one dependency', () => { + const XML_SAMPLE = ` + + + + + + + sap.com + abap-platform-XX + 1.2.0 + https://github.com/SAP/abap-platform-xx.git + + + + + + `; + expect(getDependencyVersionFromApack(XML_SAMPLE, 'sap.com/abap-platform-xx')).toBe('1.2.0'); +}); + test('should fail on dependency without version', () => { const malformedXml = XML_SAMPLE.replace(/VERSION/g, 'NOTVERSION'); expect(() => getDependencyVersionFromApack(malformedXml, 'sap.com/abap-platform-xx')) From af884cddca284788b5e323d0d3fec9a7a930c49f Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:27:54 +0200 Subject: [PATCH 07/14] handler support apack dependencies --- handler.js | 5 ++++- handler.test.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/handler.js b/handler.js index 9d77652..545260b 100644 --- a/handler.js +++ b/handler.js @@ -18,6 +18,7 @@ const { const { APACK_FILENAME, getVersionFromApack, + getDependencyVersionFromApack, } = require('./lib/apack'); module.exports.getShieldJson = async (event, context) => { @@ -45,7 +46,9 @@ async function handleEvent(event, context) { const url = createUrlFromParams(validatedParams); const srcData = await fetchResource(url); let version = (validatedParams.file === APACK_FILENAME) - ? getVersionFromApack(srcData) + ? validatedParams.apackExtra === 'dependencies' + ? getDependencyVersionFromApack(srcData, validatedParams.apackExtraParam) + : getVersionFromApack(srcData) : parseSourceFile(srcData, validatedParams.attr); validateVersion(version); diff --git a/handler.test.js b/handler.test.js index e405970..3012ba2 100644 --- a/handler.test.js +++ b/handler.test.js @@ -22,6 +22,14 @@ https.get.mockImplementation((url, handler) => { resMock.write(' '); resMock.write(' '); resMock.write(' 0.2'); + resMock.write(' '); + resMock.write(' '); + resMock.write(' sap.com'); + resMock.write(' abap-platform-XX'); + resMock.write(' 1.2.0'); + resMock.write(' https://github.com/SAP/abap-platform-xx.git'); + resMock.write(' '); + resMock.write(' '); resMock.write(' '); resMock.write(' '); resMock.write(''); @@ -69,8 +77,6 @@ describe('test with path params', () => { test('should fail with wrong request', async () => { const event = { - // resource: '/version-shield-json/{sourcePath}', - // path: '/version-shield-json/xxx', pathParameters: { sourcePath: 'xxx' }, @@ -158,4 +164,38 @@ describe('test with apack', () => { expect(console.log).toHaveBeenNthCalledWith(2, 'URL:', 'https://raw.githubusercontent.com/zzz/apack-test/master/.apack-manifest.xml'); expect(console.log).toHaveBeenNthCalledWith(3, 'fetch statusCode: 200'); }); + + test('should work with apack and dependencies', async () => { + const event = { + resource: '/version-shield-json/{sourcePath}', + path: '/version-shield-json/github/zzz/apack-test/.apack-manifest.xml', + pathParameters: { + sourcePath: 'github/zzz/apack-test/.apack-manifest.xml/dependencies/sap.com/abap-platform-xx' + }, + }; + const context = {}; + + global.console = { + log: jest.fn(), + error: jest.fn(), + }; + + await expect(handler.getShieldJson(event, context)).resolves.toEqual({ + statusCode: 200, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + message: 'v1.2.0', + schemaVersion: 1, + label: 'abap package version', + color: 'orange', + }), + }); + + expect(console.log).toHaveBeenNthCalledWith(1, 'Requested path:', event.path); + expect(console.log).toHaveBeenNthCalledWith(2, 'URL:', 'https://raw.githubusercontent.com/zzz/apack-test/master/.apack-manifest.xml'); + expect(console.log).toHaveBeenNthCalledWith(3, 'fetch statusCode: 200'); + }); }); From 3d66b8c41260e319a050737ac5fe261f033f30bd Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:34:41 +0200 Subject: [PATCH 08/14] add local tests --- localtest-apack-deps.js | 20 ++++++++++++++++++++ test.http | 1 + 2 files changed, 21 insertions(+) create mode 100644 localtest-apack-deps.js diff --git a/localtest-apack-deps.js b/localtest-apack-deps.js new file mode 100644 index 0000000..79c6142 --- /dev/null +++ b/localtest-apack-deps.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +const handler = require('./handler'); + +(async function main() { + const event = { + // resource: '/version-shield-json/{sourcePath}', + // path: '/version-shield-json/github/SAP-samples/abap-platform-jak/.apack-manifest.xml', + pathParameters: { + sourcePath: 'github/mbtools/mbt-versions/.apack-manifest.xml/dependencies/github.com/mbtools/mbt-bc-cts-req' + }, + }; + const context = { + + }; + + let result = await handler.getShieldJson(event, context); + if (result instanceof Promise) result = await result; + console.log(result); +})(); diff --git a/test.http b/test.http index 14061af..2d05f33 100644 --- a/test.http +++ b/test.http @@ -20,6 +20,7 @@ GET https://img.shields.io/endpoint?url=https://u0zlg8upk8.execute-api.eu-west-1 GET https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/SAP-samples/abap-platform-jak/.apack-manifest.xml +GET https://dev.shield.abap.space/version-shield-json/github/mbtools/mbt-versions/.apack-manifest.xml/dependencies/github.com/mbtools/mbt-bc-cts-req ############## ### DEV PATH From 277bbe1db0b77b7bc907c7dea41278555f544a52 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:38:05 +0200 Subject: [PATCH 09/14] docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cd84944..e853678 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ For example: [`https://img.shields.io/endpoint?url=https://shield.abap.space/ver - The version is supposed to be in semantic version format - `'X.Y.Z'` or `'vX.Y.Z'`. - if `$PATH` = `.apack-manifest.xml` the version is read directly from that file. +- apack parsing also supports displaying dependency version (see [issue #1](https://github.com/sbcgua/abap-package-version-shield/issues/1)). `'...apack-manifest.xml/dependencies//'`. ### Badge customizing From 34c10f82d1d6617f6bcc5225deb0812a3d287d06 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:45:20 +0200 Subject: [PATCH 10/14] optimize deployment --- serverless.yml | 8 +++++++- test.http | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/serverless.yml b/serverless.yml index 0a41e69..a422dd1 100644 --- a/serverless.yml +++ b/serverless.yml @@ -11,7 +11,13 @@ provider: package: exclude: - secrets - - docs/* + - docs/** + - bin/** + - .github/** + - '*.md' + - localtest* + - '*.http' + - playground* functions: getAbapVersionShieldJson: diff --git a/test.http b/test.http index 2d05f33..0e8d560 100644 --- a/test.http +++ b/test.http @@ -19,7 +19,7 @@ GET https://img.shields.io/endpoint?url=https://u0zlg8upk8.execute-api.eu-west-1 ### With shields.io apack-manifest GET https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/SAP-samples/abap-platform-jak/.apack-manifest.xml - +### GET https://dev.shield.abap.space/version-shield-json/github/mbtools/mbt-versions/.apack-manifest.xml/dependencies/github.com/mbtools/mbt-bc-cts-req ############## From c52b66670c91c9ffde335e6d75136407605814dd Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 11:54:57 +0200 Subject: [PATCH 11/14] prevent too long path --- lib/params.js | 1 + lib/params.test.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/params.js b/lib/params.js index a39a5b1..42aa74e 100644 --- a/lib/params.js +++ b/lib/params.js @@ -9,6 +9,7 @@ function parsePathParams({pathParameters}) { if (!pathParameters.sourcePath) throw Error('Unexpected source path'); const segments = pathParameters.sourcePath.split('/').filter(s => s !== ''); if (segments.length === 0) throw Error('Unexpected path'); + if (segments.length > 20) throw Error('Too many path segments'); const STATES = enumify(['TYPE', 'OWNER', 'REPO', 'FILE', 'ATTR', 'END']); let expected = STATES.TYPE; diff --git a/lib/params.test.js b/lib/params.test.js index 1dbcd87..4c5a636 100644 --- a/lib/params.test.js +++ b/lib/params.test.js @@ -109,6 +109,13 @@ describe('Regular Parser tests', () => { }, })).toThrow('Unexpect path segment'); }); + test('should throw on too long path', () => { + expect(() => parsePathParams({ + pathParameters: { + sourcePath: new Array(21).fill('a').join('/'), + }, + })).toThrow('Too many path segments'); + }); }); describe('apack Parser tests', () => { From 1ab6bf19ace1a82bdad41c452c2e91f20ee6c145 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 12:02:10 +0200 Subject: [PATCH 12/14] update gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ec95785..aa73a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ node_modules jspm_packages +# artifacts +coverage + # Serverless directories .serverless From eacf1a547f244b29531a913bfff566676cda07f8 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 12:36:36 +0200 Subject: [PATCH 13/14] e2e tests --- jest.e2e.config.js | 8 ++++++++ lambda.e2e.test.js | 32 ++++++++++++++++++++++++++++++++ package-lock.json | 6 ++++++ package.json | 8 ++++++++ 4 files changed, 54 insertions(+) create mode 100644 jest.e2e.config.js create mode 100644 lambda.e2e.test.js diff --git a/jest.e2e.config.js b/jest.e2e.config.js new file mode 100644 index 0000000..4d126ad --- /dev/null +++ b/jest.e2e.config.js @@ -0,0 +1,8 @@ +module.exports = { + testMatch: [ + '**/?(*.)+(e2e).(test).[jt]s?(x)', + ], + // "testPathIgnorePatterns": [ + // "/node_modules/", + // ] +}; diff --git a/lambda.e2e.test.js b/lambda.e2e.test.js new file mode 100644 index 0000000..e523b3d --- /dev/null +++ b/lambda.e2e.test.js @@ -0,0 +1,32 @@ +const fetch = require('node-fetch'); +const pick = require('lodash.pick'); + +const PREFIX = ''; +const HOST = 'shield.abap.space'; +const functionName = 'version-shield-json'; +const versionRe = /^v\d{1,3}\.\d{1,3}(\.\d{1,3})?$/i; + +const getUrl = (params) => `https://${PREFIX}${HOST}/${functionName}/${params}`; + +async function validateExpectations(resp) { + expect(resp.ok).toBeTruthy(); + const json = await resp.json(); + expect(typeof json).toBe('object'); + expect(pick(json, ['schemaVersion', 'label', 'color'])).toEqual({ + schemaVersion: 1, + label: 'abap package version', + color: 'orange' + }); + expect(typeof json.message).toBe('string'); + expect(json.message).toMatch(versionRe); +} + +test('should process abap constant', async () => { + const resp = await fetch(getUrl('github/sbcgua/mockup_loader/src/zif_mockup_loader_constants.intf.abap')); + await validateExpectations(resp); +}); + +test('should process abap constant', async () => { + const resp = await fetch(getUrl('github/SAP-samples/abap-platform-jak/.apack-manifest.xml')); + await validateExpectations(resp); +}); diff --git a/package-lock.json b/package-lock.json index 3f22c6e..4611866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3840,6 +3840,12 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", + "dev": true + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", diff --git a/package.json b/package.json index 984dd23..7f0e914 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "test": "jest", "test:watch": "jest --watch", + "test:e2e": "jest -c jest.e2e.config.js", "lint": "eslint . lib", "deploy-dev": "bash ./bin/deploy-dev.sh", "deploy-prod": "bash ./bin/deploy-dev.sh", @@ -16,10 +17,17 @@ "devDependencies": { "eslint": "^6.8.0", "jest": "^24.9.0", + "node-fetch": "^2.6.0", "serverless-domain-manager": "^3.3.1" }, "dependencies": { "fast-xml-parser": "^3.16.0", "lodash.pick": "^4.4.0" + }, + "jest": { + "testPathIgnorePatterns": [ + "/node_modules/", + "e2e" + ] } } From 71b984903a1edee67dd71fc434d1e449c91f60b8 Mon Sep 17 00:00:00 2001 From: Alexander Tsybulsky Date: Sat, 22 Feb 2020 12:42:57 +0200 Subject: [PATCH 14/14] dev e2e --- lambda.e2e.test.js | 9 +++++---- package.json | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lambda.e2e.test.js b/lambda.e2e.test.js index e523b3d..a294302 100644 --- a/lambda.e2e.test.js +++ b/lambda.e2e.test.js @@ -1,12 +1,13 @@ const fetch = require('node-fetch'); const pick = require('lodash.pick'); -const PREFIX = ''; -const HOST = 'shield.abap.space'; +const PREFIX = (process.env.E2E_DEV === '1') ? 'dev.' : ''; +const HOST = PREFIX + 'shield.abap.space'; const functionName = 'version-shield-json'; const versionRe = /^v\d{1,3}\.\d{1,3}(\.\d{1,3})?$/i; +console.log('Host:', HOST); -const getUrl = (params) => `https://${PREFIX}${HOST}/${functionName}/${params}`; +const getUrl = (params) => `https://${HOST}/${functionName}/${params}`; async function validateExpectations(resp) { expect(resp.ok).toBeTruthy(); @@ -26,7 +27,7 @@ test('should process abap constant', async () => { await validateExpectations(resp); }); -test('should process abap constant', async () => { +test('should process apack', async () => { const resp = await fetch(getUrl('github/SAP-samples/abap-platform-jak/.apack-manifest.xml')); await validateExpectations(resp); }); diff --git a/package.json b/package.json index 7f0e914..a474119 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "test": "jest", "test:watch": "jest --watch", "test:e2e": "jest -c jest.e2e.config.js", + "test:e2e-dev": "env E2E_DEV=1 jest -c jest.e2e.config.js", "lint": "eslint . lib", "deploy-dev": "bash ./bin/deploy-dev.sh", "deploy-prod": "bash ./bin/deploy-dev.sh",