-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
50 lines (45 loc) · 1.29 KB
/
test.js
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
var Promise = require('bluebird');
var assert = require('assert');
var sinon = require('sinon');
var _ = require('lodash');
var trelloBackup = require('./lib');
var fs = require('./lib/fs');
var trello = require('./lib/trello');
var stub = function(obj, meth, fn) {
return sinon.stub(obj, meth).callsFake(fn);
};
var tests = [
function boardNameWithASlash() {
stub(fs, 'readJSONFile', _.constant({ backupDirectory: 'backups' }));
stub(trello, 'getBoards', _.constant(Promise.resolve({ boardId: 'board/name' })));
stub(trello, 'downloadBoard', _.noop);
stub(trello, 'downloadAttachments', _.noop);
stub(console, 'log', _.noop);
function restore() {
fs.readJSONFile.restore();
trello.getBoards.restore();
trello.downloadBoard.restore();
trello.downloadAttachments.restore();
console.log.restore();
}
return trelloBackup('config')
.then(function () {
assert.equal(
trello.downloadBoard.getCall(0).args[0].filename,
'backups/boards/boardId - board_name.json'
);
})
.finally(restore);
}
];
Promise
.each(tests, function (test) {
console.log(test.name);
return test();
})
.then(function () {
console.log('Success');
})
.catch(function (err) {
console.log(err.stack);
});