forked from youiest/youiest-unionize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testUpdateClient.coffee
100 lines (84 loc) · 3.06 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
# 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