-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
91 lines (68 loc) · 2.61 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
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
var mocha = require('mocha'),
assert = require('chai').assert,
ig = require('./index');
var nock = require("nock");
var api = nock("https://www.instagram.com").persist()
.get("/explore/tags/nrkvalg").replyWithFile(200, __dirname + '/fixtures/tagPage.html')
.get(/\/p\/\w+/).replyWithFile(200, __dirname + '/fixtures/postPage.html')
.get(/\/explore\/locations\/\d+/).replyWithFile(200, __dirname + '/fixtures/locationPage.html');
describe('instagram-tagscrape', function(){
it('should throw error when called with missing tag argument', function(done){
ig.scrapeTagPage().then(function(result){
assert.fail('Promise should be rejected')
done();
})
.catch(function(err){
assert.typeOf(err, 'error');
done();
});
});
it('should return object containing count, total and media', function(done){
ig.scrapeTagPage('nrkvalg').then(function(result){
assert.isAtLeast(result.count, 1);
assert.isAtLeast(result.total, 1);
assert.equal(result.media.length, result.count);
done();
})
});
it('should throw error when called with missing code argument', function(done){
ig.scrapeTagPage().then(function(result){
assert.fail('Promise should be rejected')
done();
})
.catch(function(err){
assert.typeOf(err, 'error');
done();
});
});
it('should return data from single post', function(done){
ig.scrapePostPage('BMmWPcBhGAv').then(function(result){
assert.equal(result.id, 1379888153741254703);
done();
});
});
it('should throw error when called with missing id argument', function(done){
ig.scrapeLocationPage().then(function(result){
assert.fail('Promise should be rejected')
done();
})
.catch(function(err){
assert.typeOf(err, 'error');
done();
});
});
it('should return location data from locationPage', function(done){
ig.scrapeLocationPage(542401).then(function(result){
assert.equal(result.name, 'Det Akademiske Kvarter');
done();
});
});
it('should return media containing data from loading each post page and location page', function(done){
this.timeout(10000);
ig.deepScrapeTagPage('nrkvalg').then(function(result){
assert.isDefined(result.media[0].owner.username);
assert.isDefined(result.media[5].location.lat);
done();
});
});
});