1 | 'use strict';
|
2 |
|
3 | const expect = require('chai').expect;
|
4 | const Adapter = require('../lib/Adapter');
|
5 | const Application = require('../lib/Application');
|
6 |
|
7 | describe('class Adapter', function() {
|
8 | let adapter, app;
|
9 | let noop = function(){};
|
10 |
|
11 | beforeEach(function() {
|
12 | app = new Application('test');
|
13 | adapter = new Adapter(app, {});
|
14 | });
|
15 |
|
16 | describe('constructor(app, options)', function() {
|
17 | it('should raise an error if app is not an valid Application instance', function() {
|
18 | expect(function() {
|
19 | new Adapter;
|
20 | }).to.throw(Error).have.property('message', 'app must be an instance of \'Application\'');
|
21 |
|
22 | expect(function() {
|
23 | new Adapter('app');
|
24 | }).to.throw(Error).have.property('message', 'app must be an instance of \'Application\'');
|
25 | });
|
26 |
|
27 | [
|
28 | ['app', function() { return app; }],
|
29 | ['options', {}],
|
30 | ['methods', []],
|
31 | ['sortedMethods', []]
|
32 | ].forEach(function(prop) {
|
33 | it(`should have property '${prop[0]}' and corresponding value`, function() {
|
34 | let value = typeof prop[1] === 'function' ? prop[1]() : prop[1];
|
35 | expect(adapter).to.have.property(prop[0]).deep.eq(value);
|
36 | });
|
37 | });
|
38 | });
|
39 |
|
40 | describe('createMethodsBy(wrapper)', function() {
|
41 | it('should raise an error if wrapper is not a valid function', function() {
|
42 | expect(function() {
|
43 | adapter.createMethodsBy('abc');
|
44 | }).to.throw(Error).have.property('message', 'abc is not a valid wrapper function');
|
45 | });
|
46 |
|
47 | it('should filter methods by supported adapter', function() {
|
48 | app.define('test', {
|
49 | adapter: 'express'
|
50 | }, function() {});
|
51 |
|
52 | app.set('adapter', 'express');
|
53 | let methods = adapter.createMethodsBy(noop);
|
54 | expect(methods).to.have.property('length', 1);
|
55 | expect(methods[0]).to.have.property('name', 'test.test');
|
56 | expect(methods[0]).to.have.property('description', 'test');
|
57 | expect(methods[0]).to.have.property('verb', 'all');
|
58 | expect(methods[0]).to.have.property('path', '/');
|
59 | expect(methods[0]).to.have.property('handler');
|
60 |
|
61 | app.set('adapter', 'socketio');
|
62 | expect(adapter.createMethodsBy(noop)).to.have.property('length', 0);
|
63 | });
|
64 | });
|
65 |
|
66 | describe('createHandler()', function() {
|
67 | it('should raise an error for Not Implement', function() {
|
68 | expect(function() {
|
69 | adapter.createHandler();
|
70 | }).to.throw(Error).have.property('message', 'Not Implement');
|
71 | });
|
72 | });
|
73 |
|
74 | describe('createContext()', function() {
|
75 | it('should raise an error if there is no specific context', function() {
|
76 | expect(function() {
|
77 | adapter.createContext();
|
78 | }).to.throw(Error).have.property('message', 'undefined is not a valid Context');
|
79 | });
|
80 | });
|
81 |
|
82 | describe('callback()', function() {
|
83 | it('should raise an error for Not Implement', function() {
|
84 | expect(function() {
|
85 | adapter.callback();
|
86 | }).to.throw(Error).have.property('message', 'Not Implement');
|
87 | });
|
88 | });
|
89 |
|
90 | describe('listen()', function() {
|
91 | it('should raise an error for Not Implement', function() {
|
92 | expect(function() {
|
93 | adapter.listen();
|
94 | }).to.throw(Error).have.property('message', 'Not Implement');
|
95 | });
|
96 | });
|
97 |
|
98 | describe('debugAllMethods(isDebug)', function() {
|
99 | it('should return debug messages', function() {
|
100 | app.define('test', {
|
101 | adapter: 'express'
|
102 | }, function() {});
|
103 | adapter.methods = adapter.createMethodsBy(noop);
|
104 |
|
105 | expect(adapter.debugAllMethods()).to.deep.eq([
|
106 | 'All Methods: (1)',
|
107 | '=> test.test ALL / test'
|
108 | ]);
|
109 | });
|
110 | });
|
111 | });
|