@@ -7,6 +7,7 @@ const hyperdb = require('hyperdb')
77
88const hypergraph = require ( '../index' )
99const constants = require ( '../lib/constants' )
10+ const prefixes = require ( '../lib/prefixes' )
1011
1112function ramStore ( filename ) {
1213 // filename will be one of: data, bitfield, tree, signatures, key, secret_key
@@ -72,11 +73,44 @@ describe('hypergraph', function () {
7273 db = hypergraph ( ramStore )
7374 db . on ( 'ready' , ( ) => {
7475 const stream = db . db . createReadStream ( '@prefix/' )
76+ var count = 0
7577 stream . on ( 'data' , ( nodes ) => {
76- // add test
78+ const prefix = prefixes . fromKey ( nodes [ 0 ] . key )
79+ count ++
80+ expect ( nodes [ 0 ] . value . toString ( ) ) . to . eql ( constants . DEFAULT_PREFIXES [ prefix ] )
7781 } )
7882 stream . on ( 'error' , done )
7983 stream . on ( 'end' , ( ) => {
84+ expect ( count ) . to . eql ( Object . keys ( constants . DEFAULT_PREFIXES ) . length )
85+ done ( )
86+ } )
87+ } )
88+ } )
89+ it ( 'includes only specified prefixes (options.prefixes)' , ( done ) => {
90+ var customPrefixes = {
91+ schema : 'http://schema.org/' ,
92+ library : 'http://purl.org/library/' ,
93+ void : 'http://rdfs.org/ns/void#' ,
94+ dct : 'http://purl.org/dc/terms/' ,
95+ rdf : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' ,
96+ madsrdf : 'http://www.loc.gov/mads/rdf/v1#' ,
97+ discovery : 'http://worldcat.org/vocab/discovery/' ,
98+ bgn : 'http://bibliograph.net/' ,
99+ pto : 'http://www.productontology.org/id/' ,
100+ dc : 'http://purl.org/dc/elements/1.1/'
101+ }
102+ db = hypergraph ( ramStore , { prefixes : customPrefixes } )
103+ db . on ( 'ready' , ( ) => {
104+ const stream = db . db . createReadStream ( '@prefix/' )
105+ var count = 0
106+ stream . on ( 'data' , ( nodes ) => {
107+ const prefix = prefixes . fromKey ( nodes [ 0 ] . key )
108+ count ++
109+ expect ( nodes [ 0 ] . value . toString ( ) ) . to . eql ( customPrefixes [ prefix ] )
110+ } )
111+ stream . on ( 'error' , done )
112+ stream . on ( 'end' , ( ) => {
113+ expect ( count ) . to . eql ( Object . keys ( customPrefixes ) . length )
80114 done ( )
81115 } )
82116 } )
0 commit comments