1 | const chai = require('chai');
|
2 | const expect = chai.expect;
|
3 | const asPromised = require('chai-as-promised');
|
4 | chai.use(asPromised);
|
5 | const TestConfig = require('../config');
|
6 | const Task = require('../../app/models/task');
|
7 | const TasksService = require('../../app/services/tasks');
|
8 |
|
9 | describe('tasks service', function () {
|
10 | this.timeout(5000);
|
11 |
|
12 | it('does not add a task if a mutator cannot be found in redis', (done) => {
|
13 |
|
14 | const task = new Task({
|
15 | source: TestConfig.elasticsearch.source,
|
16 | destination: TestConfig.elasticsearch.destination,
|
17 | transfer: {
|
18 | documents: {
|
19 | fromIndices: '*'
|
20 | }
|
21 | },
|
22 | mutators: {
|
23 | actions: [{id: 'doesNotExist'}]
|
24 | }
|
25 | });
|
26 |
|
27 | const redisClient = {
|
28 | sismember: () => Promise.resolve(false),
|
29 | sadd: () => done(new Error('Should not be called.')),
|
30 | del: () => done(new Error('Should not be called.')),
|
31 | hexists: () => Promise.resolve(false)
|
32 | };
|
33 |
|
34 | const tasksService = new TasksService(redisClient);
|
35 | expect(tasksService.add('testid', task)).to.be.rejectedWith('Src for mutator id doesNotExist not found')
|
36 | .then(() => done());
|
37 | });
|
38 |
|
39 | it('does not add a task if a filter cannot be found in redis', (done) => {
|
40 |
|
41 | const task = new Task({
|
42 | source: TestConfig.elasticsearch.source,
|
43 | destination: TestConfig.elasticsearch.destination,
|
44 | transfer: {
|
45 | documents: {
|
46 | fromIndices: '*',
|
47 | filters: {
|
48 | actions: [{id: 'doesNotExist'}]
|
49 | }
|
50 | }
|
51 | }
|
52 | });
|
53 |
|
54 | const redisClient = {
|
55 | sismember: () => Promise.resolve(false),
|
56 | sadd: () => done(new Error('Should not be called.')),
|
57 | del: () => done(new Error('Should not be called.')),
|
58 | hexists: () => Promise.resolve(false)
|
59 | };
|
60 |
|
61 | const tasksService = new TasksService(redisClient);
|
62 | expect(tasksService.add('testid', task)).to.be.rejectedWith('Src for filter id doesNotExist not found')
|
63 | .then(() => done());
|
64 | });
|
65 |
|
66 | }); |
\ | No newline at end of file |