@@ -6,23 +6,33 @@ const DummyModel = types.model('DummyModel', { id: types.identifier });
66
77describe ( 'createAsyncStore' , ( ) => {
88 it ( 'should create AsyncStore model' , ( ) => {
9- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel ) ;
9+ const AsyncStore = createAsyncStore ( {
10+ name : 'AsyncStore' ,
11+ itemModel : DummyModel ,
12+ } ) ;
1013 expect ( AsyncStore . name ) . toBe ( 'AsyncStore' ) ;
1114 } ) ;
1215
1316 it ( 'should create asyncStore instance' , ( ) => {
14- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel ) ;
17+ const AsyncStore = createAsyncStore ( {
18+ name : 'AsyncStore' ,
19+ itemModel : DummyModel ,
20+ } ) ;
1521 const asyncStore = AsyncStore . create ( ) ;
1622 expect ( asyncStore . isReady ) . toBe ( false ) ;
1723 } ) ;
1824
1925 it ( 'should fetch one item' , async ( ) => {
2026 const dummyItem = DummyModel . create ( { id : 'foo' } ) ;
21- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel , ( ) => ( {
22- async fetchOne ( ) {
23- return dummyItem ;
24- } ,
25- } ) ) ;
27+ const AsyncStore = createAsyncStore ( {
28+ name : 'AsyncStore' ,
29+ itemModel : DummyModel ,
30+ fetchActions : ( ) => ( {
31+ async fetchOne ( ) {
32+ return dummyItem ;
33+ } ,
34+ } ) ,
35+ } ) ;
2636 const asyncStore = AsyncStore . create ( ) ;
2737 const container = asyncStore . getOne ( 'foo' ) ;
2838 await when ( ( ) => container . isReady ) ;
@@ -34,11 +44,15 @@ describe('createAsyncStore', () => {
3444 it ( 'should fetch many items' , async ( ) => {
3545 const dummyItem1 = DummyModel . create ( { id : 'foo' } ) ;
3646 const dummyItem2 = DummyModel . create ( { id : 'bar' } ) ;
37- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel , ( ) => ( {
38- async fetchMany ( ) {
39- return [ dummyItem1 , dummyItem2 ] ;
40- } ,
41- } ) ) ;
47+ const AsyncStore = createAsyncStore ( {
48+ name : 'AsyncStore' ,
49+ itemModel : DummyModel ,
50+ fetchActions : ( ) => ( {
51+ async fetchMany ( ) {
52+ return [ dummyItem1 , dummyItem2 ] ;
53+ } ,
54+ } ) ,
55+ } ) ;
4256 const asyncStore = AsyncStore . create ( ) ;
4357 const containers = asyncStore . getMany ( [ 'foo' , 'bar' ] ) ;
4458 await when ( ( ) => asyncStore . isReady ) ;
@@ -50,11 +64,15 @@ describe('createAsyncStore', () => {
5064 it ( 'should fetch all items' , async ( ) => {
5165 const dummyItem1 = DummyModel . create ( { id : 'foo' } ) ;
5266 const dummyItem2 = DummyModel . create ( { id : 'bar' } ) ;
53- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel , ( ) => ( {
54- async fetchAll ( ) {
55- return [ dummyItem1 , dummyItem2 ] ;
56- } ,
57- } ) ) ;
67+ const AsyncStore = createAsyncStore ( {
68+ name : 'AsyncStore' ,
69+ itemModel : DummyModel ,
70+ fetchActions : ( ) => ( {
71+ async fetchAll ( ) {
72+ return [ dummyItem1 , dummyItem2 ] ;
73+ } ,
74+ } ) ,
75+ } ) ;
5876 const asyncStore = AsyncStore . create ( ) ;
5977 asyncStore . getAll ( ) ;
6078 await when ( ( ) => asyncStore . isReady ) ;
@@ -65,11 +83,15 @@ describe('createAsyncStore', () => {
6583 } ) ;
6684
6785 it ( 'should fail to fetch one item' , async ( ) => {
68- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel , ( ) => ( {
69- async fetchOne ( ) {
70- throw Error ( 'Failed to fetch item' ) ;
71- } ,
72- } ) ) ;
86+ const AsyncStore = createAsyncStore ( {
87+ name : 'AsyncStore' ,
88+ itemModel : DummyModel ,
89+ fetchActions : ( ) => ( {
90+ async fetchOne ( ) {
91+ throw Error ( 'Failed to fetch item' ) ;
92+ } ,
93+ } ) ,
94+ } ) ;
7395 const asyncStore = AsyncStore . create ( ) ;
7496 const container = asyncStore . getOne ( 'foo' ) ;
7597 await when ( ( ) => container . isReady ) ;
@@ -79,11 +101,15 @@ describe('createAsyncStore', () => {
79101 } ) ;
80102
81103 it ( 'should fail to fetch many items' , async ( ) => {
82- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel , ( ) => ( {
83- async fetchMany ( ) {
84- throw Error ( 'Failed to fetch items' ) ;
85- } ,
86- } ) ) ;
104+ const AsyncStore = createAsyncStore ( {
105+ name : 'AsyncStore' ,
106+ itemModel : DummyModel ,
107+ fetchActions : ( ) => ( {
108+ async fetchMany ( ) {
109+ throw Error ( 'Failed to fetch items' ) ;
110+ } ,
111+ } ) ,
112+ } ) ;
87113 const asyncStore = AsyncStore . create ( ) ;
88114 const containers = asyncStore . getMany ( [ 'foo' , 'bar' ] ) ;
89115 await when ( ( ) => asyncStore . isReady ) ;
@@ -95,23 +121,32 @@ describe('createAsyncStore', () => {
95121 } ) ;
96122
97123 it ( 'should throw exception when not supporting fetchOne' , async ( ) => {
98- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel ) ;
124+ const AsyncStore = createAsyncStore ( {
125+ name : 'AsyncStore' ,
126+ itemModel : DummyModel ,
127+ } ) ;
99128 const asyncStore = AsyncStore . create ( ) ;
100129 expect ( asyncStore . _fetchOne ( 'foo' ) ) . rejects . toEqual (
101130 Error ( "Store doesn't support fetchOne" )
102131 ) ;
103132 } ) ;
104133
105134 it ( 'should throw exception when not supporting fetchMany' , async ( ) => {
106- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel ) ;
135+ const AsyncStore = createAsyncStore ( {
136+ name : 'AsyncStore' ,
137+ itemModel : DummyModel ,
138+ } ) ;
107139 const asyncStore = AsyncStore . create ( ) ;
108140 expect ( asyncStore . _fetchMany ( [ 'foo' , 'bar' ] ) ) . rejects . toEqual (
109141 Error ( "Store doesn't support fetchMany" )
110142 ) ;
111143 } ) ;
112144
113145 it ( 'should throw exception when not supporting fetchAll' , async ( ) => {
114- const AsyncStore = createAsyncStore ( 'AsyncStore' , DummyModel ) ;
146+ const AsyncStore = createAsyncStore ( {
147+ name : 'AsyncStore' ,
148+ itemModel : DummyModel ,
149+ } ) ;
115150 const asyncStore = AsyncStore . create ( ) ;
116151 expect ( asyncStore . _fetchAll ( ) ) . rejects . toEqual (
117152 Error ( "Store doesn't support fetchAll" )
0 commit comments