Skip to content

Commit

Permalink
add dcat version in template error
Browse files Browse the repository at this point in the history
  • Loading branch information
sansth1010 committed Nov 21, 2024
1 parent 25b430c commit cc1e10a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/dcat-us/constants/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const HEADER_V_1X = {

// Context header for DCAT US 3.0
// source: https://raw.githubusercontent.com/DOI-DO/dcat-us/refs/heads/main/context/dcat-us-3.0.jsonld
export const HEADER_V_3X = {
export const HEADER_V_3_0 = {
'@context': {
'@version': 1.1,
'@protected': true,
Expand Down
6 changes: 3 additions & 3 deletions src/dcat-us/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readableFromArray, streamToString } from '../test-helpers/stream-utils';
import { getDataStreamDcatUs } from './';
import * as datasetFromApi from '../test-helpers/mock-dataset.json';
import { HEADER_V_3X } from './constants/contexts';
import { HEADER_V_3_0 } from './constants/contexts';

async function generateDcatFeed(dataset, template, templateTransforms, version) {
const { stream: dcatStream } = getDataStreamDcatUs(template, templateTransforms, version);
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('generating DCAT-US 3.0 feed', () => {
it('formats catalog correctly', async function () {
const { feed } = await generateDcatFeed([], {}, {}, version);

expect(feed['@context']).toStrictEqual(HEADER_V_3X['@context']);
expect(feed['@context']).toStrictEqual(HEADER_V_3_0['@context']);
expect(feed['conformsTo']).toBe('https://resource.data.gov/profile/dcat-us#');
expect(feed['@type']).toBe('dcat:Catalog');
expect(Array.isArray(feed['dcat:dataset'])).toBeTruthy();
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('generating DCAT-US 3.0 feed', () => {
},
version);

expect(feed['@context']).toStrictEqual(HEADER_V_3X['@context']);
expect(feed['@context']).toStrictEqual(HEADER_V_3_0['@context']);
expect(feed['@type']).toBe('dcat:Catalog');
expect(feed['@id']).toBe('hub.arcgis.com');
expect(feed['conformsTo']).toBe('https://resource.data.gov/profile/dcat-us#');
Expand Down
4 changes: 2 additions & 2 deletions src/dcat-us/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { compileDcatFeedEntry } from './compile-dcat-feed';
import { FeedFormatterStream } from './feed-formatter-stream';
import { TransformsList } from 'adlib';
import { HEADER_V_3X, HEADER_V_1X } from './constants/contexts';
import { HEADER_V_3_0, HEADER_V_1X } from './constants/contexts';

export function getDataStreamDcatUs(feedTemplate: any, feedTemplateTransforms: TransformsList, version: string) {
const footer = '\n\t]\n}';
Expand Down Expand Up @@ -37,6 +37,6 @@ function generateDcatUs1XHeader() {
}

function generateDcatUs3XHeader(header: Record<string, any>) {
const catalogStr = JSON.stringify({ ...HEADER_V_3X, ...header }, null, '\t');
const catalogStr = JSON.stringify({ ...HEADER_V_3_0, ...header }, null, '\t');
return `${catalogStr.substring(0, catalogStr.length - 2)},\n\t"dcat:dataset": [\n`;
}
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createMockKoopApp } from './test-helpers/create-mock-koop-app';
import { readableFromArray } from './test-helpers/stream-utils';
import { DcatUsError } from './dcat-us/dcat-us-error';
import { PassThrough } from 'stream';
import { HEADER_V_3X } from './dcat-us/constants/contexts';
import { HEADER_V_3_0 } from './dcat-us/constants/contexts';

function buildPluginAndApp(feedTemplate, feedTemplateTransforms) {
let Output;
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Output Plugin', () => {
expect(res.body).toBeDefined();
const dcatStream = res.body;
expect(dcatStream['@context']).toBeDefined();
expect(dcatStream['@context']).toStrictEqual(HEADER_V_3X['@context']);
expect(dcatStream['@context']).toStrictEqual(HEADER_V_3_0['@context']);
expect(dcatStream['@type']).toBe('dcat:Catalog');
expect(dcatStream['conformsTo']).toBe('https://resource.data.gov/profile/dcat-us#');
expect(dcatStream['@type']).toBe('dcat:Catalog');
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export = class OutputDcatUs {
}
} = req;

const version = this.getVersion(_.get(req, 'path', ''));

if (!feedTemplate) {
throw new DcatUsError('DCAT-US 1.1 feed template is not provided.', 400);
throw new DcatUsError(`DCAT-US ${version} feed template is not provided.`, 400);
}

const version = this.getVersion(_.get(req, 'path', ''));

const { stream: dcatStream } = getDataStreamDcatUs(feedTemplate, feedTemplateTransforms, version);

const datasetStream = await this.getDatasetStream(req);
Expand Down

0 comments on commit cc1e10a

Please sign in to comment.