diff --git a/src/examples-spec.js b/src/examples-spec.js index 27ed5ea..0a432b8 100644 --- a/src/examples-spec.js +++ b/src/examples-spec.js @@ -28,10 +28,7 @@ for (const { validationMode, })); const failures = results.filter((result) => result.severity === 'failure') - .map((error) => `${error.path}: ${error.message.split('\n')[0]}`) - // TECH DEBT: beta:virtualTour has been removed from the beta namespace temporarily as it breaks other libraries - // Remove the line below once beta:virtualTour has been re-introduced - .filter((x) => x.indexOf('beta:virtualTour') === -1); + .map((error) => `${error.path}: ${error.message.split('\n')[0]}`); expect(failures).toEqual([]); }); diff --git a/src/validate-spec.js b/src/validate-spec.js index d4fe631..d640b06 100644 --- a/src/validate-spec.js +++ b/src/validate-spec.js @@ -712,4 +712,172 @@ describe('validate', () => { expect(result[0].severity).toBe(ValidationErrorSeverity.NOTICE); }); }); + + // Organization level data (Modelling Opportunity Data section 5.8.1): a stand-alone Organization, + // as the top-level object or an RPDE item's data, has its own required and recommended fields. + // These are set in data-models by containing field name (`$` and `data`), so these tests also + // guard against changes to those names. + describe('Organization level data', () => { + let validOrganization; + let feedOptions; + + // The feed page gives the license, so the records in it do not + const organizationFeed = (organization) => { + const data = { ...organization }; + delete data.license; + return { + items: [ + { + id: '1', + kind: 'Organization', + state: 'updated', + data, + modified: 1533177378657, + }, + ], + next: 'https://example.org/api/feed/?afterId=1&afterTimestamp=1533177378657&limit=500', + license: 'https://creativecommons.org/licenses/by/4.0/', + }; + }; + + const missingFields = (result, type) => result + .filter((error) => error.type === type) + .map((error) => error.path); + + // Minimal beta namespace context defining beta:dateVerified, as published at https://openactive.io/ns-beta + const betaContext = { + '@context': { + rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + rdfs: 'http://www.w3.org/2000/01/rdf-schema#', + schema: 'https://schema.org/', + beta: 'https://openactive.io/ns-beta#', + label: 'rdfs:label', + comment: 'rdfs:comment', + domainIncludes: { '@id': 'schema:domainIncludes', '@type': '@id' }, + rangeIncludes: { '@id': 'schema:rangeIncludes', '@type': '@id' }, + Property: 'rdf:Property', + }, + '@graph': [ + { + '@id': 'beta:dateVerified', + '@type': 'Property', + label: 'dateVerified', + comment: 'The date on which the details of this organization were last verified as correct by the publisher.', + domainIncludes: ['schema:Organization'], + rangeIncludes: ['schema:Date'], + }, + ], + }; + + beforeEach(() => { + nock('https://openactive.io') + .get('/ns-beta') + .reply(200, betaContext, { + 'Content-Type': 'application/ld+json', + }); + + validOrganization = { + '@context': [metaData.contextUrl, 'https://openactive.io/ns-beta'], + '@type': 'Organization', + '@id': 'https://example.org/id/organisation/1', + name: 'Example Yacht Club', + 'beta:dateVerified': '2026-10-01', + license: 'https://creativecommons.org/licenses/by/4.0/', + description: 'A community amateur sports club focused on getting people sailing.', + url: 'https://exampleyachtclub.org/', + sameAs: ['https://www.facebook.com/ExampleYachtClub/'], + email: 'info@exampleyachtclub.org', + telephone: '020 7946 0000', + activity: [ + { + '@id': 'https://openactive.io/activity-list#c16df6ed-a4a0-4275-a8c3-1c8cff56856f', + prefLabel: 'Tai Chi', + '@type': 'Concept', + inScheme: 'https://openactive.io/activity-list', + }, + ], + location: 'Example Wharf, Greenwich, London SE10 0BW', + }; + feedOptions = new OptionsHelper({ + loadRemoteJson: true, + version: 'latest', + validationMode: 'RPDEFeed', + }); + }); + + it('should return no errors for a valid stand-alone Organization', async () => { + const result = await validate(validOrganization, feedOptions); + + expect(result.length).toBe(0); + }); + + it('should require activity and location on a stand-alone Organization', async () => { + const organization = { ...validOrganization }; + delete organization.activity; + delete organization.location; + + const result = await validate(organization, feedOptions); + + expect(missingFields(result, ValidationErrorType.MISSING_REQUIRED_FIELD)).toEqual(['$.activity', '$.location']); + }); + + it('should require beta:dateVerified on a stand-alone Organization', async () => { + const organization = { ...validOrganization }; + delete organization['beta:dateVerified']; + + const result = await validate(organization, feedOptions); + + expect(missingFields(result, ValidationErrorType.MISSING_REQUIRED_FIELD)).toEqual(['$["beta:dateVerified"]']); + }); + + it('should require license on a stand-alone Organization', async () => { + const organization = { ...validOrganization }; + delete organization.license; + + const result = await validate(organization, feedOptions); + + expect(missingFields(result, ValidationErrorType.MISSING_REQUIRED_FIELD)).toEqual(['$.license']); + }); + + it('should recommend description and email on a stand-alone Organization', async () => { + const organization = { ...validOrganization }; + delete organization.description; + delete organization.email; + + const result = await validate(organization, feedOptions); + + expect(missingFields(result, ValidationErrorType.MISSING_RECOMMENDED_FIELD)).toEqual(['$.description', '$.email']); + }); + + it('should require activity and location on an Organization in an RPDE feed', async () => { + const organization = { ...validOrganization }; + delete organization.activity; + delete organization.location; + + const result = await validate(organizationFeed(organization), feedOptions); + + expect(missingFields(result, ValidationErrorType.MISSING_REQUIRED_FIELD)).toEqual(['$.items[0].data.activity', '$.items[0].data.location']); + }); + + it('should accept an RPDE feed of valid Organizations, without license on each Organization', async () => { + const feed = organizationFeed(validOrganization); + + const result = await validate(feed, feedOptions); + + expect(feed.items[0].data.license).toBeUndefined(); + + expect(result.length).toBe(1); + expect(result[0].type).toBe(ValidationErrorType.FOUND_RPDE_FEED); + }); + + it('should not require activity or location on an Organization that is an organizer', async () => { + const event = { ...validSessionSeries }; + + const result = await validate(event, feedOptions); + + expect(event.organizer.activity).toBeUndefined(); + expect(event.organizer.location).toBeUndefined(); + expect(result.length).toBe(0); + }); + }); });