Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
27bf78f6
Commit
27bf78f6
authored
Apr 28, 2017
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add jio rss feed and opml storage
opml and rss feed are splitted into two differents jio storages
parent
754e5df9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1171 additions
and
1 deletion
+1171
-1
Gruntfile.js
Gruntfile.js
+3
-1
src/jio.storage/opmlstorage.js
src/jio.storage/opmlstorage.js
+176
-0
src/jio.storage/rssfeedstorage.js
src/jio.storage/rssfeedstorage.js
+206
-0
test/jio.storage/opmlstorage.tests.js
test/jio.storage/opmlstorage.tests.js
+409
-0
test/jio.storage/rssfeedstorage.test.js
test/jio.storage/rssfeedstorage.test.js
+375
-0
test/tests.html
test/tests.html
+2
-0
No files found.
Gruntfile.js
View file @
27bf78f6
...
...
@@ -180,7 +180,9 @@ module.exports = function (grunt) {
'
src/jio.storage/localstorage.js
'
,
'
src/jio.storage/indexeddbstorage.js
'
,
'
src/jio.storage/cryptstorage.js
'
,
'
src/jio.storage/websqlstorage.js
'
'
src/jio.storage/websqlstorage.js
'
,
'
src/jio.storage/rssfeedstorage.js
'
,
'
src/jio.storage/opmlstorage.js
'
],
dest
:
'
dist/<%= pkg.name %>-<%= pkg.version %>.js
'
// dest: 'jio.js'
...
...
src/jio.storage/opmlstorage.js
0 → 100644
View file @
27bf78f6
/*
* Copyright 2016, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/*jslint nomen: true*/
/*global jIO, RSVP, DOMParser */
(
function
(
jIO
,
RSVP
,
DOMParser
)
{
"
use strict
"
;
var
dummy
=
{
getAttribute
:
function
()
{
return
;
}};
function
getOpmlOutlineAsDict
(
outline
)
{
var
outline_dict
=
{
title
:
outline
.
getAttribute
(
'
title
'
)
||
''
,
htmlurl
:
outline
.
getAttribute
(
'
htmlUrl
'
)
||
''
,
xmlurl
:
outline
.
getAttribute
(
'
xmlUrl
'
)
||
''
,
url
:
outline
.
getAttribute
(
'
url
'
)
||
''
,
text
:
outline
.
getAttribute
(
'
text
'
)
||
''
,
type
:
outline
.
getAttribute
(
'
type
'
)
||
''
,
version
:
outline
.
getAttribute
(
'
version
'
)
||
''
,
created
:
outline
.
getAttribute
(
'
created
'
)
||
''
,
category
:
outline
.
getAttribute
(
'
category
'
)
||
''
};
return
outline_dict
;
}
function
getOpmlDocumentId
(
outline
)
{
return
outline
.
getAttribute
(
'
url
'
)
||
outline
.
getAttribute
(
'
htmlUrl
'
)
||
outline
.
getAttribute
(
'
xmlUrl
'
)
||
''
;
}
function
getOpmlHeadAsDict
(
doc
)
{
var
element
;
function
getElementsByTagName
(
name
)
{
return
(
doc
.
getElementsByTagName
(
name
)[
0
]
||
dummy
).
textContent
;
}
element
=
{
opml_title
:
getElementsByTagName
(
'
title
'
),
create_date
:
getElementsByTagName
(
'
dateCreated
'
),
modified_date
:
getElementsByTagName
(
'
dateModified
'
),
owner_name
:
getElementsByTagName
(
'
ownerName
'
),
owner_email
:
getElementsByTagName
(
'
ownerEmail
'
),
opml_link
:
getElementsByTagName
(
'
link
'
)
};
return
element
;
}
function
getOpmlElement
(
doc
,
id
)
{
var
outline_list
=
doc
.
getElementsByTagName
(
'
outline
'
),
i
,
max
,
element
=
getOpmlHeadAsDict
(
doc
);
for
(
i
=
0
,
max
=
outline_list
.
length
;
i
<
max
;
i
+=
1
)
{
if
(
outline_list
[
i
].
getAttribute
(
'
htmlUrl
'
)
===
id
||
outline_list
[
i
].
getAttribute
(
'
xmlUrl
'
)
===
id
||
outline_list
[
i
].
getAttribute
(
'
url
'
)
===
id
)
{
Object
.
assign
(
element
,
getOpmlOutlineAsDict
(
outline_list
[
i
]));
break
;
}
}
return
element
;
}
function
getOpmlElementList
(
doc
,
options
)
{
var
i
,
max
,
tmp_id
,
push_method
,
opml_head
=
{},
opml_list
=
[],
outline_list
=
doc
.
getElementsByTagName
(
'
outline
'
);
if
(
options
.
include_docs
===
true
)
{
opml_head
=
getOpmlHeadAsDict
(
doc
);
push_method
=
function
(
id
,
outline
)
{
var
element
=
getOpmlOutlineAsDict
(
outline
);
Object
.
assign
(
element
,
opml_head
);
opml_list
.
push
({
"
id
"
:
id
,
"
value
"
:
{},
"
doc
"
:
element
});
};
}
else
{
push_method
=
function
(
id
)
{
opml_list
.
push
({
"
id
"
:
id
,
"
value
"
:
{}
});
};
}
for
(
i
=
0
,
max
=
outline_list
.
length
;
i
<
max
;
i
+=
1
)
{
if
(
!
outline_list
[
i
].
hasChildNodes
())
{
tmp_id
=
getOpmlDocumentId
(
outline_list
[
i
]);
if
(
tmp_id
!==
''
)
{
push_method
(
tmp_id
,
outline_list
[
i
]);
}
}
}
return
opml_list
;
}
function
parseOpmlFeed
(
feed_url
,
id
,
options
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
feed_url
,
dataType
:
"
text
"
});
})
.
push
(
function
(
response
)
{
var
element
,
result
;
element
=
new
DOMParser
().
parseFromString
(
response
.
target
.
responseText
,
"
text/xml
"
);
if
(
id
!==
undefined
&&
id
!==
null
)
{
result
=
getOpmlElement
(
element
,
id
);
if
(
result
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
result
;
}
if
(
!
options
)
{
options
=
{};
}
return
getOpmlElementList
(
element
,
options
);
},
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
throw
error
;
});
}
/**
* The JIO OPML Storage extension
*
* @class OPMLStorage
* @constructor
*/
function
OPMLStorage
(
spec
)
{
if
(
typeof
spec
.
url
!==
'
string
'
)
{
throw
new
TypeError
(
"
OPMLStorage 'url' is not of type string
"
);
}
this
.
_url
=
spec
.
url
;
}
OPMLStorage
.
prototype
.
get
=
function
(
id
)
{
return
parseOpmlFeed
(
this
.
_url
,
id
);
};
OPMLStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
(
capacity
===
"
list
"
)
||
(
capacity
===
"
include
"
);
};
OPMLStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
return
parseOpmlFeed
(
this
.
_url
,
undefined
,
options
);
};
jIO
.
addStorage
(
'
opml
'
,
OPMLStorage
);
}(
jIO
,
RSVP
,
DOMParser
));
src/jio.storage/rssfeedstorage.js
0 → 100644
View file @
27bf78f6
/*
* Copyright 2016, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/*jslint nomen: true*/
/*global jIO, RSVP, DOMParser */
// JIO Rss Storage Description :
// {
// type: "rss",
// url: {string}
// }
(
function
(
jIO
,
RSVP
,
DOMParser
)
{
"
use strict
"
;
var
dummy
=
{
getAttribute
:
function
()
{
return
;
}};
function
selectElement
(
element
,
selector
)
{
return
(
element
.
querySelector
(
selector
)
||
dummy
);
}
function
getRssHeaderItemDict
(
element
)
{
var
rss_channel
=
element
.
querySelector
(
"
rss > channel
"
),
feed_channel
;
feed_channel
=
{
siteTitle
:
selectElement
(
rss_channel
,
"
title
"
).
textContent
,
reference
:
selectElement
(
rss_channel
,
"
description
"
).
textContent
,
siteLink
:
selectElement
(
rss_channel
,
"
link
"
).
textContent
,
lastBuildDate
:
selectElement
(
rss_channel
,
"
lastBuildDate
"
).
textContent
,
siteGenerator
:
selectElement
(
rss_channel
,
"
generator
"
).
textContent
,
siteDocs
:
selectElement
(
rss_channel
,
"
docs
"
).
textContent
};
return
feed_channel
;
}
function
getFeedItem
(
entry
)
{
var
item
;
item
=
{
link
:
selectElement
(
entry
,
"
link
"
).
textContent
,
date
:
selectElement
(
entry
,
"
pubDate
"
).
textContent
,
title
:
selectElement
(
entry
,
"
title
"
).
textContent
,
author
:
selectElement
(
entry
,
"
author
"
).
textContent
,
category
:
selectElement
(
entry
,
"
category
"
).
textContent
,
comments
:
selectElement
(
entry
,
"
comments
"
).
textContent
,
sourceUrl
:
selectElement
(
entry
,
"
source
"
).
getAttribute
(
'
url
'
),
source
:
selectElement
(
entry
,
"
source
"
).
textContent
,
description
:
selectElement
(
entry
,
"
description
"
).
textContent
,
guid
:
selectElement
(
entry
,
"
guid
"
).
textContent
};
return
item
;
}
function
getRssFeedEntry
(
element
,
id
)
{
var
item
,
rss_guid_list
,
i
;
if
(
id
!==
undefined
&&
id
!==
null
)
{
rss_guid_list
=
element
.
querySelectorAll
(
"
rss>channel>item>guid
"
);
for
(
i
=
0
;
i
<
rss_guid_list
.
length
;
i
+=
1
)
{
if
(
rss_guid_list
[
i
].
textContent
===
id
)
{
item
=
getFeedItem
(
rss_guid_list
[
i
].
parentNode
);
Object
.
assign
(
item
,
getRssHeaderItemDict
(
element
));
break
;
}
}
}
return
item
;
}
function
getRssFeedEntryList
(
element
,
options
)
{
var
rss_entry_list
,
item_list
=
[],
push_method
,
feed_channel
;
if
(
options
.
include_docs
===
true
)
{
feed_channel
=
getRssHeaderItemDict
(
element
);
push_method
=
function
(
id
,
entry
)
{
var
item
;
if
(
!
id
)
{
return
;
}
item
=
getFeedItem
(
entry
);
Object
.
assign
(
item
,
feed_channel
);
item_list
.
push
({
"
id
"
:
id
,
"
value
"
:
{},
"
doc
"
:
item
});
};
}
else
{
push_method
=
function
(
id
)
{
if
(
!
id
)
{
return
;
}
item_list
.
push
({
"
id
"
:
id
,
"
value
"
:
{}
});
};
}
rss_entry_list
=
element
.
querySelectorAll
(
"
rss > channel > item
"
);
[].
forEach
.
call
(
rss_entry_list
,
function
(
entry
)
{
push_method
(
selectElement
(
entry
,
"
guid
"
).
textContent
,
entry
);
});
return
item_list
;
}
function
parseRssFeed
(
feed_url
,
id
,
options
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
feed_url
,
dataType
:
"
text
"
});
})
.
push
(
function
(
response
)
{
var
element
,
item
;
element
=
new
DOMParser
().
parseFromString
(
response
.
target
.
responseText
,
"
text/xml
"
);
if
(
id
!==
undefined
&&
id
!==
null
)
{
item
=
getRssFeedEntry
(
element
,
id
);
if
(
item
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
item
;
}
if
(
!
options
)
{
options
=
{};
}
return
getRssFeedEntryList
(
element
,
options
);
},
function
(
error
)
{
if
((
error
.
target
!==
undefined
)
&&
(
error
.
target
.
status
===
404
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
throw
error
;
});
}
/**
* The JIO RSSStorage Storage extension
*
* @class RSSStorage
* @constructor
*/
function
RSSStorage
(
spec
)
{
if
(
typeof
spec
.
url
!==
'
string
'
)
{
throw
new
TypeError
(
"
RSSStorage 'url' is not of type string
"
);
}
this
.
_url
=
spec
.
url
;
}
RSSStorage
.
prototype
.
get
=
function
(
id
)
{
return
parseRssFeed
(
this
.
_url
,
id
);
};
RSSStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
(
capacity
===
"
list
"
)
||
(
capacity
===
'
include
'
);
};
RSSStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
return
parseRssFeed
(
this
.
_url
,
undefined
,
options
);
};
jIO
.
addStorage
(
'
rss
'
,
RSSStorage
);
}(
jIO
,
RSVP
,
DOMParser
));
test/jio.storage/opmlstorage.tests.js
0 → 100644
View file @
27bf78f6
/*jslint nomen: true */
/*global jIO, QUnit, sinon*/
(
function
(
jIO
,
QUnit
,
sinon
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
ok
=
QUnit
.
ok
,
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
,
domain
=
"
http://opml.example.com
"
,
opml_url
=
domain
+
"
/opml.xml
"
;
/////////////////////////////////////////////////////////////////
// Opml constructor
/////////////////////////////////////////////////////////////////
module
(
"
OPMLStorage.constructor
"
);
test
(
"
Storage store URL
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
'
opml
'
,
url
:
opml_url
});
deepEqual
(
jio
.
__storage
.
_url
,
opml_url
);
});
/////////////////////////////////////////////////////////////////
// OPMLStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
OPMLStorage.get
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
jio
=
jIO
.
createJIO
({
type
:
'
opml
'
,
url
:
opml_url
});
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
get inexistent document
"
,
function
()
{
this
.
server
.
respondWith
(
"
GET
"
,
opml_url
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
"
foo
"
]);
stop
();
expect
(
3
);
this
.
jio
.
get
(
'
nofounditem
'
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get document
"
,
function
()
{
var
id
=
"
http://opml.example.com/feeds/syndication.xml
"
,
expected_dict
=
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Syndication News
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/syndication.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
};
this
.
server
.
respondWith
(
"
GET
"
,
opml_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="ISO-8859-1"?>
'
+
'
<opml version="1.0">
'
+
'
<head>
'
+
'
<title>feedOnFeeds.xml</title>
'
+
'
<dateCreated>Thu, 12 Sep 2003 23:35:52 GMT</dateCreated>
'
+
'
<dateModified>Fri, 12 Sep 2003 23:45:37 GMT</dateModified>
'
+
'
<ownerName>SomeUser</ownerName>
'
+
'
<ownerEmail>newsfor@example.com</ownerEmail>
'
+
'
<link>http://opml.example.com/opml.xml</link>
'
+
'
</head>
'
+
'
<body>
'
+
'
<outline text="Sample OPML">
'
+
'
<outline text="Mobile News" type="link" url="http://opml.example.
'
+
'
com/feeds/mobile.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Syndication News" type="link" url="http://opml.examp
'
+
'
le.com/feeds/syndication.xml" dateCreated="Thu, 12 Sep 2003 23:35:52
'
+
'
GMT"/>
'
+
'
</outline>
'
+
'
<outline text="World News">
'
+
'
<outline text="Politics" type="link" url="http://opml.example.com/
'
+
'
feeds/politics.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Sports" type="link" url="http://opml.example.com/fee
'
+
'
ds/sports.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
</outline>
'
+
'
<outline text="Various">
'
+
'
<outline text="Weather" type="link" url="http://opml.example.com/fe
'
+
'
eds/weather.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Entertainment" type="link" url="http://opml.example.
'
+
'
com/feeds/ent.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
</outline>
'
+
'
</body>
'
+
'
</opml>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
get
(
id
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// OPMLStorage.allDocs
/////////////////////////////////////////////////////////////////
module
(
"
OPMLStorage.allDocs
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
jio
=
jIO
.
createJIO
({
type
:
'
opml
'
,
url
:
opml_url
});
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
get all document with include_docs false
"
,
function
()
{
var
expected_dict
=
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
http://opml.example.com/feeds/mobile.xml
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
http://opml.example.com/feeds/syndication.xml
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
}
};
this
.
server
.
respondWith
(
"
GET
"
,
opml_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="ISO-8859-1"?>
'
+
'
<opml version="1.0">
'
+
'
<head>
'
+
'
<title>feedOnFeeds.xml</title>
'
+
'
<dateCreated>Thu, 12 Sep 2003 23:35:52 GMT</dateCreated>
'
+
'
<dateModified>Fri, 12 Sep 2003 23:45:37 GMT</dateModified>
'
+
'
<ownerName>SomeUser</ownerName>
'
+
'
<ownerEmail>newsfor@example.com</ownerEmail>
'
+
'
<link>http://opml.example.com/opml.xml</link>
'
+
'
</head>
'
+
'
<body>
'
+
'
<outline text="Sample OPML">
'
+
'
<outline text="Mobile News" type="link" url="http://opml.example.
'
+
'
com/feeds/mobile.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Syndication News" type="link" url="http://opml.examp
'
+
'
le.com/feeds/syndication.xml" dateCreated="Thu, 12 Sep 2003 23:35:52
'
+
'
GMT"/>
'
+
'
</outline>
'
+
'
</body>
'
+
'
</opml>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
allDocs
({
include_docs
:
false
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get all documents
"
,
function
()
{
var
expected_dict
=
{
"
data
"
:
{
"
rows
"
:
[
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Mobile News
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/mobile.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/mobile.xml
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Syndication News
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/syndication.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/syndication.xml
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Politics
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/politics.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/politics.xml
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Sports
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/sports.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/sports.xml
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Weather
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/weather.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/weather.xml
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
category
"
:
""
,
"
create_date
"
:
"
Thu, 12 Sep 2003 23:35:52 GMT
"
,
"
created
"
:
""
,
"
htmlurl
"
:
""
,
"
modified_date
"
:
"
Fri, 12 Sep 2003 23:45:37 GMT
"
,
"
opml_link
"
:
"
http://opml.example.com/opml.xml
"
,
"
opml_title
"
:
"
feedOnFeeds.xml
"
,
"
owner_email
"
:
"
newsfor@example.com
"
,
"
owner_name
"
:
"
SomeUser
"
,
"
text
"
:
"
Entertainment
"
,
"
title
"
:
""
,
"
type
"
:
"
link
"
,
"
url
"
:
"
http://opml.example.com/feeds/ent.xml
"
,
"
version
"
:
""
,
"
xmlurl
"
:
""
},
"
id
"
:
"
http://opml.example.com/feeds/ent.xml
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
6
}
};
this
.
server
.
respondWith
(
"
GET
"
,
opml_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="ISO-8859-1"?>
'
+
'
<opml version="1.0">
'
+
'
<head>
'
+
'
<title>feedOnFeeds.xml</title>
'
+
'
<dateCreated>Thu, 12 Sep 2003 23:35:52 GMT</dateCreated>
'
+
'
<dateModified>Fri, 12 Sep 2003 23:45:37 GMT</dateModified>
'
+
'
<ownerName>SomeUser</ownerName>
'
+
'
<ownerEmail>newsfor@example.com</ownerEmail>
'
+
'
<link>http://opml.example.com/opml.xml</link>
'
+
'
</head>
'
+
'
<body>
'
+
'
<outline text="Sample OPML">
'
+
'
<outline text="Mobile News" type="link" url="http://opml.example.
'
+
'
com/feeds/mobile.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Syndication News" type="link" url="http://opml.examp
'
+
'
le.com/feeds/syndication.xml" dateCreated="Thu, 12 Sep 2003 23:35:52
'
+
'
GMT"/>
'
+
'
</outline>
'
+
'
<outline text="World News">
'
+
'
<outline text="Politics" type="link" url="http://opml.example.com/
'
+
'
feeds/politics.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Sports" type="link" url="http://opml.example.com/fee
'
+
'
ds/sports.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
</outline>
'
+
'
<outline text="Various">
'
+
'
<outline text="Weather" type="link" url="http://opml.example.com/fe
'
+
'
eds/weather.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
<outline text="Entertainment" type="link" url="http://opml.example.
'
+
'
com/feeds/ent.xml" dateCreated="Thu, 12 Sep 2003 23:35:52 GMT"/>
'
+
'
</outline>
'
+
'
</body>
'
+
'
</opml>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
allDocs
({
include_docs
:
true
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check documents
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
sinon
));
\ No newline at end of file
test/jio.storage/rssfeedstorage.test.js
0 → 100644
View file @
27bf78f6
/*jslint nomen: true */
/*global jIO, QUnit, sinon*/
(
function
(
jIO
,
QUnit
,
sinon
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
ok
=
QUnit
.
ok
,
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
,
domain
=
"
https://example.org
"
,
feed_url
=
domain
+
"
/feed.xml
"
;
/////////////////////////////////////////////////////////////////
// Feed constructor
/////////////////////////////////////////////////////////////////
module
(
"
RSSStorage.constructor
"
);
test
(
"
Storage store URL
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
'
rss
'
,
url
:
feed_url
});
deepEqual
(
jio
.
__storage
.
_url
,
feed_url
);
});
/////////////////////////////////////////////////////////////////
// RSSStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
RSSStorage.get
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
jio
=
jIO
.
createJIO
({
type
:
'
rss
'
,
url
:
feed_url
});
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
get inexistent document
"
,
function
()
{
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
"
foo
"
]);
stop
();
expect
(
3
);
this
.
jio
.
get
(
'
nofounditem
'
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get inexistent rss entry
"
,
function
()
{
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
404
,
{
"
Content-Type
"
:
"
text/html
"
},
'
<?xml version="1.0" encoding="UTF-8" ?>
'
+
'
<rss version="2.0">
'
+
'
<channel>
'
+
'
<title>RSS Example</title>
'
+
'
<description>This is an example of an RSS feed</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is an example of an Item</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<guid isPermaLink="false">1102345</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
</channel>
'
+
'
</rss>
'
]);
stop
();
expect
(
3
);
this
.
jio
.
get
(
'
BAD_RSS_GUID
'
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get document
"
,
function
()
{
var
id
=
"
1102345
"
,
expected_dict
=
{
"
author
"
:
undefined
,
"
category
"
:
undefined
,
"
comments
"
:
undefined
,
"
date
"
:
"
Tue, 29 Aug 2006 09:00:00 -0400
"
,
"
description
"
:
"
This is an example of an Item
"
,
"
guid
"
:
"
1102345
"
,
"
lastBuildDate
"
:
"
Mon, 28 Aug 2006 11:12:55 -0400
"
,
"
link
"
:
"
http://www.domain.com/link.htm
"
,
"
reference
"
:
"
This is an example of an RSS feed
"
,
"
siteDocs
"
:
undefined
,
"
siteGenerator
"
:
undefined
,
"
siteLink
"
:
"
http://www.domain.com/link.htm
"
,
"
siteTitle
"
:
"
RSS Example
"
,
"
source
"
:
undefined
,
"
sourceUrl
"
:
undefined
,
"
title
"
:
"
Item Example
"
};
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="UTF-8" ?>
'
+
'
<rss version="2.0">
'
+
'
<channel>
'
+
'
<title>RSS Example</title>
'
+
'
<description>This is an example of an RSS feed</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is an example of an Item</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<guid isPermaLink="false">1102345</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is another example of an Item</description>
'
+
'
<link>http://www.domain.com/link2.htm</link>
'
+
'
<guid isPermaLink="false">11023-258</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
</channel>
'
+
'
</rss>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
get
(
id
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// RSSStorage.allDocs
/////////////////////////////////////////////////////////////////
module
(
"
RSSStorage.allDocs
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
jio
=
jIO
.
createJIO
({
type
:
'
rss
'
,
url
:
feed_url
});
},
teardown
:
function
()
{
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
empty documents
"
,
function
()
{
var
expected_dict
=
{
"
data
"
:
{
"
rows
"
:
[],
"
total_rows
"
:
0
}
};
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
'
<?xml version="1.0" encoding="UTF-8" ?>
'
+
'
<rss version="2.0">
'
+
'
<channel>
'
+
'
</channel>
'
+
'
</rss>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
allDocs
()
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check documents
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get all documents
"
,
function
()
{
var
expected_dict
=
{
"
data
"
:
{
"
rows
"
:
[
{
"
doc
"
:
{
"
author
"
:
undefined
,
"
category
"
:
undefined
,
"
comments
"
:
undefined
,
"
date
"
:
"
Tue, 29 Aug 2006 09:00:00 -0400
"
,
"
description
"
:
"
This is an example of an Item
"
,
"
guid
"
:
"
1102345
"
,
"
lastBuildDate
"
:
"
Mon, 28 Aug 2006 11:12:55 -0400
"
,
"
link
"
:
"
http://www.domain.com/link.htm
"
,
"
reference
"
:
"
This is an example of an RSS feed
"
,
"
siteDocs
"
:
undefined
,
"
siteGenerator
"
:
undefined
,
"
siteLink
"
:
"
http://www.domain.com/link.htm
"
,
"
siteTitle
"
:
"
RSS Example
"
,
"
source
"
:
undefined
,
"
sourceUrl
"
:
undefined
,
"
title
"
:
"
Item Example
"
},
"
id
"
:
"
1102345
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
author
"
:
undefined
,
"
category
"
:
undefined
,
"
comments
"
:
undefined
,
"
date
"
:
"
Tue, 29 Aug 2006 09:00:00 -0400
"
,
"
description
"
:
"
This is another example of an Item
"
,
"
guid
"
:
"
11023-258
"
,
"
lastBuildDate
"
:
"
Mon, 28 Aug 2006 11:12:55 -0400
"
,
"
link
"
:
"
http://www.domain.com/link2.htm
"
,
"
reference
"
:
"
This is an example of an RSS feed
"
,
"
siteDocs
"
:
undefined
,
"
siteGenerator
"
:
undefined
,
"
siteLink
"
:
"
http://www.domain.com/link.htm
"
,
"
siteTitle
"
:
"
RSS Example
"
,
"
source
"
:
undefined
,
"
sourceUrl
"
:
undefined
,
"
title
"
:
"
Item Example
"
},
"
id
"
:
"
11023-258
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
}
};
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="UTF-8" ?>
'
+
'
<rss version="2.0">
'
+
'
<channel>
'
+
'
<title>RSS Example</title>
'
+
'
<description>This is an example of an RSS feed</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is an example of an Item</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<guid isPermaLink="false">1102345</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is another example of an Item</description>
'
+
'
<link>http://www.domain.com/link2.htm</link>
'
+
'
<guid isPermaLink="false">11023-258</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
</channel>
'
+
'
</rss>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
allDocs
({
include_docs
:
true
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check documents
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get all documents with include_docs false
"
,
function
()
{
var
expected_dict
=
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
1102345
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
1
}
};
this
.
server
.
respondWith
(
"
GET
"
,
feed_url
,
[
200
,
{
"
Content-Type
"
:
"
text/xml
"
},
'
<?xml version="1.0" encoding="UTF-8" ?>
'
+
'
<rss version="2.0">
'
+
'
<channel>
'
+
'
<title>RSS Example</title>
'
+
'
<description>This is an example of an RSS feed</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
<item>
'
+
'
<title>Item Example</title>
'
+
'
<description>This is an example of an Item</description>
'
+
'
<link>http://www.domain.com/link.htm</link>
'
+
'
<guid isPermaLink="false">1102345</guid>
'
+
'
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
'
+
'
</item>
'
+
'
</channel>
'
+
'
</rss>
'
]);
stop
();
expect
(
1
);
this
.
jio
.
allDocs
()
.
then
(
function
(
result
)
{
deepEqual
(
result
,
expected_dict
,
"
Check documents
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
sinon
));
\ No newline at end of file
test/tests.html
View file @
27bf78f6
...
...
@@ -41,6 +41,8 @@
<script
src=
"jio.storage/uuidstorage.tests.js"
></script>
<script
src=
"jio.storage/replicatestorage.tests.js"
></script>
<script
src=
"jio.storage/shastorage.tests.js"
></script>
<script
src=
"jio.storage/rssfeedstorage.test.js"
></script>
<script
src=
"jio.storage/opmlstorage.tests.js"
></script>
<!--script src="jio.storage/qiniustorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
...
...
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