Skip to content

Commit

Permalink
Fix issue on catalog creation
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Jan 3, 2025
1 parent 44188c4 commit e1e18b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 10 additions & 3 deletions lib/routes/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const writeFile = util.promisify(fs.writeFile);

export class Catalog {
constructor() {
this._organization = utils.datasetsConfig.organization;
this._storage = utils.datasetsConfig.storage;
this._datasets = utils.datasetsConfig.datasets;
this._serverConfig = utils.serverConfig;
Expand All @@ -25,15 +26,17 @@ export class Catalog {
'Content-Type': 'application/ld+json'
});
res.send(await readFile(`${this.storage}/catalog/${agency}/catalog.json`, 'utf8'));
res.status(200);
} else {
const catalog = await this.createCatalog(agency);
writeFile(`${this.storage}/catalog/${agency}/catalog.json`, JSON.stringify(catalog), 'utf8');
await writeFile(`${this.storage}/catalog/${agency}/catalog.json`, JSON.stringify(catalog), 'utf8');
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Content-Type': 'application/ld+json'
});
res.send(catalog);
res.status(200);
}
} else {
res.set({ 'Cache-Control': 'no-cache' });
Expand Down Expand Up @@ -97,9 +100,9 @@ export class Catalog {
"license": "http://creativecommons.org/publicdomain/zero/1.0/",
"accessRights": "access:PUBLIC",
"publisher": {
"@id": utils.datasetsConfig.organization.id,
"@id": this.organization.id,
"@type": "Organization",
"name": utils.datasetsConfig.organization.name
"name": this.organization.name
},
"dataset": []
};
Expand Down Expand Up @@ -218,6 +221,10 @@ export class Catalog {
return dist;
}

get organization() {
return this._organization;
}

get storage() {
return this._storage;
}
Expand Down
13 changes: 8 additions & 5 deletions test/serving/serve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ test('Simulate http request for routes', async () => {
});

test('Test to create DCAT catalog', async () => {
expect.assertions(2);
expect.assertions(3);
let res = {
sts: null,
headers: new Map(),
Expand All @@ -317,13 +317,16 @@ test('Test to create DCAT catalog', async () => {
let catalog = new Catalog();
await catalog.getCatalog({ params: { agency: "fakeAgency"}}, res);
expect(res.sts).toBe(404);
await catalog.getCatalog({ params: { agency: "test" }}, res);
await catalog.getCatalog({ params: { agency: "test" }}, res);
await del([`${utils.datasetsConfig['storage']}/catalog`], { force: true});

catalog._storage = utils.datasetsConfig['storage'];
catalog._datasets = utils.datasetsConfig['datasets'];
let cat = await catalog.createCatalog('test');
catalog._organization = utils.datasetsConfig['organization'];

const cat = await catalog.createCatalog('test');
expect(cat['@context']).toBeDefined();
await catalog.getCatalog({ params: { agency: "test" }}, res);
expect(res.sts).toBe(200);
await del(utils.datasetsConfig['storage'] + '/catalog/test/catalog.json');
});

function findConnection(id, array) {
Expand Down
Empty file.

0 comments on commit e1e18b8

Please sign in to comment.