-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
88 lines (84 loc) · 3.08 KB
/
test.js
File metadata and controls
88 lines (84 loc) · 3.08 KB
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
var nock = require('nock');
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var yoapi = require('./index');
chai.use(chaiAsPromised);
var expect = chai.expect;
describe('yo-api', function() {
describe('Default behavior', function() {
it('should partially apply if passed a string as the first argument', function () {
expect(yoapi('asdfghjkl')).to.be.a('function');
});
it('should throw if passed anything other than a string first', function() {
expect(function() { yoapi(1) }).to.throw(Error);
expect(function() { yoapi([]) }).to.throw(Error);
expect(function() { yoapi({}) }).to.throw(Error);
expect(function() { yoapi(null) }).to.throw(Error);
expect(function() { yoapi(undefined) }).to.throw(Error);
});
});
describe('sendYo', function() {
beforeEach(function() {
nock('https://api.justyo.co')
.post('/yo/', {
'api_token': 'asdfghjkl',
'username': 'aulekin'
})
.reply(200, {
'success': true, // lol, this is what 200 is for...
'yo_id': '553159ba9e43a200273eb64b'
});
});
it('should send a yo to the username', function() {
expect(yoapi._sendYo('asdfghjkl', 'aulekin')).to.eventually.eql({
'success': true,
'yo_id': '553159ba9e43a200273eb64b'
});
});
// TODO: Figure out why nock behavior is different for this case
it('should provide a callback api as well', function(done) {
yoapi._sendYo('asdfghjkl', 'aulekin', function(err, body) {
expect(err).to.be.null;
expect(body).to.eql({
'success': true,
'yo_id': '553159ba9e43a200273eb64b'
});
done();
});
});
it('should silently convert username "all" into a /yoall/ call', function() {
throw new Error('write this test');
});
describe('link sending', function() {
it('should send a link if one is provided', function() {
throw new Error('write this test');
});
it('should fail if link is not a URL', function() {
throw new Error('write this test');
});
})
});
describe('getSubscribers', function() {
beforeEach(function() {
nock('https://api.justyo.co')
.get('/subscribers_count/?api_token=asdfghjkl')
.reply('200', { count: 5 });
});
it('should resolve to the response body', function() {
expect(yoapi.subs('asdfghjkl')).to.eventually.have.property('count');
});
it('should accept a callback', function(done) {
yoapi.subs('asdfghjkl', function(err, data) {
expect(data).to.eql({ count: 5 });
done();
});
});
it('should throw if passed anything other than a string', function() {
expect(function() { yoapi.subs(1) }).to.throw(Error);
expect(function() { yoapi.subs([]) }).to.throw(Error);
expect(function() { yoapi.subs({}) }).to.throw(Error);
expect(function() { yoapi.subs(null) }).to.throw(Error);
expect(function() { yoapi.subs(undefined) }).to.throw(Error);
});
});
});