fix webmention get as a string
This commit is contained in:
parent
90773a2521
commit
4d45134e1f
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jam-my-stack",
|
"name": "jam-my-stack",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
|
|
|
@ -10,12 +10,17 @@ async function getWebmentions(domain) {
|
||||||
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
|
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
|
||||||
const result = await got(url)
|
const result = await got(url)
|
||||||
|
|
||||||
result.body.json.forEach(mention => {
|
if(!result.body || !result.body) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const json = JSON.parse(result.body).json
|
||||||
|
|
||||||
|
json.forEach(mention => {
|
||||||
mention.publishedFromNow = dayjs(mention.published).fromNow()
|
mention.publishedFromNow = dayjs(mention.published).fromNow()
|
||||||
mention.relativeTarget = mention.target.substring(mention.target.indexOf(domain) + domain.length, mention.target.length)
|
mention.relativeTarget = mention.target.substring(mention.target.indexOf(domain) + domain.length, mention.target.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
return result.body.json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
|
return json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -5,7 +5,8 @@ async function got(url) {
|
||||||
if(url.indexOf('/webmention') >= 0) {
|
if(url.indexOf('/webmention') >= 0) {
|
||||||
const result = await fs.readFile(`./test/__mocks__/get-sample.json`, 'utf8');
|
const result = await fs.readFile(`./test/__mocks__/get-sample.json`, 'utf8');
|
||||||
return {
|
return {
|
||||||
body: JSON.parse(result)
|
// WHY not a JSON.parse here? The body is a STRING IRL!
|
||||||
|
body: result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
jest.disableAutomock()
|
||||||
|
jest.unmock('got')
|
||||||
|
|
||||||
|
const { getWebmentions } = require('./../../src/webmention/get')
|
||||||
|
const domain = "brainbaking.com"
|
||||||
|
|
||||||
|
describe("webmention receive scenario test", () => {
|
||||||
|
|
||||||
|
test("getWebmentions fetches anything at all", async () => {
|
||||||
|
const result = await getWebmentions(domain)
|
||||||
|
expect(result.length).toBeGreaterThan(-1)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue