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