1+ require ( './../common' ) ;
2+
3+ var Api = require ( './../../' ) . Api ;
4+
5+
6+ describe ( 'Api.remove() method' , function ( ) {
7+
8+ var api ;
9+ var url = 'http://foobar:8080' ;
10+
11+ beforeEach ( function ( ) {
12+ api = new Api ( { url : url } ) ;
13+ sinon . stub ( api , "request" ) ;
14+ } ) ;
15+
16+ afterEach ( function ( ) {
17+ api . request . restore ( ) ; // Unwraps the spy
18+ } ) ;
19+
20+ it ( 'should call request() with proper params (force=false)' , function ( ) {
21+ api . remove ( 'foo' , '123' ) ;
22+ expect ( api . request ) . to . have . callCount ( 1 ) ;
23+ expect ( api . request ) . to . have . been . calledWith ( 'foo/123' , null , null , "DELETE" ) ;
24+ } ) ;
25+
26+ it ( 'should call request() with proper params (force=true)' , function ( ) {
27+ api . remove ( 'foo' , '123' , true ) ;
28+ expect ( api . request ) . to . have . callCount ( 1 ) ;
29+ expect ( api . request ) . to . have . been . calledWith ( 'foo/123' , { force : true } , null , "DELETE" ) ;
30+ } ) ;
31+
32+ it ( 'should resolve returned promise if removal was ok' , function ( done ) {
33+ api . request . resolves ( { success : true } ) ;
34+ var promise = api . logout ( ) ;
35+ expect ( promise ) . to . be . fulfilled . and . notify ( done ) ;
36+ } ) ;
37+
38+ it ( 'should reject returned promise if removal was not ok' , function ( done ) {
39+ api . httpOptions . headers . sessionID = 123 ;
40+ api . request . resolves ( false ) ;
41+ var promise = api . remove ( 'foo' , '123' ) ;
42+ expect ( promise ) . to . be . rejected . and . notify ( done ) ;
43+ } ) ;
44+ } ) ;
0 commit comments