UNPKG

2.63 kBJavaScriptView Raw
1var assert = require('assert');
2var Ticket = require('../lib/ticket');
3var Tickets = require('../lib/tickets');
4
5describe('Tickets', function() {
6 var ts, t1, t2;
7
8 before(function () {
9 t1 = new Ticket();
10 t2 = new Ticket();
11 ts = new Tickets();
12 ts.push(t1);
13 ts.push(t2);
14 })
15
16 it('should accept', function () {
17 assert.ok(!t1.isAccepted, 'ticket 1 is not accepted');
18 assert.ok(!t2.isAccepted, 'ticket 2 is not accepted');
19 ts.accept();
20 assert.ok(t1.isAccepted, 'ticket 1 is accepted');
21 assert.ok(t2.isAccepted, 'ticket 2 is accepted');
22 })
23
24 it('should queue', function () {
25 assert.ok(!t1.isQueued, 'ticket 1 is not queued');
26 assert.ok(!t2.isQueued, 'ticket 2 is not queued');
27 ts.queued();
28 assert.ok(t1.isQueued, 'ticket 1 is queued');
29 assert.ok(t2.isQueued, 'ticket 2 is queued');
30 })
31
32 it('should start and stop', function () {
33 assert.ok(!t1.isStarted, 'ticket 1 is not started');
34 assert.ok(!t2.isStarted, 'ticket 2 is not started');
35 ts.started();
36 assert.ok(t1.isStarted, 'ticket 1 is started');
37 assert.ok(t2.isStarted, 'ticket 2 is started');
38 ts.stopped();
39 assert.ok(!t1.isStarted, 'ticket 1 is stopped');
40 assert.ok(!t2.isStarted, 'ticket 2 is stopped');
41 })
42
43 it('should finish and emit', function (done) {
44 assert.ok(!t1.isFinished, 'ticket 1 is not finished');
45 assert.ok(!t2.isFinished, 'ticket 2 is not finished');
46 t2.once('finish', function (result) {
47 assert.deepEqual(result, { x: 1 });
48 assert.ok(t2.isFinished, 'ticket 2 is finished');
49 done();
50 })
51 ts.finish({ x: 1 });
52 })
53
54 it('should fail and emit', function (done) {
55 assert.ok(!t1.isFailed, 'ticket 1 not failed');
56 assert.ok(!t2.isFailed, 'ticket 2 not failed');
57 var called = 0;
58 t1.once('failed', function (err) {
59 assert.equal(err, 'some_error');
60 assert.ok(t1.isFailed, 'ticket 1 failed');
61 called++;
62 if (called == 2) { done() }
63 })
64 t2.once('failed', function (err) {
65 assert.equal(err, 'some_error');
66 assert.ok(t2.isFailed, 'ticket 2 failed');
67 called++;
68 if (called == 2) { done() }
69 })
70 ts.failed('some_error');
71 })
72
73 it('should progress and emit', function (done) {
74 t1.once('progress', function (progress) {
75 assert.equal(progress.pct, 50);
76 assert.equal(progress.complete, 1);
77 assert.equal(progress.total, 2);
78 assert.equal(progress.message, 'test');
79 assert.equal(typeof progress.eta, 'string');
80 done()
81 });
82 ts.progress({
83 complete: 1,
84 total: 2,
85 message: 'test'
86 });
87 })
88
89
90})