Commit afcc30ba authored by Mark Stenglein's avatar Mark Stenglein

Add the CalUserTypeParam type

parent ccdbf95f
......@@ -17,13 +17,53 @@
*/
import Parameter from "./Parameter";
/**
* Class implementing section 3.2.3 of RFC 5545: Calendar User Type
*
* Default value of the user type should be INDIVIDUAL if none specified
* (empty string).
*
* TODO: Verify this is only specified on properties with the CAL-ADDRESS
* value type.
*
* @author Mark Stenglein <mark@stenglein>
* @since 0.1.0
*/
export default class CalUserTypeParam extends Parameter {
private _calUserType: string;
constructor(usertype: string) {
super("CUTYPE", []);
if (usertype.length > 0) {
this.calUserType = usertype;
}
else if (usertype.length === 0) {
// Sets the default of INDIVIDUAL to start
this.calUserType = "INDIVIDUAL";
}
}
get calUserType(): string {
return this._calUserType;
}
set calUserType(newType: string) {
if (newType === "INDIVIDUAL" ||
newType === "GROUP" ||
newType === "RESOURCE" ||
newType === "ROOM" ||
newType === "UNKNOWN" ||
Parameter.isXName(newType) ||
Parameter.isIanaToken(newType)
) {
this._calUserType = newType;
this.paramValues = [newType];
}
else {
throw new TypeError("Cal User Type must either be known or valid" +
"XName/Iana Token");
}
}
}
......@@ -25,19 +25,48 @@ describe("CalUserTypeParam", () => {
});
describe("constructor()", () => {
it("Generates a value", () => {
const param: CalUserTypeParam = new CalUserTypeParam("");
expect(param).to.exist;
});
});
it("Generates a default value correctly", () => {
const param: CalUserTypeParam = new CalUserTypeParam("");
expect(param.calUserType).to.be.equal("INDIVIDUAL");
});
it("Sets non-default value correctly", () => {
const param: CalUserTypeParam = new CalUserTypeParam("ROOM");
expect(param.calUserType).to.be.equal("ROOM");
});
describe("GET Methods", () => {
it("Fails on incorrect input type", () => {
expect(() => {
const param: CalUserTypeParam = new CalUserTypeParam("INVALID;NAME");
}).to.throw("Cal User Type must either be known or validXName/Iana Token");
});
});
describe("SET Methods", () => {
describe("GET/SET Methods", () => {
it("Allows for changes and returns correct values", () => {
const param: CalUserTypeParam = new CalUserTypeParam("INDIVIDUAL");
const res1: string = param.calUserType;
param.calUserType = "GROUP";
const res2: string = param.calUserType;
expect(res1).to.be.equal("INDIVIDUAL");
expect(res2).to.be.equal("GROUP");
});
});
describe("generate()", () => {
it("Generates the right value", () => {
const param: CalUserTypeParam = new CalUserTypeParam("GROUP");
const expected: string = "CUTYPE=GROUP";
expect(param.generate()).to.equal(expected);
});
});
});
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