diff --git a/test/datatype_spec.js b/test/datatype_spec.js index 4a8d6c6..06fa0a4 100644 --- a/test/datatype_spec.js +++ b/test/datatype_spec.js @@ -107,6 +107,50 @@ describe('jsonld.put data type', function() { }); }); }); + + it('does preserve date type when defined in context', function(done) { + var example = { + "@context": { + "@vocab": "http://schema.org/", + "startTime": { "@type": "http://www.w3.org/2001/XMLSchema#dateTime" } + }, + "@id": "http://example.net/random-thing", + "@type": "Action", + "startTime": "2014-01-28T12:27:54" + }; + db.jsonld.put(example, function() { + db.get({ + predicate: 'http://schema.org/startTime' + }, function(err, triples) { + expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^'); + done(); + }); + + }); + }); + + it('does preserve date type when defined for given object', function(done) { + var example = { + "@context": { + "@vocab": "http://schema.org/" + }, + "@id": "http://example.net/random-thing", + "@type": "Action", + "startTime": { + "@value": "2014-01-28T12:27:54", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + } + }; + db.jsonld.put(example, function() { + db.get({ + predicate: 'http://schema.org/startTime' + }, function(err, triples) { + expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^'); + done(); + }); + + }); + }); }); }); describe('jsonld.get data type', function() { @@ -237,5 +281,78 @@ describe('jsonld.get data type', function() { }); }); + it('does preserve date', function(done) { + var example = { + "@context": { + "@vocab": "http://schema.org/", + }, + "@id": "http://example.net/random-thing", + "@type": "Action" + }; + var triple = { + subject: example['@id'], + predicate: 'http://schema.org/startTime', + object: '"2014-01-28T12:27:54"^^' + }; + db.jsonld.put(example, function() { + db.put(triple, function() { + db.jsonld.get(example['@id'], example['@context'], function(err, doc) { + expect(doc['startTime']['@type']).to.equal('http://www.w3.org/2001/XMLSchema#dateTime'); + done(); + }); + }); + }); + }); + + //https://github.com/digitalbazaar/jsonld.js/issues/49#issuecomment-31614358 + it('compacts term if value matches type', function(done) { + var example = { + "@context": { + "@vocab": "http://schema.org/", + "startTime": { "@type": "http://www.w3.org/2001/XMLSchema#dateTime" } + }, + "@id": "http://example.net/random-thing", + "@type": "Action" + }; + var triple = { + subject: example['@id'], + predicate: 'http://schema.org/startTime', + object: '"2014-01-28T12:27:54"^^' + }; + db.jsonld.put(example, function() { + db.put(triple, function() { + db.jsonld.get(example['@id'], example['@context'], function(err, doc) { + expect(doc['startTime']).to.equal('2014-01-28T12:27:54'); + done(); + }); + }); + }); + }); + + //https://github.com/digitalbazaar/jsonld.js/issues/49#issuecomment-31614358 + it('does not compact term when value does not have explicit type', function(done) { + var example = { + "@context": { + "@vocab": "http://schema.org/", + "startTime": { "@type": "http://www.w3.org/2001/XMLSchema#dateTime" } + }, + "@id": "http://example.net/random-thing", + "@type": "Action" + }; + var triple = { + subject: example['@id'], + predicate: 'http://schema.org/startTime', + object: '"2014-01-28T12:27:54"' + }; + db.jsonld.put(example, function() { + db.put(triple, function() { + db.jsonld.get(example['@id'], example['@context'], function(err, doc) { + expect(doc['http://schema.org/startTime']).to.equal('2014-01-28T12:27:54'); + done(); + }); + }); + }); + }); + }); });