Add test for alternate ActivityPub content type; refactor tests

parent 7232b33a
......@@ -4,19 +4,41 @@
process.env.NODE_ENV = 'test'
const assert = require('assert')
const rp = require('request-promise')
const request = require('request-promise')
const url = require('url')
const app = require('../src/app')
//
// Helpers
//
const port = app.get('port') || 3030
const getUrl = pathname => url.format({
const urlFor = pathname => url.format({
hostname: app.get('host') || 'localhost',
protocol: 'http',
port,
pathname
})
describe('Feathers application tests', () => {
const assertActor = body => {
const owner = JSON.parse(body)
assert.equal(owner['@context'], 'https://www.w3.org/ns/activitystreams')
assert.equal(owner.type, 'Person')
}
const mainActivityPubContentType = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
const alternativeActivityPubContentType = 'application/activity+json'
const resource = ({path, accept}) => {
return {
url: urlFor(path),
headers: {
'Accept': accept
}
}
}
describe('Indiepub', () => {
before(function (done) {
this.server = app.listen(port)
this.server.once('listening', () => done())
......@@ -26,32 +48,29 @@ describe('Feathers application tests', () => {
this.server.close(done)
})
it('starts and shows the index page', () => {
return rp({
url: getUrl('/'),
headers: {
'Accept': 'text/html'
}
}).then(body => assert.ok(body.indexOf('<!doctype html>') !== -1))
})
describe('Index', () => {
it('Displays web client for text/html.', () => {
return request({
url: urlFor('/'),
headers: {
'Accept': 'text/html'
}
}).then(body => assert.ok(body.indexOf('<!doctype html>') !== -1))
})
it('Returns Actor object for ActivityPub request with main content-type.', () => {
return request(resource({path: '/', accept: mainActivityPubContentType})).then(body => assertActor(body))
})
it('returns the owner’s Actor object for ActivityPub requests on /', () => {
return rp({
url: getUrl('/'),
headers: {
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
}).then((body) => {
const owner = JSON.parse(body)
assert.equal(owner['@context'], 'https://www.w3.org/ns/activitystreams')
assert.equal(owner.type, 'Person')
it('Returns Actor object for ActivityPub request with alternative content type.', () => {
return request(resource({path: '/', accept: alternativeActivityPubContentType})).then(body => assertActor(body))
})
})
describe('404', function () {
it('shows a 404 HTML page', () => {
return rp({
url: getUrl('path/to/nowhere'),
it('Shows a 404 HTML page.', () => {
return request({
url: urlFor('path/to/nowhere'),
headers: {
'Accept': 'text/html'
}
......@@ -61,9 +80,9 @@ describe('Feathers application tests', () => {
})
})
it('shows a 404 JSON error without stack trace', () => {
return rp({
url: getUrl('path/to/nowhere'),
it('Shows a 404 JSON error without stack trace.', () => {
return request({
url: urlFor('path/to/nowhere'),
json: true
}).catch(res => {
assert.equal(res.statusCode, 404)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment