1 | var loopback = require('loopback');
|
2 | var RemoteRouting = require('../index.js');
|
3 | var expect = require('chai').expect;
|
4 | var sinon = require('sinon');
|
5 | var app = loopback();
|
6 | var _ = require('lodash');
|
7 |
|
8 | app.set('legacyExplorer', false)
|
9 | app.use(loopback.rest());
|
10 |
|
11 | describe('RemoteRouting', function(){
|
12 | var Color = null;
|
13 | var Palatee = null;
|
14 | var db = null;
|
15 | var remoteEndpoints = null;
|
16 |
|
17 | beforeEach(function(){
|
18 | db = app.dataSource('db', {adapter: 'memory'});
|
19 |
|
20 | Color = app.model('color', {name: String, relations: {
|
21 | palatee: {
|
22 | type: 'belongsTo',
|
23 | model: 'palatee'
|
24 | }
|
25 | }});
|
26 |
|
27 | Palatee = app.model('palatee', {name: String, relations: {
|
28 | colors: {
|
29 | type: 'hasMany',
|
30 | model: 'color'
|
31 | }
|
32 | }});
|
33 |
|
34 | db.attach(Color);
|
35 | db.attach(Palatee);
|
36 | });
|
37 |
|
38 | describe('only option', function(){
|
39 | it('should only expose specified remote methods', function(){
|
40 | RemoteRouting(Color, {only: ['@create']});
|
41 | expect(getModelRest(Color).length).to.eql(1);
|
42 | });
|
43 | });
|
44 |
|
45 | describe('expect option', function(){
|
46 | it('should expose all remote methods except specified ones', function(){
|
47 | RemoteRouting(Color, {except: ['@create', '@find']});
|
48 | getModelRest(Color).forEach(function(endpoint){
|
49 | expect(endpoint.method).to.not.eql('color.create')
|
50 | expect(endpoint.method).to.not.eql('color.find')
|
51 | })
|
52 | });
|
53 | });
|
54 |
|
55 | function getModelRest(Model){
|
56 | return app.handler('rest').adapter.allRoutes().filter(function(endpoint){
|
57 | var reg = new RegExp('^'+Model.modelName);
|
58 | return reg.test(endpoint.method);
|
59 | })
|
60 | }
|
61 | });
|