Skip to content

Commit

Permalink
handle invalid google-dataset annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH committed Sep 24, 2024
1 parent 2a7947b commit dad1777
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 15 deletions.
6 changes: 5 additions & 1 deletion js/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3950,7 +3950,11 @@
this._googleDatasetMetadata = null;
} else {
var metadataAnnotation = module._getRecursiveAnnotationValue(this._context, this._table.annotations.get(module._annotations.GOOGLE_DATASET_METADATA).content);
this._googleDatasetMetadata = new GoogleDatasetMetadata(this, metadataAnnotation);
if (!isObjectAndNotNull(metadataAnnotation) || !isObjectAndNotNull(metadataAnnotation.dataset)) {
this._googleDatasetMetadata = null;
} else {
this._googleDatasetMetadata = new GoogleDatasetMetadata(this, metadataAnnotation);
}
}
}
return this._googleDatasetMetadata;
Expand Down
153 changes: 152 additions & 1 deletion test/specs/json_ld/conf/google_metadata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,157 @@
}
}
}
},
"missing_google_metadata": {
"kind": "table",
"table_name": "missing_google_metadata",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
]
},
"invalid_google_metadata_1": {
"kind": "table",
"table_name": "invalid_google_metadata_1",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2021:google-dataset": null
}
},
"invalid_google_metadata_2": {
"kind": "table",
"table_name": "invalid_google_metadata_2",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2021:google-dataset": {}
}
},
"invalid_google_metadata_3": {
"kind": "table",
"table_name": "invalid_google_metadata_3",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2021:google-dataset": {
"detailed": null
}
}
},
"invalid_google_metadata_4": {
"kind": "table",
"table_name": "invalid_google_metadata_4",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2021:google-dataset": {
"detailed": {
"some_invalid_prop": "test"
}
}
}
},
"invalid_google_metadata_5": {
"kind": "table",
"table_name": "invalid_google_metadata_5",
"schema_name": "google_metadata_schema",
"keys": [
{
"unique_columns": [
"id"
]
}
],
"column_definitions": [
{
"name": "id",
"nullok": false,
"type": {
"typename": "integer"
}
}
],
"annotations": {
"tag:isrd.isi.edu,2021:google-dataset": {
"detailed": {
"dataset": "test"
}
}
}
}
}
}
}
28 changes: 24 additions & 4 deletions test/specs/json_ld/tests/01.reference_google_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ exports.execute = function (options) {
schemaName = "google_metadata_schema",
tableName = "google_metadata_w_handlebars";

var handlebarsGoogleMetadataUri = options.url + "/catalog/" + catalog_id + "/entity/" + schemaName + ":" + tableName + "/@sort(id)";

var chaiseURL = "https://example.org/chaise";
var recordURL = chaiseURL + "/record";
var record2URL = chaiseURL + "/record-two";
Expand Down Expand Up @@ -46,17 +44,39 @@ exports.execute = function (options) {
return url;
};

const getURL = (tName) => {
return options.url + "/catalog/" + catalog_id + "/entity/" + schemaName + ":" + tName + "/@sort(id)";
}

const resolveReference = async (tName) => {
return options.ermRest.resolve(getURL(tName), { cid: "test" });
}

beforeAll(function () {
options.ermRest.appLinkFn(appLinkFn);
});

it('googleDatasetMetadata.compute should handle tables without any google-dataset annotation or invalid ones', async () => {
const expectNull = async (tName) => {
const ref = await resolveReference(tName);
expect(ref.contextualize.detailed.googleDatasetMetadata).toBeNull();
};

expectNull('missing_google_metadata');
expectNull('invalid_google_metadata_1');
expectNull('invalid_google_metadata_2');
expectNull('invalid_google_metadata_3');
expectNull('invalid_google_metadata_4');
expectNull('invalid_google_metadata_5');
});

describe("with handlebar templating", function () {
var tuples, tuple, reference;

beforeAll(function (done) {
options.ermRest.resolve(handlebarsGoogleMetadataUri, { cid: "test" }).then(function (response) {
resolveReference(tableName).then(function (response) {
reference = response.contextualize.detailed;
return response.read(2);
return reference.read(2);
}).then(function (response) {
tuples = response.tuples;
done();
Expand Down
18 changes: 9 additions & 9 deletions test/specs/json_ld/tests/02.json_ld_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports.execute = function (options) {
var module = options.includes.ermRest;
describe("validation of structured data", function () {
it("should ignore attributes that are not part of the vocabulary", function (done) {
var jsonInput = {"@type": "Dataset","@context": "http://schema.org","name": "dummy",
var jsonInput = {"@type": "Dataset","@context": "http://schema.org","name": "dummy",
"description": "lorem ipsum", "verson": "4"};
expect(jsonInput.verson).toEqual("4");

Expand All @@ -16,7 +16,7 @@ exports.execute = function (options) {
});

it("should return false if missing @context", function (done) {
var jsonInput = {"@type": "Dataset","name": "dummy",
var jsonInput = {"@type": "Dataset","name": "dummy",
"description": "lorem ipsum"};
expect(jsonInput["@context"]).toEqual(undefined);

Expand All @@ -29,7 +29,7 @@ exports.execute = function (options) {
});

it("should return false if incorrect @type", function (done) {
var jsonInput = {"@type": "Datass","@context": "http://schema.org","name": "dummy",
var jsonInput = {"@type": "Datass","@context": "http://schema.org","name": "dummy",
"description": "lorem ipsum"};
expect(jsonInput["@type"]).toEqual("Datass");

Expand All @@ -52,11 +52,11 @@ exports.execute = function (options) {
}
};
expect(jsonInput["creator"]["name"]).toEqual(undefined);
expect(jsonInput["creator"]).toBeObject();
expect(jsonInput["creator"]).toBeTruthy();

var result = module.validateJSONLD(jsonInput);
expect(result.isValid).toEqual(true);
expect(result.modifiedJsonLd["creator"]).not.toBeObject();
expect(result.modifiedJsonLd["creator"]).not.toBeTruthy();
delete jsonInput["creator"];
expect(result.modifiedJsonLd).toEqual(jsonInput);
done();
Expand All @@ -72,7 +72,7 @@ exports.execute = function (options) {
});

it("should ignore attribute if datatype not followed", function (done) {
var jsonInput = {"@type": "Dataset","@context": "http://schema.org","name": "dummy",
var jsonInput = {"@type": "Dataset","@context": "http://schema.org","name": "dummy",
"description": "lorem ipsum", "url": 77};
expect(jsonInput["url"]).toEqual(77);

Expand All @@ -87,7 +87,7 @@ exports.execute = function (options) {
it("The google_metadata with incorrect element(incorrect data type) inside array returned with that element excluded", function (done) {
var jsonInput = {
"@type": "Dataset", "@context": "http://schema.org", "name": "dummy",
"description": "lorem ipsum",
"description": "lorem ipsum",
"keywords": ["sales",
"ice cream",
"ice cream brands",
Expand Down Expand Up @@ -118,7 +118,7 @@ exports.execute = function (options) {
it("The google_metadata with incorrect element(null) inside array returned with that element excluded", function (done) {
var jsonInput = {
"@type": "Dataset", "@context": "http://schema.org", "name": "dummy",
"description": "lorem ipsum",
"description": "lorem ipsum",
"keywords": ["sales",
"ice cream",
"ice cream brands",
Expand Down Expand Up @@ -149,7 +149,7 @@ exports.execute = function (options) {
it("The google_metadata with all incorrect element(null) inside array returned without array", function (done) {
var jsonInput = {
"@type": "Dataset", "@context": "http://schema.org", "name": "dummy",
"description": "lorem ipsum",
"description": "lorem ipsum",
"keywords": [
null,
""
Expand Down

0 comments on commit dad1777

Please sign in to comment.