Move server test folder into server directory

parent a53c67a7
......@@ -15,7 +15,7 @@
"bugs": {},
"directories": {
"lib": "server",
"test": "test/"
"test": "server/test/"
},
"engines": {
"node": "^8.0.0",
......@@ -27,7 +27,7 @@
"prestart": "npm run build",
"start": "NODE_ENV=production node server/",
"test": "npm run -s mocha",
"mocha": "mocha test/ --recursive --exit"
"mocha": "mocha server/test/ --recursive --exit"
},
"dependencies": {
"@feathersjs/configuration": "^1.0.1",
......
npm run -s mocha
// @ts-check
/* global describe, before, after, it */
process.env.NODE_ENV = 'test'
const assert = require('assert')
const request = require('request-promise')
const url = require('url')
const app = require('../app')
//
// Helpers
//
const port = app.get('port') || 3030
const urlFor = pathname => url.format({
hostname: app.get('host') || 'localhost',
protocol: 'http',
port,
pathname
})
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('Indie Site', () => {
before(function (done) {
this.server = app.listen(port)
this.server.once('listening', () => done())
})
after(function (done) {
this.server.close(done)
})
describe('Index', () => {
it('Returns Actor object for ActivityPub request with main content-type.', () => {
return request(resource({path: '/', accept: mainActivityPubContentType})).then(body => assertActor(body))
})
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 request({
url: urlFor('path/to/nowhere'),
headers: {
'Accept': 'text/html'
}
}).catch(res => {
assert.equal(res.statusCode, 404)
assert.ok(res.error.indexOf('<html>') !== -1)
})
})
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)
assert.equal(res.error.code, 404)
assert.equal(res.error.message, 'Page not found')
assert.equal(res.error.name, 'NotFound')
})
})
})
})
/* global describe, it */
const assert = require('assert')
const app = require('../../app')
describe('\'owner\' service', () => {
it('registered the service', () => {
const service = app.service('owner')
assert.ok(service, 'Registered the service')
})
})
// @ts-check
/* global describe, it */
const assert = require('assert')
const app = require('../../app')
const siteConfiguration = require('../../../client/assets/data.json')
describe('site-configuration service', () => {
it('registered the service', () => {
const service = app.service('site-configuration')
assert.ok(service, 'Registered the service')
})
it('returns correct site configuration', async () => {
const service = app.service('site-configuration')
const siteConfigrationFromService = await service.find()
assert.deepStrictEqual(siteConfiguration, siteConfigrationFromService)
})
})
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