Commit 88db3b2b authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Added CommonNameParam

parent b001f9be
......@@ -209,6 +209,25 @@ representation for a textual property value.
- The URI parameter value MUST be specified in a quoted-string.
### 3.2.2. Common Name
- To specify the common name to be associated with the calendar user specified
by the property.
- Format Definition: This property parameter is defined by the following
notation:
- `cnparam = "CN" "=" param-value`
- Description: This parameter can be specified on properties with a CAL-ADDRESS
value type. The parameter specifies the common name to be associated with the
calendar user specified by the property. The parameter value is text. The
parameter value can be used for display text to be associated with the calendar
address specified by the property.
- Example:
- `ORGANIZER;CN="John Smith":mailto:jsmith@example.com`
### 3.2.3. Calendar User Type
### 3.2.4. Delegators
### 3.2.5. Delegatees
......
import Parameter from "./Parameter";
/**
* **Implements Section 3.2.2: Common Name from RFC 5545**
*
* Example (see the CN param):
*
* `ORGANIZER;CN="John Smith":mailto:jsmith@example.com`
*
* Defined as:
*
* `cnparam = "CN" "=" param-value`
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
*/
export default class CommonNameParam extends Parameter {
private _commonName: string;
constructor(commonName: string) {
super("CN", []);
this.commonName = commonName;
this.paramValues = [this.commonName];
}
get commonName() {
return this._commonName;
}
/**
* Checks to make sure that the common name is either param-text or
* quoted-text and sets the private commonName variable.
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
* @param newCommonName the new common name to be validated and set
* @returns void
*/
set commonName(newCommonName: string) {
this._commonName = newCommonName;
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ export default class Parameter implements ICalElement {
*/
private _paramValues: string[];
/**
* Value determines whether or not the parameter requres that the content
* Value determines whether or not the parameter requires that the content
* line stores a value alongside the Parameter. Consult the individual
* implementations' documentation in the RFC to see more information on
* parameters which require this.
......
import CommonNameParam from "../src/CommonNameParam";
import { expect } from "chai";
import "mocha";
describe("CommonNameParam", () => {
it("exists", () => {
expect(CommonNameParam).to.exist;
});
describe("constructor", () => {
it("Generates a value", () => {
const param: CommonNameParam = new CommonNameParam("@ocelotsloth");
expect(param).to.exist;
});
it("Fails on bad input `\"`", () => {
expect(() => {
const param: CommonNameParam = new CommonNameParam("Bad quotes \" in middle");
}).to.throw(
"param-value must either be valid paramtext or quoted-string"
);
});
it("Fails on bad input `;`", () => {
expect(() => {
const param: CommonNameParam = new CommonNameParam("Bad semicolons ; in middle");
}).to.throw(
"param-value must either be valid paramtext or quoted-string"
);
});
});
describe("GET Methods", () => {
it("Retruns a value", () => {
const param: CommonNameParam = new CommonNameParam("@ocelotsloth");
expect(param.commonName).to.exist;
});
it("Returns the correct value", () => {
const param: CommonNameParam = new CommonNameParam("@ocelotsloth");
expect(param.commonName).to.equal("@ocelotsloth");
});
});
describe("SET Methods", () => {
it("Allows changes to common name", () => {
const param: CommonNameParam = new CommonNameParam("Mark Stenglein");
expect(param.commonName).to.equal("Mark Stenglein");
param.commonName = "@ocelotsloth";
expect(param.commonName).to.equal("@ocelotsloth");
});
});
describe("generate()", () => {
it("Generates the right value", () => {
const param: CommonNameParam = new CommonNameParam("Mark Stenglein");
const expected: string = "CN=Mark Stenglein";
expect(param.generate()).to.equal(expected);
});
});
});
\ No newline at end of file
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