Commit 2d1a6b5f authored by Mark Stenglein's avatar Mark Stenglein

DelegatorsParam: Finish out initial build

This commit along with the previous commits implements
the Delegator Parameter sufficiently to move on.

There are still a couple of TODO's out for this one,
but for the most part it's all ++ and the test cases are
successful.

When this gets to the point where I have implemented the
different CAL-ADDRESS value type, I'll need to come back to this
and figure out how to implement that TODO.
Signed-off-by: Mark Stenglein's avatarMark Stenglein <mark@stengle.in>
parent 148aa91e
......@@ -44,6 +44,8 @@ import Parameter from "./Parameter";
* ATTENDEE;DELEGATED-FROM="mailto:jsmith@example.com":mailto:
* jdoe@example.com
*
* - Note: The Param here ends with the DQUOTE, the rest is part of ATTENDEE
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
......@@ -81,15 +83,34 @@ export default class DelegatorsParam extends Parameter {
* Sets the private _delegators and also writes the "mailto:" to the
* front of each delegator before writing super.paramValues
*
* TODO: Add proper testing to make sure that only valid delegators
* DONE: Add proper testing to make sure that only valid delegators
* are added
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
set delegators(newDelegators: string[]) {
// Empty array to build the parent paramValues from newDelegators
const paramValues: string[] = [];
/*
* Checks to make sure that each individual Delegator
* consists only of QSafeChars before wrapping it in DQUOTEs
* and adding the `mailto:`
*/
newDelegators.forEach((newDelegator: string) => {
if (!Parameter.isQSafeChar(newDelegator)) {
throw new TypeError("Delegator must be QSafeChars");
} else {
paramValues.push("\"mailto:" + newDelegator + "\"");
}
});
// Passes the built paramValues to the Parent class
this.paramValues = paramValues;
// Saves the given values for the getter funciton
this._delegators = newDelegators;
this.paramValues = this._delegators;
}
}
......@@ -22,60 +22,96 @@ import "mocha";
/**
* Test the DelegatorsParam class.
*/
describe("DelegatorsParam", () => {
describe("DelegatorsParam:", () => {
it("Should exist", () => {
expect(DelegatorsParam).to.exist;
});
describe("Constructor", () => {
describe("Constructor:", () => {
it("Should create an object", () => {
const delegator: string = "Mark Stenglein";
const delegatorParam: DelegatorsParam = new DelegatorsParam(delegator);
expect(delegatorParam).to.exist;
});
it("Should convert string to string[]", () => {
const delegator: string = "Mark Stenglein";
const testParam: DelegatorsParam = new DelegatorsParam(delegator);
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);
expect(testParam.delegators).to.not.deep.equal([delegators]);
expect(testParam.delegators).to.deep.equal(delegators);
});
});
describe("Setter/Getter", () => {
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);
});
it("Sets paramValues as well", () => {
const delegators: string[] = ["Mark", "Stenglein"];
const testParam: DelegatorsParam = new DelegatorsParam("test");
const delegators: string[] = ["mark@stengle.in"];
const testParam: DelegatorsParam = new DelegatorsParam("te@s.t");
testParam.delegators = delegators;
expect(testParam.paramValues).to.exist;
});
it("Sets paramValues correctly", () => {
const delegators: string[] = ["Mark", "Stenglein"];
const testParam: DelegatorsParam = new DelegatorsParam("test");
const delegators: string[] = ["mark@stengle.in", "te@s.t"];
const testParam: DelegatorsParam = new DelegatorsParam("diff@ema.il");
testParam.delegators = delegators;
expect(testParam.paramValues).to.be.deep.equal(delegators);
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");
});
});
});
describe("Generator", () => {
describe("Generator:", () => {
it("Properly Generates output for single delegator", () => {
const delegators: string[] = ["\"mailto:mark@stengle.in\""];
const delegators: string[] = ["mark@stengle.in"];
const testParam: DelegatorsParam = new DelegatorsParam(delegators);
const actual: string = "DELEGATED-FROM=\"mailto:mark@stengle.in\"";
expect(testParam.generate()).to.be.equal(actual);
});
it("Properly Generates output for multiple delegators", () => {
const delegators: string[] = ["\"mailto:one@one.com\"", "\"mailto:two@two.com\""];
const delegators: string[] = ["one@one.com", "two@two.com"];
const testParam: DelegatorsParam = new DelegatorsParam(delegators);
const actual: string = "DELEGATED-FROM=\"mailto:one@one.com\",\"mailto:two@two.com\"";
const actual: string = "DELEGATED-FROM=\"mailto:one@one.com\"," +
"\"mailto:two@two.com\"";
expect(testParam.generate()).to.be.equal(actual);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment