Skip to content

Commit

Permalink
floundering
Browse files Browse the repository at this point in the history
  • Loading branch information
dbenge committed Sep 1, 2023
1 parent 1dffa50 commit 98b9755
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 88 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"e2e": "jest --collectCoverage=false --testRegex ./e2e"
},
"engines": {
"node": "^14.18 || ^16.13 || >=18"
"node": ">=18"
},
"aio-app-builder-templates": [
"@adobe/generator-app-excshell",
Expand Down
70 changes: 70 additions & 0 deletions src/dx-excshell-1/actions/remarkDoc/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
let unified;
//import { unified } from "unified";
let markdown;
//import markdown from "remark-parse";
let remarkBreaks;
//import remarkBreaks from "remark-breaks";
let docx;
//import docx from "remark-docx";
let pdf;
//import pdf from "remark-pdf/node";
let unifiedPrettier;
//import unifiedPrettier from 'unified-prettier';

//export default async function(params){
//unified = (await import('unified')).default;
//markdown = (await import('remark-parse')).default;
//remarkBreaks = (await import('remark-breaks')).default;
//docx = (await import('remark-docx')).default;
//pdf = (await import('remark-pdf/node')).default;
//unifiedPrettier = (await import('unified-prettier')).default;
/*
if(docType === 'docx'){
return await remarkDocx(params.markdownSource, params.docName);
}else{
return await remarkPdf(params.markdownSource, params.docName);
}*/
//return {
// statusCode: 200,
// body: "boo"
// };
//}

function remarkDoc(params) {
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: {
LOG_LEVEL: params.LOG_LEVEL,
message: 'this is a test message'
}
}
}

/*
async function remarkDocx(markdownSource, docName) {
const processor = unified(unifiedPrettier).use(markdown).use(remarkBreaks).use(docx, { output: "buffer" });
const doc = await processor.process(markdownSource);
const buffer = await doc.result;
return {
statusCode: 200,
body: buffer
};
}
async function remarkPdf(markdownSource, docName) {
const processor = unified(unifiedPrettier).use(markdown).use(remarkBreaks).use(pdf, { output: "buffer" });
const doc = await processor.process(markdownSource);
const buffer = await doc.result;
return {
statusCode: 200,
body: buffer
};
}
*/

exports.main = remarkDoc;
41 changes: 0 additions & 41 deletions src/dx-excshell-1/actions/remarkDoc/remarkDoc.mjs

This file was deleted.

15 changes: 15 additions & 0 deletions src/dx-excshell-1/actions/testmjs/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ////////////////////////////
// index.mjs - this is the EcmaScript Module that contains the functionality

export default function (params) {
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: {
LOG_LEVEL: params.LOG_LEVEL,
message: 'this is a test message'
}
}
}
23 changes: 23 additions & 0 deletions src/dx-excshell-1/e2e/testmjs.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* <license header>
*/

const { Config } = require('@adobe/aio-sdk').Core
const fs = require('fs')
const fetch = require('node-fetch')

// get action url
const namespace = Config.get('runtime.namespace')
const hostname = Config.get('cna.hostname') || 'adobeioruntime.net'
const packagejson = JSON.parse(fs.readFileSync('package.json').toString())
const runtimePackage = 'dx-excshell-1'
const actionUrl = `https://${namespace}.${hostname}/api/v1/web/${runtimePackage}/testmjs`

// The deployed actions are secured with the `require-adobe-auth` annotation.
// If the authorization header is missing, Adobe I/O Runtime returns with a 401 before the action is executed.
test('returns a 401 when missing Authorization header', async () => {
const res = await fetch(actionUrl)
expect(res).toEqual(expect.objectContaining({
status: 401
}))
})
50 changes: 6 additions & 44 deletions src/dx-excshell-1/ext.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,21 @@ runtimeManifest:
dx-excshell-1:
license: Apache-2.0
actions:
generic:
function: actions/generic/index.cjs
web: 'yes'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
annotations:
require-adobe-auth: false
final: true
md-to-docx:
function: actions/md-to-docx/index.cjs
web: 'yes'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
AIO_RUNTIME_AUTH: $AIO_runtime_auth
AIO_RUNTIME_APIHOST: $AIO_runtime_apihost
annotations:
require-adobe-auth: false
final: true
md-to-pdf:
function: actions/md-to-pdf/index.cjs
web: 'yes'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
annotations:
require-adobe-auth: false
final: true
md-to-docx-info:
function: actions/md-to-docx-info/index.cjs
remarkDoc:
function: actions/remarkDoc/index.mjs
web: 'yes'
runtime: nodejs:16
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
annotations:
require-adobe-auth: false
final: true
md-to-pdf-info:
function: actions/md-to-pdf-info/index.cjs
testmjs:
function: actions/testmjs/index.mjs
web: 'yes'
runtime: nodejs:16
runtime: nodejs:18
inputs:
LOG_LEVEL: debug
annotations:
require-adobe-auth: false
final: true
remarkDoc:
function: actions/remarkDoc/remarkDoc.mjs
web: 'yes'
runtime: nodejs:16
inputs:
LOG_LEVEL: debug
annotations:
require-adobe-auth: false
final: true
84 changes: 84 additions & 0 deletions src/dx-excshell-1/test/testmjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* <license header>
*/

