parent
e740476232
commit
0ff54d8a7b
@ -0,0 +1,14 @@
|
||||
|
||||
const serveMyJamDomain = "brainbaking.com"
|
||||
const serveMyJamToken = "miauwkes"
|
||||
|
||||
const serveMyJamEndpoint = "https://jam.brainbaking.com"
|
||||
|
||||
// see https://github.com/wgroeneveld/serve-my-jams
|
||||
// don't care if token is visible, just an extra security-by-obscurity step, everything is public anyway
|
||||
module.exports = {
|
||||
serveMyJamEndpoint,
|
||||
|
||||
serveMyJamDomain,
|
||||
serveMyJamToken
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
const got = require('got')
|
||||
const config = require('../config')
|
||||
|
||||
const dayjs = require('dayjs')
|
||||
const relativeTime = require('dayjs/plugin/relativeTime')
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
async function getWebmentions() {
|
||||
const url = `${config.serveMyJamEndpoint}/webmention/${config.serveMyJamDomain}/${config.serveMyJamToken}`
|
||||
const result = await got(url)
|
||||
|
||||
result.body.json.forEach(mention => {
|
||||
mention.publishedFromNow = dayjs(mention.published).fromNow()
|
||||
})
|
||||
|
||||
return result.body.json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getWebmentions
|
||||
}
|
@ -0,0 +1 @@
|
||||
{"status":"success","json":[{"author":{"name":"Stampeding Longhorn"},"content":"undefined...","published":"2021-03-08T18:35:24","source":"https://brid.gy/like/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nwg4LYyh4WgrJOXg","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"},{"author":{"name":"Wouter Groeneveld"},"content":"@StampedingLonghorn I tried to chase him away, but you know how that turned out... 😼 There's even cat hair inside the cases... (to be clear: also unintentional)...","published":"2021-03-02T16:18:46.000Z","source":"https://brid.gy/comment/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nxVFgAbVtebcM9gW","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"},{"author":{"name":"https://jefklakscodex.com/about"},"content":"About the Codex | Jefklaks Codex","published":"2021-03-08T17:14:25","source":"https://jefklakscodex.com/about","target":"https://brainbaking.com/about/"},{"author":{"name":"Stampeding Longhorn"},"content":"@wouter The cat pictures are awesome....","published":"2021-03-02T16:17:18.000Z","source":"https://brid.gy/comment/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nxN8ytch0BW2FVXU","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"}]}
|
@ -1,7 +1,16 @@
|
||||
const fs = require('fs').promises
|
||||
|
||||
async function got() {
|
||||
return fs.readFile('./test/__mocks__/masto-feed-sample.xml', 'utf8');
|
||||
async function got(url) {
|
||||
console.log(`through got mock, url ${url}`)
|
||||
if(url.indexOf('/webmention') >= 0) {
|
||||
const result = await fs.readFile(`./test/__mocks__/get-sample.json`, 'utf8');
|
||||
return {
|
||||
body: JSON.parse(result)
|
||||
}
|
||||
}
|
||||
|
||||
const result = await fs.readFile(`./test/__mocks__/masto-feed-sample.xml`, 'utf8');
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = got
|
||||
|
@ -1,6 +1,6 @@
|
||||
const fs = require('fs')
|
||||
|
||||
const fakedata = fs.readFileSync('./test/__mocks__/expected-goodreads-content.js')
|
||||
const fakedata = fs.readFileSync('./test/goodreads/__mocks__/expected-goodreads-content.js')
|
||||
|
||||
function getmock(url, callback) {
|
||||
callback({
|
@ -1,8 +0,0 @@
|
||||
|
||||
jest.mock('got');
|
||||
const gotmock = require("got");
|
||||
|
||||
test("got is mocked", async () => {
|
||||
const data = await gotmock("bla");
|
||||
expect(data).toMatch(/brainbaking/)
|
||||
})
|
@ -0,0 +1,31 @@
|
||||
|
||||
const MockDate = require('mockdate')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
describe("webmention receive serve-my-jam tests", () => {
|
||||
|
||||
const { getWebmentions } = require('./../../src/webmention/get')
|
||||
MockDate.set(dayjs('2021-03-11T19:00:00').toDate())
|
||||
|
||||
test("getWebmentions fetches from serve-my-jam depending on config", async () => {
|
||||
const result = await getWebmentions()
|
||||
expect(result.length).toBe(4)
|
||||
})
|
||||
|
||||
test("getWebmentions enriches data with fromNow data", async () => {
|
||||
const result = await getWebmentions()
|
||||
const mention = result[0]
|
||||
|
||||
expect(mention.published).toEqual("2021-03-08T18:35:24")
|
||||
expect(mention.publishedFromNow).toEqual("3 days ago")
|
||||
})
|
||||
|
||||
test("getWebmentions are sorted by published date descending", async() => {
|
||||
const result = await getWebmentions()
|
||||
|
||||
expect(result[0].published).toEqual("2021-03-08T18:35:24")
|
||||
expect(result[1].published).toEqual("2021-03-08T17:14:25")
|
||||
expect(result[2].published).toEqual("2021-03-02T16:18:46.000Z")
|
||||
})
|
||||
|
||||
})
|
Loading…
Reference in new issue