1 | 'use strict';
|
2 | const path = require('path');
|
3 | const chai = require('chai');
|
4 | const expect = chai.expect;
|
5 | const AdapterInterface = require(path.join(__dirname, '../index'));
|
6 | const JSONAdapter = require(path.join(__dirname, '../adapters/json_content'));
|
7 |
|
8 | describe('Content Adapter Interface', function() {
|
9 | describe('basic assumptions and methods', function() {
|
10 | it('Should be an object with specified required properties and types', () => {
|
11 | let interfaceFields = ['render', 'error'];
|
12 | interfaceFields.forEach(field => {
|
13 | expect(AdapterInterface.interface[field]).to.equal('function');
|
14 | });
|
15 | });
|
16 | it('Should have a create method', () => {
|
17 | expect(AdapterInterface.create).to.be.a('function');
|
18 | });
|
19 | });
|
20 | describe('generating a pre-loaded adapter by adapter name', function() {
|
21 | it('Should throw an error if adapter name does not exist in list', done => {
|
22 | try {
|
23 | let adapter = AdapterInterface.create({ adapter: 'some-non-existant-adapter' });
|
24 | done(new Error('Should not evaluate this line'));
|
25 | } catch (e) {
|
26 | expect(e instanceof Error).to.be.true;
|
27 | done();
|
28 | }
|
29 | });
|
30 | it('Should return a constructed adapter given a valid adapter name', () => {
|
31 | let adapter = AdapterInterface.create({ adapter: 'json' });
|
32 | expect(adapter instanceof JSONAdapter).to.be.true;
|
33 | });
|
34 | it('Should return a constructed adapter given a valid adapter name when only .responder is defined', () => {
|
35 | let adapter = AdapterInterface.create({ responder: 'json' });
|
36 | expect(adapter instanceof JSONAdapter).to.be.true;
|
37 | });
|
38 | });
|
39 | describe('generating an adapter from a provided constructor', function() {
|
40 | it('Should throw an error if custom adapter class is missing required methods', done => {
|
41 | try {
|
42 | let Invalid_Adapter = class Invalid_Adapter {
|
43 | constructor() {
|
44 | this.method = false;
|
45 | }
|
46 | };
|
47 | let adapter = AdapterInterface.create({ adapter: Invalid_Adapter });
|
48 | } catch (e) {
|
49 | expect(e instanceof Error).to.be.true;
|
50 | done();
|
51 | }
|
52 | });
|
53 | it('Should return a constructed adapter given a valid custom class', () => {
|
54 | let Valid_Adapter = class Valid_Adapter {
|
55 | constructor() {
|
56 | this.error = () => true;
|
57 | this.render = () => true;
|
58 | }
|
59 | };
|
60 | let adapter = AdapterInterface.create({ adapter: Valid_Adapter });
|
61 | expect(adapter instanceof Valid_Adapter).to.be.true;
|
62 | });
|
63 | });
|
64 | }); |
\ | No newline at end of file |