forked from chrisben/imgcache.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImgCacheTest.coffee
executable file
·70 lines (59 loc) · 1.79 KB
/
ImgCacheTest.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
log = new ObjectLogger("ImgCacheTest")
class ImgCacheTest
self = @
if Meteor.isClient
imgCache = window.ImgCache
suiteSetup: (test)=>
try
log.enter "suiteSetup"
finally
log.return()
suiteTearDown: (test)->
try
log.enter "suiteTearDown"
finally
log.return()
setup: ->
try
log.enter "setup"
if Meteor.isClient
imgCache.clearCache()
else
lv.ImgCache = {}
finally
log.return()
tearDown: ->
try
log.enter "tearDown"
stubs.restoreAll()
spies.restoreAll()
finally
log.return()
tests:[
{
name: "Ground.Collection - reproduce bug"
func:(test)=>
try
log.enter("Ground.Collection - reproduce bug")
if Meteor.isServer
lv.ImgCache.coll = new Mongo.Collection('testImages')
lv.ImgCache.coll.remove({})
expect(lv.ImgCache.coll.find().count()).to.equal(0)
url = 'http://storage.googleapis.com/menuapp/public/c1.jpg'
id = lv.ImgCache.coll.insert({url: url})
expect(lv.ImgCache.coll.find().count()).to.equal(1)
expect(id).to.be.a('string').that.is.ok
img = lv.ImgCache.coll.findOne({url: url})
expect(img).to.be.an('object').that.has.property('url')
cachedUrl = 'localhost:http://storage.googleapis.com/menuapp/public/c1.jpg'
expect(lv.ImgCache.coll.update({url: url}, {$set: {cachedUrl: cachedUrl}})).to.equal(1)
img = lv.ImgCache.coll.findOne({url: url})
expect(img, 'updated img').to.be.an('object').that.contain.keys(['url', 'cachedUrl'])
finally
log.return()
}
]
try
Munit.run(new ImgCacheTest())
catch err
log.error(err.stack)