Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect saving of object representation terms #434

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ describe('CollectionObjectSolidStore', () => {
heightUnit: 'CMT',
depthUnit: 'CMT',
widthUnit: 'CMT',
subject: [ { name: 'subject', uri: 'https://uri/' } ],
location: [ { name: 'location', uri: 'https://uri/' } ],
person: [ { name: 'person', uri: 'https://uri/' } ],
organization: [ { name: 'organization', uri: 'https://uri/' } ],
event: [ { name: 'event', uri: 'https://uri/' } ],
};

});
Expand Down Expand Up @@ -86,6 +91,7 @@ describe('CollectionObjectSolidStore', () => {
objectThing = client.addUrl(objectThing, 'http://schema.org/isPartOf', mockCollection.uri);

client.getUrl = jest.fn(() => mockCollection.uri);
client.getUrlAll = jest.fn(() => [ 'test-url' ]);
client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThingAll = jest.fn(() => [ objectThing ]);
client.getThing = jest.fn(() => objectThing);
Expand All @@ -110,6 +116,7 @@ describe('CollectionObjectSolidStore', () => {
client.getThing = jest.fn(() => client.createThing({ url: mockObject.uri }));
client.getThingAll = jest.fn(() => [ objectThing ]);
client.getUrl = jest.fn((thing, uri) => uri === 'http://schema.org/isPartOf' ? 'http://test.uri/' : null);
client.getUrlAll = jest.fn(() => [ 'test-url' ]);

const url = mockObject.uri;
const result = await service.getObjectsForCollection(mockCollection);
Expand All @@ -122,6 +129,12 @@ describe('CollectionObjectSolidStore', () => {
[ 'test-dataset', `${url}-width` ],
[ 'test-dataset', `${url}-depth` ],
[ 'test-dataset', `${url}-weight` ],
// representation items
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
]);

});
Expand All @@ -141,6 +154,7 @@ describe('CollectionObjectSolidStore', () => {
client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'test-url');
client.getUrlAll = jest.fn(() => [ 'test-url' ]);
client.getStringWithLocale = jest.fn(() => 'test-string');
client.getStringNoLocale = jest.fn(() => 'test-string');
client.getInteger = jest.fn(() => 1);
Expand All @@ -162,6 +176,7 @@ describe('CollectionObjectSolidStore', () => {
client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => null);
client.getUrlAll = jest.fn(() => [ 'test-url' ]);

const url = 'test-url';
const result = await service.get('test-url');
Expand All @@ -175,6 +190,12 @@ describe('CollectionObjectSolidStore', () => {
[ 'test-dataset', `${url}-width` ],
[ 'test-dataset', `${url}-depth` ],
[ 'test-dataset', `${url}-weight` ],
// representation items
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
[ 'test-dataset', `test-url` ],
]);

});
Expand Down Expand Up @@ -237,6 +258,7 @@ describe('CollectionObjectSolidStore', () => {
client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'http://test-uri/');
client.getUrlAll = jest.fn(() => [ 'http://test-uri/' ]);
client.setThing = jest.fn(() => 'test-thing');
client.removeThing = jest.fn(() => 'test-thing');
client.saveSolidDatasetAt = jest.fn(async () => 'test-dataset');
Expand All @@ -254,6 +276,7 @@ describe('CollectionObjectSolidStore', () => {
image: mockObject.image,
name: mockObject.name,
type: mockObject.type,
subject: [ { name: 'subject', uri: 'https://uri/' } ],
}));

expect(result.uri).toMatch(/http:\/\/test-uri\/#.*/i);
Expand All @@ -278,6 +301,47 @@ describe('CollectionObjectSolidStore', () => {

});

it('should not set undefined properties', async() => {

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'http://test-uri/');
client.getUrlAll = jest.fn(() => [ ]);
client.setThing = jest.fn(() => 'test-thing');
client.removeThing = jest.fn(() => 'test-thing');
client.saveSolidDatasetAt = jest.fn(async () => 'test-dataset');
client.addUrl = jest.fn(() => 'test-url');
client.addStringNoLocale = jest.fn(() => 'test-url');
client.addStringWithLocale = jest.fn(() => 'test-url');
client.addInteger = jest.fn(() => 'test-url');
client.addDecimal = jest.fn(() => 'test-url');

const objectWithoutSubject = {
...mockObject,
subject: undefined,
location: undefined,
person: undefined,
organization: undefined,
event: undefined,
};

const result = await service.save(objectWithoutSubject)
;

expect(result).toEqual(expect.objectContaining({
description: objectWithoutSubject.description,
image: objectWithoutSubject.image,
name: objectWithoutSubject.name,
type: objectWithoutSubject.type,
subject: undefined,
location: undefined,
person: undefined,
organization: undefined,
event: undefined,
}));

});

});

describe('toThing()', () => {
Expand Down Expand Up @@ -375,8 +439,9 @@ describe('CollectionObjectSolidStore', () => {
'width',
'depth',
'weight',
'representations',
'dataset',
])('should error when object is %s', (value) => {
])('should error when object.%s is not set', (value) => {

const thing = client.createThing({ url: mockObject.uri });

Expand All @@ -387,6 +452,7 @@ describe('CollectionObjectSolidStore', () => {
width: thing,
depth: thing,
weight: thing,
representations: [ thing ],
dataset: thing,
};

Expand All @@ -399,6 +465,7 @@ describe('CollectionObjectSolidStore', () => {
params.width,
params.depth,
params.weight,
params.representations,
params.dataset
)).toThrow();

Expand All @@ -422,6 +489,7 @@ describe('CollectionObjectSolidStore', () => {
objectThing,
objectThing,
objectThing,
[ objectThing ],
objectThing
);

Expand Down Expand Up @@ -453,7 +521,50 @@ describe('CollectionObjectSolidStore', () => {

it('should set Terms correctly', () => {

client.getUrl = jest.fn(() => 'https://test.url/');
const subjectThing = client.createThing({ url: `${mockObject.uri}subject` });
const locationThing = client.createThing({ url: `${mockObject.uri}location` });
const personThing = client.createThing({ url: `${mockObject.uri}person` });
const organizationThing = client.createThing({ url: `${mockObject.uri}organization` });
const eventThing = client.createThing({ url: `${mockObject.uri}event` });

client.getUrl = jest.fn((thing, uri) => {

if (uri.includes('#type')) {

if (thing === subjectThing) {

return 'http://schema.org/DefinedTerm';

} else if (thing === locationThing) {

return 'http://schema.org/Place';

} else if (thing === personThing) {

return 'http://schema.org/Person';

} else if (thing === organizationThing) {

return 'http://schema.org/Organization';

} else if (thing === eventThing) {

return 'http://schema.org/Event';

} else {

return 'https://test.url/';

}

} else {

return 'https://test.url/';

}

});

client.getStringNoLocale = jest.fn(() => 'test-string');
client.getUrlAll = jest.fn(() => [ 'https://test.url/' ]);
client.getStringWithLocale = jest.fn(() => 'test-string');
Expand All @@ -469,6 +580,13 @@ describe('CollectionObjectSolidStore', () => {
objectThing,
objectThing,
objectThing,
[
subjectThing,
locationThing,
personThing,
organizationThing,
eventThing,
],
objectThing
);

Expand Down
Loading