jest.mock('@adobe/aio-sdk', () => ({
Core: {
Logger: jest.fn()
}
}))

const { Core } = require('@adobe/aio-sdk')
const mockLoggerInstance = { info: jest.fn(), debug: jest.fn(), error: jest.fn() }
Core.Logger.mockReturnValue(mockLoggerInstance)

jest.mock('node-fetch')
const fetch = require('node-fetch')
const action = require('./../actions/testmjs/index.js')

beforeEach(() => {
Core.Logger.mockClear()
mockLoggerInstance.info.mockReset()
mockLoggerInstance.debug.mockReset()
mockLoggerInstance.error.mockReset()
})

const fakeParams = { __ow_headers: { authorization: 'Bearer fake' } }
describe('testmjs', () => {
test('main should be defined', () => {
expect(action.main).toBeInstanceOf(Function)
})
test('should set logger to use LOG_LEVEL param', async () => {
await action.main({ ...fakeParams, LOG_LEVEL: 'fakeLevel' })
expect(Core.Logger).toHaveBeenCalledWith(expect.any(String), { level: 'fakeLevel' })
})
test('should return an http reponse with the fetched content', async () => {
const mockFetchResponse = {
ok: true,
json: () => Promise.resolve({ content: 'fake' })
}
fetch.mockResolvedValue(mockFetchResponse)
const response = await action.main(fakeParams)
expect(response).toEqual({
statusCode: 200,
body: { content: 'fake' }
})
})
test('if there is an error should return a 500 and log the error', async () => {
const fakeError = new Error('fake')
fetch.mockRejectedValue(fakeError)
const response = await action.main(fakeParams)
expect(response).toEqual({
error: {
statusCode: 500,
body: { error: 'server error' }
}
})
expect(mockLoggerInstance.error).toHaveBeenCalledWith(fakeError)
})
test('if returned service status code is not ok should return a 500 and log the status', async () => {
const mockFetchResponse = {
ok: false,
status: 404
}
fetch.mockResolvedValue(mockFetchResponse)
const response = await action.main(fakeParams)
expect(response).toEqual({
error: {
statusCode: 500,
body: { error: 'server error' }
}
})
// error message should contain 404
expect(mockLoggerInstance.error).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('404') }))
})
test('missing input request parameters, should return 400', async () => {
const response = await action.main({})
expect(response).toEqual({
error: {
statusCode: 400,
body: { error: 'missing header(s) \'authorization\'' }
}
})
})
})
4 changes: 3 additions & 1 deletion src/dx-excshell-1/web-src/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function bootstrapInExcShell () {
// runtime.heroClick = () => window.alert('Did I ever tell you you\'re my hero?')

// ready event brings in authentication/user info
runtime.on('ready', ({ imsOrg, imsToken, imsProfile, locale }) => {
runtime.on('ready', ({ imsOrg, imsToken, imsProfile, locale, externalQueryParams }) => {
// tell the exc-runtime object we are done
runtime.done()
console.log('Ready! received imsProfile:', imsProfile)
Expand All @@ -56,6 +56,8 @@ function bootstrapInExcShell () {
org: imsOrg,
token: imsToken
}

console.log('test paths', externalQueryParams )
// render the actual react application and pass along the runtime and ims objects to make it available to the App
ReactDOM.render(
<App runtime={runtime} ims={ims} />,
Expand Down

0 comments on commit 98b9755

Please sign in to comment.