1
- import { postList } from './bootstrap/server.js' ;
1
+ import { postList , postListCached } from './bootstrap/server.js' ;
2
2
import { createQuery } from 'meteor/cultofcoders:grapher' ;
3
3
4
+
4
5
describe ( 'Named Query' , function ( ) {
5
6
it ( 'Should return the proper values' , function ( ) {
6
7
const createdQuery = createQuery ( {
@@ -42,5 +43,31 @@ describe('Named Query', function () {
42
43
assert . isObject ( post . author ) ;
43
44
assert . isObject ( post . group ) ;
44
45
} )
45
- } )
46
- } ) ;
46
+ } ) ;
47
+
48
+ it ( 'Should properly cache the values' , function ( done ) {
49
+ const posts = postListCached . fetch ( ) ;
50
+ const postsCount = postListCached . getCount ( ) ;
51
+
52
+ const Posts = Mongo . Collection . get ( 'posts' ) ;
53
+ const postId = Posts . insert ( { title : 'Hello Cacher!' } ) ;
54
+
55
+ assert . equal ( posts . length , postListCached . fetch ( ) . length ) ;
56
+ assert . equal ( postsCount , postListCached . getCount ( ) ) ;
57
+
58
+ Meteor . setTimeout ( function ( ) {
59
+ const newPosts = postListCached . fetch ( ) ;
60
+ const newCount = postListCached . getCount ( ) ;
61
+
62
+ Posts . remove ( postId ) ;
63
+
64
+ assert . isArray ( newPosts ) ;
65
+ assert . isNumber ( newCount ) ;
66
+
67
+ assert . equal ( posts . length + 1 , newPosts . length ) ;
68
+ assert . equal ( postsCount + 1 , newCount ) ;
69
+
70
+ done ( ) ;
71
+ } , 500 )
72
+ } ) ;
73
+ } ) ;
0 commit comments