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
fea16485
Commit
fea16485
authored
Jul 22, 2014
by
Sebastian Pekarek
Browse files
unit test update
parent
2225c133
Changes
2
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
fea16485
...
...
@@ -10,7 +10,8 @@
"dependencies"
:
{},
"devDependencies"
:
{
"
mocha
"
:
"
^1.20.1
"
,
"
istanbul
"
:
"
^0.3.0
"
"
istanbul
"
:
"
^0.3.0
"
,
"
portfinder
"
:
"
^0.2.1
"
},
"scripts"
:
{
"test"
:
"istanbul cover _mocha -- -R spec"
...
...
test/test.js
View file @
fea16485
var
assert
=
require
(
"
assert
"
);
describe
(
'
ical-generator
'
,
function
()
{
'
use strict
'
;
describe
(
'
setDomain()
'
,
function
()
{
it
(
'
should return all public methods
'
,
function
()
{
var
generator
=
require
(
__dirname
+
'
/../lib/ical-generator.js
'
),
...
...
@@ -75,7 +77,7 @@ describe('ical-generator', function() {
assert
.
throws
(
function
()
{
cal
.
setProdID
({});
},
/prodid.company is a mandatory item/
);
},
/prodid
\
.
company is a mandatory item/
);
});
it
(
'
should throw error when no product given
'
,
function
()
{
...
...
@@ -86,7 +88,7 @@ describe('ical-generator', function() {
cal
.
setProdID
({
company
:
'
sebbo.net
'
});
},
/prodid.product is a mandatory item/
);
},
/prodid
\
.
product is a mandatory item/
);
});
it
(
'
should change something #1
'
,
function
()
{
...
...
@@ -143,7 +145,7 @@ describe('ical-generator', function() {
assert
.
throws
(
function
()
{
cal
.
addEvent
({});
},
/event.start is a mandatory item/
);
},
/event
\
.
start is a mandatory item/
);
});
it
(
'
should throw error when start time is not a date
'
,
function
()
{
...
...
@@ -154,7 +156,7 @@ describe('ical-generator', function() {
cal
.
addEvent
({
start
:
'
hello
'
});
},
/event.start must be a Date Object/
);
},
/event
\
.
start must be a Date Object/
);
});
it
(
'
should throw error when no end time given
'
,
function
()
{
...
...
@@ -165,7 +167,7 @@ describe('ical-generator', function() {
cal
.
addEvent
({
start
:
new
Date
()
});
},
/event.end is a mandatory item/
);
},
/event
\
.
end is a mandatory item/
);
});
it
(
'
should throw error when end time is not a date
'
,
function
()
{
...
...
@@ -177,7 +179,7 @@ describe('ical-generator', function() {
start
:
new
Date
(),
end
:
'
hello
'
});
},
/event.end must be a Date Object/
);
},
/event
\
.
end must be a Date Object/
);
});
it
(
'
should throw error when time stamp is not a date
'
,
function
()
{
...
...
@@ -190,7 +192,7 @@ describe('ical-generator', function() {
end
:
new
Date
(),
stamp
:
'
hello
'
});
},
/event.stamp must be a Date Object/
);
},
/event
\
.
stamp must be a Date Object/
);
});
it
(
'
should throw error when summary is empty
'
,
function
()
{
...
...
@@ -202,7 +204,7 @@ describe('ical-generator', function() {
start
:
new
Date
(),
end
:
new
Date
()
});
},
/event.summary is a mandatory item/
);
},
/event
\
.
summary is a mandatory item/
);
});
it
(
'
should throw error when event.organizer.name is empty
'
,
function
()
{
...
...
@@ -216,7 +218,7 @@ describe('ical-generator', function() {
summary
:
'
hello
'
,
organizer
:
{}
});
},
/event.organizer.name is empty/
);
},
/event
\
.
organizer
\
.
name is empty/
);
});
it
(
'
should throw error when event.organizer.email is empty
'
,
function
()
{
...
...
@@ -232,7 +234,7 @@ describe('ical-generator', function() {
name
:
'
Otto
'
}
});
},
/event.organizer.email is empty/
);
},
/event
\
.
organizer
\
.
email is empty/
);
});
});
...
...
@@ -353,6 +355,62 @@ describe('ical-generator', function() {
});
describe
(
'
serve()
'
,
function
()
{
it
(
'
should work
'
,
function
(
cb
)
{
var
generator
=
require
(
__dirname
+
'
/../lib/ical-generator.js
'
),
portfinder
=
require
(
'
portfinder
'
),
http
=
require
(
'
http
'
),
cal
=
generator
();
cal
.
addEvent
({
start
:
new
Date
(),
end
:
new
Date
(
new
Date
().
getTime
()
+
(
1000
*
60
*
60
)),
summary
:
'
HTTP Calendar Event
'
});
portfinder
.
getPort
(
function
(
err
,
port
)
{
if
(
err
)
{
assert
.
error
(
err
);
cb
();
}
// create server
var
server
=
http
.
createServer
(
function
(
req
,
res
)
{
cal
.
serve
(
res
);
}).
listen
(
port
,
function
()
{
// make request
var
req
=
http
.
request
({
port
:
port
},
function
(
res
)
{
var
file
=
''
;
assert
.
equal
(
res
.
headers
[
'
content-type
'
],
'
text/calendar
'
,
'
Header: text/calendar
'
);
assert
.
equal
(
res
.
headers
[
'
content-disposition
'
],
'
attachment; filename="calendar.ics"
'
,
'
Content-Disposition
'
);
res
.
setEncoding
(
'
utf8
'
);
res
.
on
(
'
data
'
,
function
(
chunk
)
{
file
+=
chunk
;
});
res
.
on
(
'
end
'
,
function
()
{
assert
.
equal
(
file
,
cal
.
toString
());
server
.
close
(
function
()
{
cb
();
});
});
});
req
.
on
(
'
error
'
,
function
(
err
)
{
assert
.
error
(
err
);
});
req
.
end
();
});
});
});
});
describe
(
'
length()
'
,
function
()
{
it
(
'
should work
'
,
function
()
{
var
generator
=
require
(
__dirname
+
'
/../lib/ical-generator.js
'
),
...
...
@@ -364,7 +422,7 @@ describe('ical-generator', function() {
start
:
new
Date
(),
end
:
new
Date
(
new
Date
().
getTime
()
+
3600000
),
summary
:
'
Example Event
'
})
})
;
assert
.
equal
(
cal
.
length
(),
1
);
});
});
...
...
@@ -379,7 +437,7 @@ describe('ical-generator', function() {
start
:
new
Date
(),
end
:
new
Date
(
new
Date
().
getTime
()
+
3600000
),
summary
:
'
Example Event
'
})
})
;
assert
.
equal
(
cal
.
length
(),
1
);
assert
.
deepEqual
(
cal
,
cal
.
clear
());
...
...
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