@@ -631,4 +631,92 @@ describe('loopback', function() {
631631 } ) ;
632632 } ) ;
633633 } ) ;
634+
635+ describe ( 'new remote method configuration' , function ( ) {
636+ function getAllMethodNamesWithoutClassName ( TestModel ) {
637+ return TestModel . sharedClass . methods ( ) . map ( function ( m ) {
638+ return m . stringName . replace ( / ^ [ ^ . ] + \. / , '' ) ; // drop the class name
639+ } ) ;
640+ }
641+
642+ it ( 'treats method names that don\'t start with "prototype." as "isStatic:true"' , function ( ) {
643+ var TestModel = loopback . createModel ( uniqueModelName ) ;
644+ loopback . configureModel ( TestModel , {
645+ dataSource : null ,
646+ methods : {
647+ staticMethod : {
648+ http : { path : '/static' }
649+ }
650+ }
651+ } ) ;
652+
653+ var methodNames = getAllMethodNamesWithoutClassName ( TestModel ) ;
654+
655+ expect ( methodNames ) . to . include ( 'staticMethod' ) ;
656+ } ) ;
657+
658+ it ( 'treats method names starting with "prototype." as "isStatic:false"' , function ( ) {
659+ var TestModel = loopback . createModel ( uniqueModelName ) ;
660+ loopback . configureModel ( TestModel , {
661+ dataSource : null ,
662+ methods : {
663+ 'prototype.instanceMethod' : {
664+ http : { path : '/instance' }
665+ }
666+ }
667+ } ) ;
668+
669+ var methodNames = getAllMethodNamesWithoutClassName ( TestModel ) ;
670+
671+ expect ( methodNames ) . to . include ( 'prototype.instanceMethod' ) ;
672+ } ) ;
673+
674+ it ( 'throws an error when "isStatic:true" and method name starts with "prototype."' , function ( ) {
675+ var TestModel = loopback . createModel ( uniqueModelName ) ;
676+ expect ( function ( ) { loopback . configureModel ( TestModel , {
677+ dataSource : null ,
678+ methods : {
679+ 'prototype.instanceMethod' : {
680+ isStatic : true ,
681+ http : { path : '/instance' }
682+ }
683+ }
684+ } ) ; } ) . to . throw ( Error , new Error ( 'Remoting metadata for' + TestModel . modelName +
685+ ' "isStatic" does not match new method name-based style.' ) ) ;
686+ } ) ;
687+
688+ it ( 'use "isStatic:true" if method name does not start with "prototype."' , function ( ) {
689+ var TestModel = loopback . createModel ( uniqueModelName ) ;
690+ loopback . configureModel ( TestModel , {
691+ dataSource : null ,
692+ methods : {
693+ staticMethod : {
694+ isStatic : true ,
695+ http : { path : '/static' }
696+ }
697+ }
698+ } ) ;
699+
700+ var methodNames = getAllMethodNamesWithoutClassName ( TestModel ) ;
701+
702+ expect ( methodNames ) . to . include ( 'staticMethod' ) ;
703+ } ) ;
704+
705+ it ( 'use "isStatic:false" if method name starts with "prototype."' , function ( ) {
706+ var TestModel = loopback . createModel ( uniqueModelName ) ;
707+ loopback . configureModel ( TestModel , {
708+ dataSource : null ,
709+ methods : {
710+ 'prototype.instanceMethod' : {
711+ isStatic : false ,
712+ http : { path : '/instance' }
713+ }
714+ }
715+ } ) ;
716+
717+ var methodNames = getAllMethodNamesWithoutClassName ( TestModel ) ;
718+
719+ expect ( methodNames ) . to . include ( 'prototype.instanceMethod' ) ;
720+ } ) ;
721+ } ) ;
634722} ) ;
0 commit comments