1 | "use strict";
|
2 |
|
3 | const Filter = require('./EmailFilter');
|
4 | const Class = require('./EmailSender');
|
5 | const assert = require('assert');
|
6 |
|
7 | class FilterImpl extends Filter
|
8 | {
|
9 |
|
10 | constructor(allow)
|
11 | {
|
12 | super('stub')
|
13 | this.allow = allow;
|
14 | }
|
15 |
|
16 | async doesAllow(address_)
|
17 | {
|
18 | return this.allow;
|
19 | }
|
20 |
|
21 | }
|
22 |
|
23 | describe(Class.name, function ()
|
24 | {
|
25 | let instance;
|
26 | let oldSendImplementation = Class.prototype.sendImplementation;
|
27 |
|
28 | beforeEach(async function ()
|
29 | {
|
30 | instance = new Class();
|
31 | });
|
32 |
|
33 | afterEach(async function ()
|
34 | {
|
35 | Class.prototype.sendImplementation = oldSendImplementation;
|
36 | });
|
37 |
|
38 | it(`empty filters`, async function ()
|
39 | {
|
40 | assert.deepEqual(instance.filters, []);
|
41 | });
|
42 |
|
43 | it(`abstract implementation`, async function ()
|
44 | {
|
45 | try
|
46 | {
|
47 | await instance.sendImplementation('test@localhost', 'test@localhost', 'SUBJECT', 'BODY')
|
48 | }
|
49 | catch (e)
|
50 | {
|
51 | return;
|
52 | }
|
53 | throw new Error('FAIL');
|
54 | });
|
55 |
|
56 | it(`filter does not allow`, async function ()
|
57 | {
|
58 | try
|
59 | {
|
60 | instance.filters.push(new FilterImpl(false))
|
61 | await instance.send('test@localhost', 'test@localhost', 'SUBJECT', 'BODY')
|
62 | }
|
63 | catch (e)
|
64 | {
|
65 | return;
|
66 | }
|
67 | throw new Error('FAIL');
|
68 | });
|
69 |
|
70 | it(`no filters go through`, function (done)
|
71 | {
|
72 | instance.sendImplementation = () => done()
|
73 | instance.send('test@localhost', 'test@localhost', 'SUBJECT', 'BODY')
|
74 | });
|
75 |
|
76 | it(`filter allows`, function (done)
|
77 | {
|
78 | instance.sendImplementation = () => done()
|
79 | instance.filters.push(new FilterImpl(true))
|
80 | instance.send('test@localhost', 'test@localhost', 'SUBJECT', 'BODY')
|
81 | });
|
82 | });
|