DelegatorsParam.spec.ts 4.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* lib-ical
* Copyright (C) 2017 Mark Stenglein
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
import DelegatorsParam from "../src/DelegatorsParam";
import { expect } from "chai";
import "mocha";

/**
 * Test the DelegatorsParam class.
 */
25
describe("DelegatorsParam:", () => {
26
27
28
29
    it("Should exist", () => {
        expect(DelegatorsParam).to.exist;
    });

30
    describe("Constructor:", () => {
31
32
33
        it("Should create an object", () => {
            const delegator: string = "Mark Stenglein";
            const delegatorParam: DelegatorsParam = new DelegatorsParam(delegator);
34

35
36
37
38
39
40
            expect(delegatorParam).to.exist;
        });

        it("Should convert string to string[]", () => {
            const delegator: string = "Mark Stenglein";
            const testParam: DelegatorsParam = new DelegatorsParam(delegator);
41

42
43
44
45
46
47
            expect(testParam.delegators).to.be.deep.equal([delegator]);
        });

        it("Should not add extra layer to input array", () => {
            const delegators: string[] = ["Mark", "Stenglein"];
            const testParam: DelegatorsParam = new DelegatorsParam(delegators);
48

49
50
51
52
53
            expect(testParam.delegators).to.not.deep.equal([delegators]);
            expect(testParam.delegators).to.deep.equal(delegators);
        });
    });

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    describe("Setter/Getter:", () => {
        it("Sets delegators", () => {
            const delegators: string[] = ["mark@stengle.in"];
            const testParam: DelegatorsParam = new DelegatorsParam("te@s.t");
            testParam.delegators = delegators;

            expect(testParam.delegators).to.exist;
        });

        it("Sets delegators with no change", () => {
            const delegators: string[] = ["mark@stengle.in"];
            const testParam: DelegatorsParam = new DelegatorsParam("te@s.t");
            testParam.delegators = delegators;

            expect(testParam.delegators).to.be.deep.equal(delegators);
        });

71
        it("Sets paramValues as well", () => {
72
73
            const delegators: string[] = ["mark@stengle.in"];
            const testParam: DelegatorsParam = new DelegatorsParam("te@s.t");
74
            testParam.delegators = delegators;
75

76
77
78
79
            expect(testParam.paramValues).to.exist;
        });

        it("Sets paramValues correctly", () => {
80
81
            const delegators: string[] = ["mark@stengle.in", "te@s.t"];
            const testParam: DelegatorsParam = new DelegatorsParam("diff@ema.il");
82
            testParam.delegators = delegators;
83
84
85
86
87
88
89
90
91
92
93
94
95
96

            const expected: string[] = ["\"mailto:mark@stengle.in\"",
                                        "\"mailto:te@s.t\""];
            expect(testParam.paramValues).to.be.deep.equal(expected);
        });

        describe("Rejects invalid delegator params:", () => {
            it("DQUOTES", () => {
                const delegators: string[] = ["mark\"@stengle.in"];

                expect(() => {
                    new DelegatorsParam(delegators);
                }).to.throw("Delegator must be QSafeChars");
            });
97
98
        });
    });
99

100
    describe("Generator:", () => {
101
        it("Properly Generates output for single delegator", () => {
102
            const delegators: string[] = ["mark@stengle.in"];
103
            const testParam: DelegatorsParam = new DelegatorsParam(delegators);
104

105
106
107
108
109
            const actual: string = "DELEGATED-FROM=\"mailto:mark@stengle.in\"";
            expect(testParam.generate()).to.be.equal(actual);
        });

        it("Properly Generates output for multiple delegators", () => {
110
            const delegators: string[] = ["one@one.com", "two@two.com"];
111
            const testParam: DelegatorsParam = new DelegatorsParam(delegators);
112
113
114

            const actual: string = "DELEGATED-FROM=\"mailto:one@one.com\"," +
                "\"mailto:two@two.com\"";
115
116
117
            expect(testParam.generate()).to.be.equal(actual);
        });
    });
118
119
});