1 | 'use strict';
|
2 |
|
3 | const expect = require('chai').expect;
|
4 | const inherits = require('util').inherits;
|
5 | const Data = require('./data');
|
6 |
|
7 | exports.validateId = function(obj) {
|
8 | expect(obj).to.not.be.null;
|
9 | expect(obj).to.be.a('object');
|
10 | expect(obj._id.toString()).to.be.a('string');
|
11 | expect(obj._id.toString()).to.have.length.of.at.least(1);
|
12 | };
|
13 |
|
14 | exports.data1 = function() {
|
15 | let data = Data.create();
|
16 | data.number = 1;
|
17 | data.source = 'arstechnica';
|
18 | data.item = 99;
|
19 | data.values = [33, 101, -1];
|
20 | data.date = 1434304033241;
|
21 | return data;
|
22 | };
|
23 |
|
24 | exports.validateData1 = function(d) {
|
25 | expect(d.number).to.be.equal(1);
|
26 | expect(d.source).to.be.equal('arstechnica');
|
27 | expect(d.item).to.be.equal(99);
|
28 | expect(d).to.have.property('values').with.length(3);
|
29 | expect(d.date.valueOf()).to.be.equal(1434304033241);
|
30 | };
|
31 |
|
32 | exports.data2 = function() {
|
33 | let data = Data.create();
|
34 | data.number = 2;
|
35 | data.source = 'reddit';
|
36 | data.item = 26;
|
37 | data.values = [1, 2, 3, 4];
|
38 | data.date = 1434304039234;
|
39 | return data;
|
40 | };
|
41 |
|
42 | exports.validateData2 = function(d) {
|
43 | expect(d.number).to.be.equal(2);
|
44 | expect(d.source).to.be.equal('reddit');
|
45 | expect(d.item).to.be.equal(26);
|
46 | expect(d).to.have.property('values').with.length(4);
|
47 | expect(d.date.valueOf()).to.be.equal(1434304039234);
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | const FailError = function(expected, actual, message) {
|
57 | Error.call(this);
|
58 | Error.captureStackTrace(this, FailError);
|
59 | this.name = 'FailError';
|
60 | this.expected = expected;
|
61 | this.actual = actual;
|
62 | this.message = message;
|
63 | };
|
64 | inherits(FailError, Error);
|
65 |
|
66 | exports.fail = function(expected, actual, message) {
|
67 | throw new FailError(expected, actual, message);
|
68 | };
|
69 |
|
70 | exports.expectError = function(error) {
|
71 | if (error instanceof FailError) {
|
72 | expect.fail(error.expected, error.actual, error.message);
|
73 | return;
|
74 | }
|
75 | expect(error instanceof Error).to.be.true;
|
76 | }; |
\ | No newline at end of file |