Skip to content

Commit

Permalink
added 5 tests for DateTime data type #14
Browse files Browse the repository at this point in the history
  • Loading branch information
elf Pavlik committed Jan 28, 2014
1 parent 6f13bad commit 39f260a
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions test/datatype_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"^^<http://www.w3.org/2001/XMLSchema#dateTime>');
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"^^<http://www.w3.org/2001/XMLSchema#dateTime>');
done();
});

});
});
});
});
describe('jsonld.get data type', function() {
Expand Down Expand Up @@ -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"^^<http://www.w3.org/2001/XMLSchema#dateTime>'
};
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"^^<http://www.w3.org/2001/XMLSchema#dateTime>'
};
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();
});
});
});
});

});
});

0 comments on commit 39f260a

Please sign in to comment.