Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tmp
logs
.DS_Store
test-results.xml
.env
1,046 changes: 767 additions & 279 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"@adobe/eslint-config-helix": "1.1.0",
"@adobe/helix-ops": "1.11.2",
"@adobe/helix-testutils": "^0.3.1",
"@adobe/openwhisk-action-builder": "2.10.1",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/exec": "5.0.0",
Expand All @@ -53,6 +54,7 @@
"codecov": "3.6.5",
"commitizen": "4.1.2",
"cz-conventional-changelog": "3.2.0",
"dotenv": "8.2.0",
"eslint": "7.0.0",
"eslint-plugin-header": "3.0.0",
"eslint-plugin-import": "2.20.2",
Expand Down
7 changes: 4 additions & 3 deletions src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ function hasParams(list, params) {
}

function embed(url, params, log) {
const matching = matchers
.filter((candidate) => hasParams(candidate.required, params))
.find((candidate) => candidate.pattern(url));
const candidates = matchers
.filter((candidate) => hasParams(candidate.required, params));

const matching = candidates.find((candidate) => candidate.pattern(url));

if (!url || !matching) {
log.warn(`No matcher found for URL ${url}`);
Expand Down
51 changes: 36 additions & 15 deletions src/matchers/excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,52 @@ async function extract(url, params, log = console) {

const tablesuri = `${worksheetsuri}${worksheetname}/tables/`;
const tables = await client.get(tablesuri);
const tablename = tables.value[0].name;
const body = await (async () => {
if (!tables.value.length) {
log.info(`worksheet ${worksheetname} has no tables: ${tablesuri}, getting range instead`);

const columnsuri = `${tablesuri}${tablename}/columns/`;
const columns = await client.get(columnsuri);
const rangeuri = `${worksheetsuri}${worksheetname}/usedRange`;
const range = await client.get(rangeuri);

const columnnames = columns.value.map(({ name }) => name);

const rowvalues = columns.value[0].values
.map((_, rownum) => columnnames.reduce((row, name, colnum) => {
const [value] = columns.value[colnum].values[rownum];
// eslint-disable-next-line no-param-reassign
row[name] = value;
return row;
}, {}));
const rows = range.values;
const columnames = rows.shift();

// discard the first row
rowvalues.shift();
const rowvalues = rows.map((row) => columnames.reduce((obj, name, index) => {
// eslint-disable-next-line no-param-reassign
obj[name] = row[index];
return obj;
}, {}));

return rowvalues;
}
const tablename = tables.value[0].name;

const columnsuri = `${tablesuri}${tablename}/columns/`;
const columns = await client.get(columnsuri);

const columnnames = columns.value.map(({ name }) => name);
const rowvalues = columns.value[0].values
.map((_, rownum) => columnnames.reduce((row, name, colnum) => {
const [value] = columns.value[colnum].values[rownum];
// eslint-disable-next-line no-param-reassign
row[name] = value;
return row;
}, {}));

// discard the first row
rowvalues.shift();

return rowvalues;
})();

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'max-age=600',
},
body: rowvalues,
body,
};
} catch (e) {
log.error(e.message);
Expand All @@ -76,7 +97,7 @@ async function extract(url, params, log = console) {


module.exports = {
required: ['share', 'AZURE_WORD2MD_CLIENT_ID', 'AZURE_HELIX_USER', 'AZURE_HELIX_PASSWORD'],
required: ['AZURE_WORD2MD_CLIENT_ID', 'AZURE_HELIX_USER', 'AZURE_HELIX_PASSWORD'],
pattern: (url) => /^https:\/\/.*\.sharepoint\.com\//.test(url),
extract,
};
50 changes: 50 additions & 0 deletions test/excel.integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/* eslint-env mocha */

const assert = require('assert');
const { condit } = require('@adobe/helix-testutils');
const { main } = require('../src/index');

require('dotenv').config();

describe('Excel Integration Test', () => {
condit('Retrieves Excel Spreadsheet without tables', condit.hasenv('AZURE_WORD2MD_CLIENT_ID', 'AZURE_HELIX_USER', 'AZURE_HELIX_PASSWORD'), async () => {
const result = await main({
__ow_logger: console,
__ow_path: '/https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx',
share: 'Edoi88tLKLpDsKzSfL-pcJYB2lIo7UKooYWnjm3w2WRrsA',
email: 'helix@adobe.com',
e: 'tD623x',
AZURE_WORD2MD_CLIENT_ID: process.env.AZURE_WORD2MD_CLIENT_ID,
AZURE_HELIX_USER: process.env.AZURE_HELIX_USER,
AZURE_HELIX_PASSWORD: process.env.AZURE_HELIX_PASSWORD,
});
assert.equal(result.statusCode, 200);
assert.equal(result.body.length, 3);
}).timeout(10000);

condit('Retrieves Excel Spreadsheet with tables', condit.hasenv('AZURE_WORD2MD_CLIENT_ID', 'AZURE_HELIX_USER', 'AZURE_HELIX_PASSWORD'), async () => {
const result = await main({
__ow_logger: console,
__ow_path: '/https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx',
share: 'Edz_l4D0BghJjLkIfyZCB7sBLaBhySyT5An7fPHVS6CFuA',
email: 'helix@adobe.com',
e: 'e5ziwf',
AZURE_WORD2MD_CLIENT_ID: process.env.AZURE_WORD2MD_CLIENT_ID,
AZURE_HELIX_USER: process.env.AZURE_HELIX_USER,
AZURE_HELIX_PASSWORD: process.env.AZURE_HELIX_PASSWORD,
});
assert.equal(result.statusCode, 200);
assert.equal(result.body.length, 20);
}).timeout(10000);
});
2 changes: 1 addition & 1 deletion test/excel.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion test/post-deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,46 @@ describe('Post-Deploy Tests', () => {
});
}).timeout(10000);

