-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
203 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
})) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\'' } | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters