Created
August 22, 2016 19:25
-
-
Save erkattak/4b94f618e7209b410faafed54a2aaf8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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