it('Excel Embed', async () => {
it('Excel Embed (without tables)', async () => {
console.log('Trying', 'https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx?share=Edoi88tLKLpDsKzSfL-pcJYB2lIo7UKooYWnjm3w2WRrsA&email=helix%40adobe.com&e=tD623x');

await chai
.request('https://adobeioruntime.net/')
.get(`${getbaseurl()}/https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx?share=Edoi88tLKLpDsKzSfL-pcJYB2lIo7UKooYWnjm3w2WRrsA&email=helix%40adobe.com&e=tD623x`)
.then((response) => {
// console.log(response.body);
expect(response).to.have.status(200);
expect(response).to.be.json;
expect(response.body).to.be.an('array').that.deep.includes({
project: 'Helix',
created: 2018,
});
}).catch((e) => {
throw e;
});
}).timeout(10000);

it('Excel Embed (with tables)', async () => {
console.log('Trying', 'https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx?share=Edz_l4D0BghJjLkIfyZCB7sBLaBhySyT5An7fPHVS6CFuA&email=helix%40adobe.com&e=e5ziwf');

await chai
.request('https://adobeioruntime.net/')
.get(`${getbaseurl()}/https://adobe-my.sharepoint.com/personal/trieloff_adobe_com/_layouts/15/guestaccess.aspx?share=Edz_l4D0BghJjLkIfyZCB7sBLaBhySyT5An7fPHVS6CFuA&email=helix%40adobe.com&e=e5ziwf`)
.then((response) => {
// console.log(response.body);
expect(response).to.have.status(200);
expect(response).to.be.json;
expect(response.body).to.be.an('array').that.deep.includes({
Column1: 'Klapptüren',
Gesamtkosten: 28976,
Hersteller: 'Hyundai',
Kofferraum: 304,
Modell: 'Trajet',
Preis: 23000,
Preis2: 1.1,
Verbrauch: 7.2,
'Verbrauch pro Jahr': 5976,
});
}).catch((e) => {
throw e;
});
Expand Down