Skip to content

Instantly share code, notes, and snippets.

@erkattak
Created August 22, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkattak/4b94f618e7209b410faafed54a2aaf8e to your computer and use it in GitHub Desktop.
Save erkattak/4b94f618e7209b410faafed54a2aaf8e to your computer and use it in GitHub Desktop.
/* global describe, beforeAll, it, expect */
/* eslint prefer-arrow-callback: 0 */
/* eslint-disable max-nested-callbacks */
'use strict';
const JSONSchemaValidator = require('jsonschema').Validator;
const Validator = new JSONSchemaValidator();
const MockExpressResponse = require('mock-express-response');
const jsonApiSchema = require('../support/jsonapi-schema.json');
const responseJsonApi = require('../../lib/middleware/response-json-api');
describe('Middleware Response JSON API', () => {
let req;
let res;
beforeAll(() => {
req = {
protocol: 'https',
hostname: 'example.com',
identity: {
channel: {id: 'channel-id'},
platform: {id: 'platform-id'}
}
};
res = new MockExpressResponse();
res.body = {
id: '936ed036-45df-4190-afce-d71b860806d1',
type: 'doesntmatter',
title: 'Title of the thing',
thing: 'This is a thing',
relationships: [
{
id: '93750180-6e6c-41c7-bbbd-839dbf30f360',
type: 'idk'
}
],
meta: {
extra: 'info'
}
};
});
it('formats response body to valid jsonapi.org schema', () => {
responseJsonApi()(req, res, () => {
expect(Validator.validate(res.body, jsonApiSchema)).toBe(true);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment