1
1
import resolveIntrospection , {
2
- filterTypesByIncludeExclude ,
2
+ isResourceExcluded ,
3
+ isResourceIncluded ,
3
4
} from './introspection' ;
4
5
import {
5
6
GET_LIST ,
@@ -12,64 +13,78 @@ import {
12
13
} from 'ra-core' ;
13
14
14
15
describe ( 'introspection' , ( ) => {
15
- describe ( 'filterTypesByIncludeExclude ' , ( ) => {
16
+ describe ( 'isResourceIncluded ' , ( ) => {
16
17
it ( 'return false with an include option containing an array and tested type is not in it' , ( ) => {
17
18
expect (
18
- filterTypesByIncludeExclude ( { include : [ 'Post' , 'Comment' ] } ) ( {
19
- name : 'NotMe' ,
19
+ isResourceIncluded ( {
20
+ include : [ 'Post' , 'Comment' ] ,
21
+ type : {
22
+ name : 'NotMe' ,
23
+ } ,
20
24
} )
21
25
) . toBe ( false ) ;
22
26
} ) ;
23
27
24
28
it ( 'return true with an include option containing an array and tested type is in it' , ( ) => {
25
29
expect (
26
- filterTypesByIncludeExclude ( { include : [ 'Post' , 'Comment' ] } ) ( {
27
- name : 'Post' ,
30
+ isResourceIncluded ( {
31
+ include : [ 'Post' , 'Comment' ] ,
32
+ type : {
33
+ name : 'Post' ,
34
+ } ,
28
35
} )
29
36
) . toBe ( true ) ;
30
37
} ) ;
31
38
32
- it ( 'return false with an exclude option containing an array and tested type is in it' , ( ) => {
39
+ it ( 'return false with an include option containing an array and tested type is not in it' , ( ) => {
33
40
expect (
34
- filterTypesByIncludeExclude ( { exclude : [ 'NotMe' ] } ) ( {
35
- name : 'NotMe' ,
41
+ isResourceIncluded ( {
42
+ include : [ 'NotMe' ] ,
43
+ type : {
44
+ name : 'Post' ,
45
+ } ,
36
46
} )
37
47
) . toBe ( false ) ;
38
48
} ) ;
39
49
40
- it ( 'return true with an include option containing an array and tested type is not in it' , ( ) => {
41
- expect (
42
- filterTypesByIncludeExclude ( { exclude : [ 'NotMe' ] } ) ( {
43
- name : 'Post' ,
44
- } )
45
- ) . toBe ( true ) ;
46
- } ) ;
47
-
48
50
it ( 'return true with an include option being a function returning true' , ( ) => {
49
51
const include = jest . fn ( ( ) => true ) ;
50
52
const type = { name : 'Post' } ;
51
- expect ( filterTypesByIncludeExclude ( { include } ) ( type ) ) . toBe ( true ) ;
53
+ expect ( isResourceIncluded ( { include, type } ) ) . toBe ( true ) ;
52
54
expect ( include ) . toHaveBeenCalledWith ( type ) ;
53
55
} ) ;
54
56
55
57
it ( 'return false with an include option being a function returning false' , ( ) => {
56
58
const include = jest . fn ( ( ) => false ) ;
57
59
const type = { name : 'Post' } ;
58
- expect ( filterTypesByIncludeExclude ( { include } ) ( type ) ) . toBe ( false ) ;
60
+ expect ( isResourceIncluded ( { include, type } ) ) . toBe ( false ) ;
59
61
expect ( include ) . toHaveBeenCalledWith ( type ) ;
60
62
} ) ;
63
+ } ) ;
64
+
65
+ describe ( 'isResourceExcluded' , ( ) => {
66
+ it ( 'return true with an exclude option containing an array and tested type is in it' , ( ) => {
67
+ expect (
68
+ isResourceExcluded ( {
69
+ exclude : [ 'NotMe' ] ,
70
+ type : {
71
+ name : 'NotMe' ,
72
+ } ,
73
+ } )
74
+ ) . toBe ( true ) ;
75
+ } ) ;
61
76
62
- it ( 'return false with an exclude option being a function returning true' , ( ) => {
77
+ it ( 'return true with an exclude option being a function returning true' , ( ) => {
63
78
const exclude = jest . fn ( ( ) => true ) ;
64
79
const type = { name : 'Post' } ;
65
- expect ( filterTypesByIncludeExclude ( { exclude } ) ( type ) ) . toBe ( false ) ;
80
+ expect ( isResourceExcluded ( { exclude, type } ) ) . toBe ( true ) ;
66
81
expect ( exclude ) . toHaveBeenCalledWith ( type ) ;
67
82
} ) ;
68
83
69
- it ( 'return true with an exclude option being a function returning false' , ( ) => {
84
+ it ( 'return false with an exclude option being a function returning false' , ( ) => {
70
85
const exclude = jest . fn ( ( ) => false ) ;
71
86
const type = { name : 'Post' } ;
72
- expect ( filterTypesByIncludeExclude ( { exclude } ) ( type ) ) . toBe ( true ) ;
87
+ expect ( isResourceExcluded ( { exclude, type } ) ) . toBe ( false ) ;
73
88
expect ( exclude ) . toHaveBeenCalledWith ( type ) ;
74
89
} ) ;
75
90
} ) ;
0 commit comments