Commit 5f146d1c authored by David Haynes's avatar David Haynes 🙆 Committed by Mark Stenglein

DelegateesParam: First pass implementation (#20)

* DelegateesParam: Add bare minimum class and comments

This commit adds the DelegateesParam parameter to the repo. The Param
actually does nothing at the moment but I intend to change that.

Additionally a test class is birthed alongside this parameter that
checks the existence of the file. Important stuff.
Signed-off-by: David Haynes's avatarDavid Haynes <dhaynes3@gmu.edu>

* DelegateesParam: Complete comments defining DelegateesParam

Essentially a big copy paste from the RFC. It's really helpful that
DelegatorsParam is so similar.
Signed-off-by: default avatarDavid Haynes <dhaynes207@gmail.com>

* DelegateesParam: Complete first pass on implementation

Delegatees function identically to delegators though have some slight
verbage changes. As a result borrow everything from DelegatorParam but
modify where needed.

Implement test spec to verify implementaion.

Closes #2Signed-off-by: default avatarDavid Haynes <dhaynes207@gmail.com>

* DelegateesParam: whitespace fixes

This commit fixes whitespace on a couple of the files introduced in !20
Signed-off-by: Mark Stenglein's avatarMark Stenglein <mark@stengle.in>
parent 0b29761a
Pipeline #1198 passed with stages
in 52 seconds
/*
* 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 Parameter from "./Parameter";
/**
* DelegateesParam Class (Chapter 3.2.5)
*
* - Purpose: To specify the calendar users to whom the calendar user
* specified by the property has delegated participation.
*
* - Format Definition: This property parameter is defined by the following
* notation:
*
* - deltoparam = "DELEGATED-TO" "=" DQUOTE cal-address
* DQUOTE *("," DQUOTE cal-address DQUOTE)
*
* - Description:
* - The parameter is specified on properties of the CAL-ADDRESS value
* type.
* - This parameter specifies those calendar users whom have been delegated
* participation in a group-scheduled event or to-do by the calendar user
* specified by the property.
* - The individual calendar address parameter values MUST each be specified
* in a quoted-string.
*
* - Example:
*
* ATTENDEE;DELEGATED-TO="mailto:jdoe@example.com","mailto:
* jqpublic@example.com":mailto:jsmith@example.com
*
* @since 0.1.0
* @author David Haynes <dhaynes3@gmu.edu>
*/
export default class DelegateesParam extends Parameter {
private _delegatees: string[];
constructor(delegatees: string | string[]) {
super("DELEGATED-TO", []);
// Converts single string object to an array.
delegatees = (delegatees instanceof Array) ? delegatees : [delegatees];
this.delegatees = delegatees;
}
/**
* Simply returns the current delegatees, as a string array.
*
* @since 0.1.0
* @author David Haynes <dhaynes3@gmu.edu>
*/
get delegatees(): string[] {
return this._delegatees;
}
/**
* Sets the private _delegatees and also writes the "mailto:" to the
* front of each delegatee before writing super.paramValues
*
* @since 0.1.0
* @author David Haynes <dhaynes3@gmu.edu>
*/
set delegatees(newDelegatees: string[]) {
// Ensure each delegatee is valid QSafeChar String
if (!newDelegatees.every(Parameter.isQSafeChar))
throw new TypeError("Delegatee must be QSafeChars");
// Construct paramValues for generation
this.paramValues = newDelegatees.map(
delegatee => `"mailto:${delegatee}"`);
// Saves the given values for the getter funciton
this._delegatees = newDelegatees;
}
}
/*
* 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 DelegateesParam from "../src/DelegateesParam";
import { expect } from "chai";
import "mocha";
/**
* Test the DelegateesParam class.
*/
describe("DelegateesParam:", () => {
it("Should exist", () => {
expect(DelegateesParam).to.exist;
});
describe("Constructor:", () => {
it("Should create an object", () => {
const delegatee: string = "Mark Stenglein";
const delegateeParam: DelegateesParam = new DelegateesParam(delegatee);
expect(delegateeParam).to.exist;
});
it("Should convert string to string[]", () => {
const delegatee: string = "Mark Stenglein";
const testParam: DelegateesParam = new DelegateesParam(delegatee);
expect(testParam.delegatees).to.be.deep.equal([delegatee]);
});
it("Should not add extra layer to input array", () => {
const delegatees: string[] = ["Mark", "Stenglein"];
const testParam: DelegateesParam = new DelegateesParam(delegatees);
expect(testParam.delegatees).to.not.deep.equal([delegatees]);
expect(testParam.delegatees).to.deep.equal(delegatees);
});
});
describe("Setter/Getter:", () => {
it("Sets delegatees", () => {
const delegatees: string[] = ["mark@stengle.in"];
const testParam: DelegateesParam = new DelegateesParam("te@s.t");
testParam.delegatees = delegatees;
expect(testParam.delegatees).to.exist;
});
it("Sets delegatees with no change", () => {
const delegatees: string[] = ["mark@stengle.in"];
const testParam: DelegateesParam = new DelegateesParam("te@s.t");
testParam.delegatees = delegatees;
expect(testParam.delegatees).to.be.deep.equal(delegatees);
});
it("Sets paramValues as well", () => {
const delegatees: string[] = ["mark@stengle.in"];
const testParam: DelegateesParam = new DelegateesParam("te@s.t");
testParam.delegatees = delegatees;
expect(testParam.paramValues).to.exist;
});
it("Sets paramValues correctly", () => {
const delegatees: string[] = ["mark@stengle.in", "te@s.t"];
const testParam: DelegateesParam = new DelegateesParam("diff@ema.il");
testParam.delegatees = delegatees;
const expected: string[] = ["\"mailto:mark@stengle.in\"",
"\"mailto:te@s.t\""];
expect(testParam.paramValues).to.be.deep.equal(expected);
});
describe("Rejects invalid delegatee params:", () => {
it("DQUOTES", () => {
const delegatees: string[] = ["mark\"@stengle.in"];
expect(() => {
new DelegateesParam(delegatees);
}).to.throw("Delegatee must be QSafeChars");
});
});
});
describe("Generator:", () => {
it("Properly Generates output for single delegatee", () => {
const delegatees: string[] = ["mark@stengle.in"];
const testParam: DelegateesParam = new DelegateesParam(delegatees);
const actual: string = "DELEGATED-TO=\"mailto:mark@stengle.in\"";
expect(testParam.generate()).to.be.equal(actual);
});
it("Properly Generates output for multiple delegatees", () => {
const delegatees: string[] = ["one@one.com", "two@two.com"];
const testParam: DelegateesParam = new DelegateesParam(delegatees);
const actual: string = "DELEGATED-TO=\"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