-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestUpdateClient.coffee
149 lines (127 loc) · 4.91 KB
/
testUpdateClient.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# emulate a logged in user, this is user, later use real user
@user = 'wiber'
@recFrom = 'picture'
ConsoleMe.enabled = true
Meteor.methods
"dummyInsert" : (args) ->
unless args
args = user
one = WI.insert
'_id': args
two = W.insert
'_id': args
#smite one, two, 'dummyInsert buckle my shoe'
return one
"clearDb": () ->
#smite eval(s), 'clearDb'
one = W.remove {}
two = WI.remove {}
smite one, two, 'clearDb buckle my boots', WI.find({}).count() , eval s
return WI.findOne({})
@generateRecommend = (i) ->
to: user+i
from: recFrom+i
Meteor.startup ->
if Meteor.isClient
testing = 0
Tinytest.addAsync 'clear - '+testing+' call clearDb server clears db and W goes to 0 items', (test, next) ->
Meteor.call 'clearDb', (res,err) ->
one = WI.find({}).count()
# test async that there are no items in db, returns only one time
test.equal one, 0
next()
testing++
Tinytest.addAsync 'clear - '+testing+' call clearDb server clears db and WI goes to 0 items', (test, next) ->
two = WI.find({}).count()
test.equal two, 0
next()
testing++
Tinytest.add 'insert - '+testing+' dummyInsert creates WI user object synced to client', (test, next) ->
Meteor.call 'dummyInsert', user, (res, err) ->
userCreated = WI.findOne
'_id': user
smite userCreated, user
test.equal userCreated._id, user
next()
testing++
Tinytest.addAsync 'update - '+testing+' clientside update of WI should hook same inserted into W', (test, next) ->
rec = generateRecommend testing
connect rec
Tracker.autorun (computation) ->
one = W.findOne
from: rec.from
to: rec.to
smite rec, one, testing, 'testing inserted', eval s
unless !one
test.equal one.from, rec.from
next()
testing++
Tinytest.addAsync 'update - '+testing+' client WI.outbox -> server W -> client WI.inbox', (test, next) ->
rec = generateRecommend testing
connect rec
Tracker.autorun (computation) ->
two = WI.findOne
_id: rec.to
smite rec, two, testing, 'testing update outbox to inbox', eval s
unless !two.inbox
test.equal two.inbox[0].from, rec.from
next()
testing++
Tinytest.addAsync 'feed - '+testing+' client WI.feed has ten dummy items hooked in after server sees feed field', (test, next) ->
# when server sees a feed attribute, it fills it called by a hook
WI.update
_id: user
,
feed: 'nothing'
Tracker.autorun (computation) ->
smite feed = WI.find({_id:'wiber'}).fetch()[0].feed, eval s
# does third feed item have a journey?
unless !feed[3].journey
# the feed function will add feed to the journey of the object
# has this feed item been created by journey?
test.equal Object.keys(feed[3].journey[0])[0], 'feed'
next()
#smite one, two, 'one two in testing',testing, rec.from, 'rec', err, eval s
Tinytest.addAsync 'update - '+testing+' client WI.outbox -> server W -> client WI.inbox', (test, next) ->
rec = generateRecommend testing
connect rec
Tracker.autorun (computation) ->
two = WI.findOne
_id: rec.to
smite rec, two, testing, 'testing update outbox to inbox', eval s
unless !two.inbox
test.equal two.inbox[0].from, rec.from
next()
testing++
Tinytest.addAsync 'session - '+testing+' assure us that dot notation does not rerun tracker', (test, next) ->
# when server sees a feed attribute, it fills it called by a hook
sending = WI.findOne({_id: user}).sending
#sending0 = WI.findOne({_id: user}).sending[0]
Session.set 'sending', sending
smite sending, 'should be undefined', eval s
sessionTracker = 0
connect generateRecommend testing++
rec = generateRecommend testing++
connect rec
smite sending, 'should be undefined', eval s
setTimeout (->
rec = generateRecommend testing++
connect rec
), 500
setTimeout (->
rec = generateRecommend testing++
connect rec
), 250
Tracker.autorun (computation) ->
smite inbox = WI.findOne({_id: user}).inbox, 'should INBOX', eval s
smite sending = WI.findOne({_id: user}).sending, 'should sending', eval s
sessionTracker++
smite sending, eval s
smite sessionTracker, 'did this run multiple times?', inbox, eval s
#smite feed = WI.find({_id:'wiber'}).fetch()[0].feed, eval s
# does third feed item have a journey?
unless sessionTracker = 1
# the feed function will add feed to the journey of the object
# has this feed item been created by journey?
test.equal WI.find({_id:'wiber'}).fetch()[0].sending[0], Session.get 'sending'
next()