@@ -13,20 +13,13 @@ describe('Controller: TryOperation', function() {
1313 $controller = _$controller_ ;
1414 scope . operation = { } ;
1515 scope . specs = { } ;
16- scope . getParameters = function mockGetParameters ( ) {
17- return [ ] ;
18- } ;
19- scope . $watch = function ( ) { } ;
20- $controller ( 'TryOperation' , {
21- $scope : scope
22- } ) ;
2316 } ) ) ;
2417
2518 describe ( '$scope.makeCall' , function ( ) {
26- afterEach ( function ( ) {
19+ afterEach ( function ( ) {
2720 $ . ajax . restore ( ) ;
2821 } ) ;
29-
22+
3023 it ( 'should call ajax when it\'s called' , function ( ) {
3124 var operation = {
3225 responses : {
@@ -47,9 +40,17 @@ describe('Controller: TryOperation', function() {
4740 }
4841 }
4942 } ;
43+ scope . getParameters = function mockGetParameters ( ) {
44+ return [ ] ;
45+ } ;
5046 scope . pathName = '/' ;
5147 scope . operation = operation ;
5248
49+ scope . $watch = function ( ) { } ;
50+ $controller ( 'TryOperation' , {
51+ $scope : scope
52+ } ) ;
53+
5354 var ajaxStub = sinon . stub ( $ , 'ajax' ) . returns ( {
5455 fail : function ( ) {
5556 return { done : function ( ) { } } ;
@@ -64,14 +65,12 @@ describe('Controller: TryOperation', function() {
6465 describe ( 'use server' , function ( ) {
6566
6667 it ( 'should upload the file' , function ( ) {
67- var parameters = [ {
68- name : 'upload' ,
69- in : 'formData' ,
70- required : true ,
71- schema : {
72- type : 'file'
73- }
74- } ] ;
68+ var parameters = [ {
69+ name : 'upload' ,
70+ in : 'formData' ,
71+ required : true ,
72+ type : 'file'
73+ } ] ;
7574 scope . specs = {
7675 host : 'localhost:3000' ,
7776 swagger : '2.0' ,
@@ -80,7 +79,7 @@ describe('Controller: TryOperation', function() {
8079 title : 'Upload API'
8180 } ,
8281 security : [ ] ,
83- consumes : [ 'multipart/form-data' ] ,
82+ consumes : [ 'multipart/form-data' ] ,
8483 paths : {
8584 '/' : {
8685 post : {
@@ -94,7 +93,9 @@ describe('Controller: TryOperation', function() {
9493 }
9594 }
9695 } ;
97- scope . pathName = '/' ;
96+ scope . operationName = 'post' ;
97+ scope . pathName = '/upload' ;
98+
9899 scope . getParameters = function ( ) {
99100 return [ {
100101 name : 'upload' ,
@@ -106,20 +107,17 @@ describe('Controller: TryOperation', function() {
106107 }
107108 } ] ;
108109 } ;
109-
110+ scope . $watch = function ( ) { } ;
111+ $controller ( 'TryOperation' , {
112+ $scope : scope
113+ } ) ;
110114 scope . getHeaderParams = { } ;
111- scope . specs . host = '127.0.0.1:8080' ;
112- var header = scope . getHeaders ( ) ;
113-
114- scope . requestModel = {
115- scheme : "http" ,
116- accept : "*/*" ,
117- contentType : "multipart/form-data" ,
118- parameters : {
119- upload : './file.txt'
120- }
121- } ;
122- var data = scope . getRequestBody ( )
115+ scope . specs . host = 'localhost:3000' ;
116+ sinon . stub ( scope , 'getHeaders' ) . returns ( {
117+ 'Accept' : "*/*" ,
118+ 'Content-Type' : 'multipart/form-data'
119+ } ) ;
120+ sinon . stub ( scope , 'getRequestBody' ) . returns ( { mydata : 12 } ) ;
123121
124122 sinon . stub ( $ , "ajax" ) . returns ( {
125123 fail : function ( ) {
@@ -129,14 +127,16 @@ describe('Controller: TryOperation', function() {
129127
130128 scope . makeCall ( ) ;
131129
132- expect ( $ . ajax . calledWithMatch ( {
130+ $ . ajax . should . have . been . calledWithMatch ( {
133131 url : 'http://localhost:3000/upload' ,
134132 type : 'post' ,
135- headers : header ,
136- data : data ,
137- contentType : false ,
133+ headers : {
134+ 'Accept' : '*/*' ,
135+ 'Content-Type' : undefined
136+ } ,
137+ data : { mydata : 12 } ,
138138 processData : false
139- } ) ) ;
139+ } ) ;
140140 } ) ;
141141 } ) ;
142142
0 commit comments