UNPKG

2.22 kBJavaScriptView Raw
1describe('.downloads', function () {
2 'use strict';
3
4 var chai = require('chai')
5 , expect = chai.expect;
6
7 var Registry = require('../')
8 , registry = new Registry();
9
10 //
11 // The module name we want to use for testing, it shouldn't matter which
12 // package we use but having the option to configure this is nice.
13 //
14 var module = 'eventemitter3';
15
16 it('has a downloads endpoint', function () {
17 expect(registry.downloads).to.be.a('object');
18 });
19
20 describe('#totals', function () {
21 it('retrieves a modules download stats', function (next) {
22 registry.downloads.totals('last-week', module, function (err, data) {
23 data = Array.isArray(data) ? data[0] : data;
24 if (err) return next(err);
25
26 expect(data.package).to.equal(module);
27 expect(data.downloads).to.be.a('number');
28
29 next();
30 });
31 });
32
33 it('receives download stats for all modules', function (next) {
34 registry.downloads.totals('last-week', function (err, data) {
35 data = Array.isArray(data) ? data[0] : data;
36 if (err) return next(err);
37
38 expect(data.downloads).to.be.a('number');
39
40 next();
41 });
42 });
43 });
44
45 describe('#range', function () {
46 it('retrieves a modules download stats', function (next) {
47 registry.downloads.range('last-week', module, function (err, data) {
48 data = Array.isArray(data) ? data[0] : data;
49 if (err) return next(err);
50
51 expect(data.package).to.equal(module);
52 expect(data.downloads).to.be.a('array');
53 expect(data.downloads).to.have.length(7);
54
55 data.downloads.forEach(function (data) {
56 expect(data.downloads).to.be.a('number');
57 });
58
59 next();
60 });
61 });
62
63 it('receives download stats for all modules', function (next) {
64 registry.downloads.range('last-week', function (err, data) {
65 data = Array.isArray(data) ? data[0] : data;
66 if (err) return next(err);
67
68 expect(data.downloads).to.be.a('array');
69 expect(data.downloads).to.have.length(7);
70
71 data.downloads.forEach(function (data) {
72 expect(data.downloads).to.be.a('number');
73 });
74
75 next();
76 });
77 });
78 });
79});