Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
lib-ical
Commits
afcc30ba
Commit
afcc30ba
authored
Mar 11, 2017
by
Mark Stenglein
Browse files
Add the CalUserTypeParam type
parent
ccdbf95f
Changes
2
Show whitespace changes
Inline
Side-by-side
src/CalUserTypeParam.ts
View file @
afcc30ba
...
...
@@ -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
"
);
}
}
}
test/CalUserTypeParam.spec.ts
View file @
afcc30ba
...
...
@@ -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
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment