Skip to content

Commit 45446dc

Browse files
committed
Use in-memory persistence in z-webmention-test
Fixes #31
1 parent a107f86 commit 45446dc

File tree

1 file changed

+74
-77
lines changed

1 file changed

+74
-77
lines changed

test/z-webmention-test.js

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ var vows = require('perjury'),
5151
sinon = require('sinon'),
5252
noopLog = require('./lib/log'),
5353
persistenceutil = require('./lib/persistence'),
54-
db = require('../lib/persistence')('/tmp')(noopLog),
55-
wrapFsMocks = persistenceutil.wrapFsMocks,
54+
memoryPersistence = persistenceutil.memoryPersistence,
55+
db = memoryPersistence()(),
5656
data = {
5757
singleLink: '<a href="http://nicenice.website/blag/new-puppy">So cute!</a>',
5858
multipleLinks: '<a href="http://magic.geek/pics/another-doggo">Even cuter!</a> I love <a href="http://catscatscats.org/">cats</a> too!',
5959
noHref: 'It\'s <a href="">yikes-worthy</a>!',
6060
noLinks: 'I have absolutely no links at all.'
6161
};
62-
6362
var clock;
6463

6564
vows.describe('Webmention module').addBatch({
@@ -96,13 +95,33 @@ vows.describe('Webmention module').addBatch({
9695
'we get a function back': function(err, webmention) {
9796
assert.isFunction(webmention[1]);
9897
},
99-
'and we set up persistence mocks': wrapFsMocks({
100-
'and we call the module with a post': {
98+
'and we call the module with a post': {
99+
topic: function(fns) {
100+
var webmention = fns[1],
101+
cb = this.callback;
102+
103+
webmention('http://example.com/socute',
104+
100,
105+
data.singleLink,
106+
function(err) {
107+
cb(err, fns);
108+
});
109+
},
110+
'it works': function(err) {
111+
assert.ifError(err);
112+
},
113+
'the spy was called': function(err, fns) {
114+
var spy = fns[0];
115+
assert.isTrue(spy.calledOnce);
116+
// XXX assert arguments
117+
},
118+
'and we call it with the same data': {
101119
topic: function(fns) {
102120
var webmention = fns[1],
103121
cb = this.callback;
104122

105123
webmention('http://example.com/socute',
124+
// Note: these are smaller because JS dates are in milliseconds but we're passing seconds
106125
100,
107126
data.singleLink,
108127
function(err) {
@@ -112,127 +131,105 @@ vows.describe('Webmention module').addBatch({
112131
'it works': function(err) {
113132
assert.ifError(err);
114133
},
115-
'the spy was called': function(err, fns) {
134+
'the spy wasn\'t called again': function(err, fns) {
116135
var spy = fns[0];
117136
assert.isTrue(spy.calledOnce);
118-
// XXX assert arguments
119137
},
120-
'and we call it with the same data': {
138+
'and we call it with a newer timestamp': {
121139
topic: function(fns) {
122140
var webmention = fns[1],
123-
cb = this.callback;
141+
cb = this.callback;
142+
143+
// This shouldn't matter, but just in case, we set the clock to be past the edited timestamp
144+
clock.tick(100 * 1000);
124145

125146
webmention('http://example.com/socute',
126-
// Note: these are smaller because JS dates are in milliseconds but we're passing seconds
127-
100,
128-
data.singleLink,
129-
function(err) {
130-
cb(err, fns);
131-
});
147+
200,
148+
data.singleLink,
149+
function(err) {
150+
cb(err, fns);
151+
});
152+
},
153+
teardown: function() {
154+
return clock.tick(-100 * 1000);
132155
},
133156
'it works': function(err) {
134157
assert.ifError(err);
135158
},
136-
'the spy wasn\'t called again': function(err, fns) {
159+
'the spy was called a second time': function(err, fns) {
137160
var spy = fns[0];
138-
assert.isTrue(spy.calledOnce);
161+
assert.isTrue(spy.calledTwice);
162+
// XXX assert arguments
139163
},
140-
'and we call it with a newer timestamp': {
164+
// XXX find a way to not nest this so deeply - it
165+
// has to be this way currently so the Sinon spy is
166+
// called in the right order
167+
'and we call it with a post with multiple links': {
141168
topic: function(fns) {
142169
var webmention = fns[1],
143170
cb = this.callback;
144171

145-
// This shouldn't matter, but just in case, we set the clock to be past the edited timestamp
146-
clock.tick(100 * 1000);
147-
148-
webmention('http://example.com/socute',
172+
webmention('http://example.com/morecuteness',
149173
200,
150-
data.singleLink,
174+
data.multipleLinks,
151175
function(err) {
152176
cb(err, fns);
153177
});
154178
},
155-
teardown: function() {
156-
return clock.tick(-100 * 1000);
157-
},
158179
'it works': function(err) {
159180
assert.ifError(err);
160181
},
161-
'the spy was called a second time': function(err, fns) {
182+
'the spy was called two more times': function(err, fns) {
162183
var spy = fns[0];
163-
assert.isTrue(spy.calledTwice);
164-
// XXX assert arguments
184+
assert.equal(spy.callCount, 4);
185+
// XXX args
165186
},
166-
// XXX find a way to not nest this so deeply - it
167-
// has to be this way currently so the Sinon spy is
168-
// called in the right order
169-
'and we call it with a post with multiple links': {
187+
'and we call the module with a post that has a blank <a href="">': {
170188
topic: function(fns) {
171189
var webmention = fns[1],
172190
cb = this.callback;
173191

174-
webmention('http://example.com/morecuteness',
192+
webmention('http://malformed.technology/everything_is_terrible',
175193
200,
176-
data.multipleLinks,
194+
data.noHref,
177195
function(err) {
178196
cb(err, fns);
179197
});
180198
},
181199
'it works': function(err) {
182200
assert.ifError(err);
183201
},
184-
'the spy was called two more times': function(err, fns) {
202+
'the spy wasn\'t called again': function(err, fns) {
185203
var spy = fns[0];
186204
assert.equal(spy.callCount, 4);
187205
// XXX args
206+
}
207+
},
208+
'and we call the module with a post that has no links at all': {
209+
topic: function(fns) {
210+
var webmention = fns[1],
211+
cb = this.callback;
212+
213+
webmention('http://ordinary.net/bland_post',
214+
200,
215+
data.noLinks,
216+
function(err) {
217+
cb(err, fns);
218+
});
188219
},
189-
'and we call the module with a post that has a blank <a href="">': {
190-
topic: function(fns) {
191-
var webmention = fns[1],
192-
cb = this.callback;
193-
194-
webmention('http://malformed.technology/everything_is_terrible',
195-
200,
196-
data.noHref,
197-
function(err) {
198-
cb(err, fns);
199-
});
200-
},
201-
'it works': function(err) {
202-
assert.ifError(err);
203-
},
204-
'the spy wasn\'t called again': function(err, fns) {
205-
var spy = fns[0];
206-
assert.equal(spy.callCount, 4);
207-
// XXX args
208-
}
220+
'it works': function(err) {
221+
assert.ifError(err);
209222
},
210-
'and we call the module with a post that has no links at all': {
211-
topic: function(fns) {
212-
var webmention = fns[1],
213-
cb = this.callback;
214-
215-
webmention('http://ordinary.net/bland_post',
216-
200,
217-
data.noLinks,
218-
function(err) {
219-
cb(err, fns);
220-
});
221-
},
222-
'it works': function(err) {
223-
assert.ifError(err);
224-
},
225-
'the spy wasn\'t called again': function(err, fns) {
226-
var spy = fns[0];
227-
assert.equal(spy.callCount, 4);
228-
// XXX args
229-
}
223+
'the spy wasn\'t called again': function(err, fns) {
224+
var spy = fns[0];
225+
assert.equal(spy.callCount, 4);
226+
// XXX args
230227
}
231228
}
232229
}
233230
}
234231
}
235-
})
232+
}
236233
}
237234
}
238235
}).export(module);

0 commit comments

Comments
 (0)