@@ -23,39 +23,37 @@ let core = new Core(
23
23
24
24
const testService = new Service ( ) ;
25
25
testService . getPrePath = ( ) : string => {
26
- return 'test/pre-path ' ;
26
+ return 'v1 ' ;
27
27
} ;
28
28
testService . getPath = ( ) : string => {
29
- return 'test/path ' ;
29
+ return 'authors ' ;
30
30
} ;
31
31
32
32
describe ( 'Path Builder' , ( ) => {
33
- let path_builder = new PathBuilder ( ) ;
34
- it ( 'should create' , ( ) => {
35
- expect ( path_builder ) . toBeTruthy ( ) ;
33
+ let path_builder : PathBuilder ;
34
+ beforeEach ( async ( ) => {
35
+ path_builder = new PathBuilder ( ) ;
36
36
} ) ;
37
+
37
38
it ( 'applyParams method should call appendPath two to four times: with service s pre-path, params.beforepath (if exists),\
38
39
and service s path' , ( ) => {
39
40
let appendPath_spy = spyOn ( path_builder , 'appendPath' ) ;
40
41
path_builder . applyParams ( testService ) ;
41
42
expect ( appendPath_spy ) . toHaveBeenCalledTimes ( 2 ) ;
42
- path_builder . applyParams ( testService , { beforepath : 'pre/ ' , include : [ 'include' ] } ) ;
43
+ path_builder . applyParams ( testService , { beforepath : 'users/1 ' , include : [ 'include' ] } ) ;
43
44
expect ( appendPath_spy ) . toHaveBeenCalledWith ( testService . getPrePath ( ) ) ;
44
- expect ( appendPath_spy ) . toHaveBeenCalledWith ( 'pre/ ' ) ;
45
+ expect ( appendPath_spy ) . toHaveBeenCalledWith ( 'users/1 ' ) ;
45
46
expect ( appendPath_spy ) . toHaveBeenCalledWith ( testService . getPath ( ) ) ;
46
47
} ) ;
47
- it ( 'applyParams method should call setInclude with params.include (if exists) to assign them to the includes array' , ( ) => {
48
- let setInclude_spy = spyOn < any > ( path_builder , 'setInclude' ) ;
49
- path_builder . applyParams ( testService , { beforepath : 'pre/' } ) ;
50
- expect ( setInclude_spy ) . not . toHaveBeenCalled ( ) ;
51
- path_builder . applyParams ( testService , { beforepath : 'pre/' , include : [ 'include' ] } ) ;
52
- expect ( setInclude_spy ) . toHaveBeenCalledWith ( [ 'include' ] ) ;
53
- expect ( path_builder . includes ) . toEqual ( [ 'include' ] ) ;
48
+ it ( 'applyParams include' , ( ) => {
49
+ path_builder . applyParams ( testService , { beforepath : 'users/1' } ) ;
50
+ expect ( path_builder . get ( ) ) . toMatch ( 'v1/users/1/authors' ) ;
51
+ path_builder . applyParams ( testService , { beforepath : 'users/1' , include : [ 'include' ] } ) ;
52
+ expect ( path_builder . get ( ) ) . toMatch ( 'v1/users/1/authors?include=include' ) ;
54
53
} ) ;
55
- it ( 'applyParams method should add fields to get_params if they are included in the request' , ( ) => {
56
- path_builder . applyParams ( testService , { fields : { test : [ 'test_attribute' ] , test2 : [ 'test2_attribute' ] } } ) ;
57
- expect ( ( path_builder as any ) . get_params . indexOf ( 'fields[test]=test_attribute' ) ) . toBeGreaterThan ( - 1 ) ;
58
- expect ( ( path_builder as any ) . get_params . indexOf ( 'fields[test2]=test2_attribute' ) ) . toBeGreaterThan ( - 1 ) ;
54
+ it ( 'applyParams fields' , ( ) => {
55
+ path_builder . applyParams ( testService , { fields : { authors : [ 'name' , 'address' ] , books : [ 'title' ] } } ) ;
56
+ expect ( path_builder . get ( ) . includes ( 'fields[authors]=name,address&fields[books]=title' ) ) . toBeTruthy ( ) ;
59
57
} ) ;
60
58
it ( 'appendPath method should add passed value to paths array (only if value is not an empty string)' , ( ) => {
61
59
path_builder . paths = [ ] ;
0 commit comments