Skip to content

Commit f3ff315

Browse files
authored
Merge pull request #8 from Cheukting/dev
Update some tests and fix #7
2 parents ce2f2b5 + 15a4114 commit f3ff315

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

lib/woql.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ WOQL.insert = function(Node, Type, Graph){
9393
}
9494

9595
WOQL.doctype = function(Type, Graph){
96-
return new WOQLQuery().add_class(Type, Graph).parent("Document");
96+
return new WOQLQuery().add_class(Type, Graph).parent("Document");
9797
}
9898

9999

@@ -212,7 +212,7 @@ WOQLQuery.prototype.order_by = function(gvarlist, asc_or_desc, query){
212212
const vars = UTILS.addNamespacesToVariables(ordering);
213213
asc_or_desc = asc_or_desc || "asc";
214214
ordering = {};
215-
ordering[asc_or_desc] = vars;
215+
ordering[asc_or_desc] = vars;
216216
}
217217
this.advanceCursor("order_by", ordering);
218218
if(query){
@@ -807,7 +807,7 @@ WOQLQuery.prototype.property = function(p,val){
807807
var nwoql = WOQL.add_property(p, val).domain(this.adding_class);
808808
nwoql.query.and.push(this.json());
809809
nwoql.adding_class = this.adding_class;
810-
return nwoql;
810+
return nwoql;
811811
}
812812
else {
813813
p = this.cleanPredicate(p);
@@ -816,7 +816,7 @@ WOQLQuery.prototype.property = function(p,val){
816816
}
817817
return this;
818818
}
819-
819+
820820
WOQLQuery.prototype.star = function(GraphIRI, Subj, Pred, Obj){
821821
Subj = (Subj ? this.cleanSubject(Subj) : "v:Subject");
822822
Pred = (Pred ? this.cleanPredicate(Pred) : "v:Predicate");
@@ -826,12 +826,12 @@ WOQLQuery.prototype.star = function(GraphIRI, Subj, Pred, Obj){
826826
return this.quad(Subj, Pred, Obj, GraphIRI);
827827
}
828828
else {
829-
console.log(Subj, Pred, Obj);
829+
//console.log(Subj, Pred, Obj);
830830
return this.triple(Subj, Pred, Obj);
831831
}
832832
}
833833

834-
/**
834+
/**
835835
* These are composite functions, the above are primitives
836836
*/
837837
WOQLQuery.prototype.getEverything = function(GraphIRI){
@@ -985,7 +985,7 @@ WOQLQuery.prototype.loadVocabulary = function(client){
985985
if(typeof v == "string"){
986986
var spl = v.split(":");
987987
if(spl.length == 2 && spl[1] && spl[0] != "_"){
988-
this.vocab[spl[1]] = v;
988+
this.vocab[spl[0]] = spl[1];
989989
}
990990
}
991991
}

test/woql.spec.js

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,37 @@ describe('woql queries', function () {
1313
expect(woqlObject.vocab.type).to.equal('rdf:type');
1414
})
1515

16+
it('check the insert method',function(){
17+
18+
const woqlObject=WOQL.insert("v:Bike_URL", "Bicycle");
19+
const woqlObjectDB=WOQL.insert("v:Bike_URL", "Bicycle", "myDB");
20+
const jsonObj={ "add_triple": [ 'v:Bike_URL', 'rdf:type', 'scm:Bicycle' ] };
21+
const jsonObjDB={ "add_quad": [ 'v:Bike_URL', 'rdf:type', 'scm:Bicycle', 'db:myDB' ] };
22+
expect(woqlObject.json()).to.eql(jsonObj);
23+
expect(woqlObjectDB.json()).to.eql(jsonObjDB);
24+
})
25+
26+
it('check the doctype method',function(){
27+
28+
const woqlObject=WOQL.doctype("Station");
29+
30+
const jsonObj={ "and": [
31+
{ "add_quad": ["scm:Station",
32+
"rdf:type",
33+
"owl:Class",
34+
"db:schema"] },
35+
{ "add_quad": ["scm:Station",
36+
"rdfs:subClassOf",
37+
"tcs:Document",
38+
"db:schema"] }
39+
] }
40+
41+
expect(woqlObject.json()).to.eql(jsonObj);
42+
43+
})
1644

1745
it('check the limit method',function(){
18-
const woqlObject=WOQL.limit(10);
46+
const woqlObject=WOQL.limit(10);
1947

2048
expect(woqlObject.json().limit[0]).to.equal(10);
2149

@@ -86,7 +114,7 @@ describe('woql queries', function () {
86114
]
87115
};
88116

89-
//expect(woqlObject.json()).to.eql(jsonObj);
117+
expect(woqlObject.json()).to.eql(jsonObj);
90118
expect(woqlObjectChain.json()).to.eql(jsonObj);
91119

92120
})
@@ -111,7 +139,7 @@ describe('woql queries', function () {
111139

112140
const woqlObjectChain=WOQL.from("http://dburl").limit(10);
113141

114-
const jsonObj={ from: [ 'http://dburl', { limit: [ 10, {} ] } ] }
142+
const jsonObj={ "from": [ 'http://dburl', { "limit": [ 10, {} ] } ] }
115143

116144
//expect(woqlObject.json()).to.eql(jsonObj);
117145
expect(woqlObjectChain.json()).to.eql(jsonObj);
@@ -122,7 +150,7 @@ describe('woql queries', function () {
122150

123151
const woqlObject=WOQL.limit(10).star();
124152

125-
const jsonObj={ limit: [ 10, { "triple": [
153+
const jsonObj={ "limit": [ 10, { "triple": [
126154
"v:Subject",
127155
"v:Predicate",
128156
"v:Object"
@@ -283,6 +311,17 @@ describe('woql queries', function () {
283311

284312
})
285313

314+
it('check the cast method',function(){
315+
316+
const woqlObject=WOQL.cast("v:Duration", "xsd:integer", "v:Duration_Cast");
317+
318+
const jsonObj={ "typecast": [ "v:Duration", "xsd:integer", "v:Duration_Cast" ] }
319+
320+
expect(woqlObject.json()).to.eql(jsonObj);
321+
322+
})
323+
324+
286325
it('check the list method',function(){
287326

288327
const woqlObject=WOQL.list(["V1","V2"]);
@@ -682,13 +721,13 @@ describe('triple builder chaining methods', function () {
682721
{ add_triple: ["v:Node_ID", "rdfs:subClassOf", "tcs:Entity"] },
683722
{ add_triple: ["v:Node_ID", "rdfs:subClassOf", "scm:hello"] }
684723
]};
685-
expect(woqlObject.json()).to.eql(jsonObj);
724+
expect(woqlObject.json()).to.eql(jsonObj);
686725
})
687726
it('check the chained doctype method',function(){
688727
const woqlObject = WOQL.doctype("MyDoc")
689728
.property("prop", "dateTime")
690729
.property("prop2", "integer")
691-
730+
692731
const jsonObj={ and: [
693732
{ add_quad: ["scm:prop2", "rdf:type", "owl:DatatypeProperty", "db:schema"] },
694733
{ add_quad: ["scm:prop2", "rdfs:range", "xsd:integer", "db:schema"] },
@@ -702,10 +741,9 @@ describe('triple builder chaining methods', function () {
702741
{ add_quad: ["scm:MyDoc", "rdf:type", "owl:Class", "db:schema"] },
703742
{ add_quad: ["scm:MyDoc", "rdfs:subClassOf", "tcs:Document", "db:schema"] }
704743
]}
705-
]},
744+
]},
706745
]};
707-
expect(woqlObject.json()).to.eql(jsonObj);
746+
expect(woqlObject.json()).to.eql(jsonObj);
708747
})
709748

710749
})
711-

test/woqlQuery.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,13 @@ describe('pre-roll queries', function () {
442442

443443
describe('woql query object', function () {
444444

445-
it('check the setVocabulary method',function(){
445+
it('check the setVocabulary and getVocabulary method',function(){
446446
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
447447

448448
const woqlObject=WOQL.limit(2).start(0);
449449
woqlObject.setVocabulary("vocab");
450-
//console.log(woqlObject.getAllDocuments().json());
451-
//done();
452-
//expect(woqlObject.setVocabulary("vocab")).to.eql(jsonObj);
450+
451+
expect(woqlObject.getVocabulary()).to.eql("vocab");
453452

454453
})
455454

0 commit comments

Comments
 (0)