Commit 148aa91e authored by Mark Stenglein's avatar Mark Stenglein

DelegatorsParam: adds basic parameter, tests, and documenatation

More work is still needed here to finish out the spec, mainly
 in enforcing some validations. Check the todo's for the bulk of
 it.

tl;dr: I've been up for more than 24 hours and need to go to bed,
    so here's my commit of progress :)
Signed-off-by: Mark Stenglein's avatarMark Stenglein <mark@stengle.in>
parent 28242e21
Pipeline #1142 passed with stage
in 25 seconds
......@@ -43,24 +43,53 @@ import Parameter from "./Parameter";
*
* ATTENDEE;DELEGATED-FROM="mailto:jsmith@example.com":mailto:
* jdoe@example.com
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
export default class DelegatorsParam extends Parameter {
private _delegators: string[];
/**
* Takes either one email or an array of emails as string or string[]
*
* - There is really no need to require that "mailto:" be included here,
* as it can be easilly added by the set method.
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
constructor(delegators: string | string[]) {
super("DELEGATED-FROM", []);
// Converts single string object to an array.
delegators = (delegators instanceof Array) ? delegators : [delegators];
this._delegators = delegators;
this.delegators = delegators;
}
/**
* Simply returns the current delegators, as a string array.
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
get delegators(): string[] {
return this._delegators;
}
/**
* 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
* are added
*
* @since 0.1.0
* @author Mark Stenglein <mark@stengle.in>
*/
set delegators(newDelegators: string[]) {
this._delegators = newDelegators;
this.paramValues = this._delegators;
}
}
......@@ -63,5 +63,21 @@ describe("DelegatorsParam", () => {
expect(testParam.paramValues).to.be.deep.equal(delegators);
});
});
describe("Generator", () => {
it("Properly Generates output for single delegator", () => {
const delegators: string[] = ["\"mailto: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 testParam: DelegatorsParam = new DelegatorsParam(delegators);
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