From 19b2f901c7940b4988ff307b24f6f48f22a5f88f Mon Sep 17 00:00:00 2001 From: Carlo Minotti <50220438+minottic@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:01:58 +0200 Subject: [PATCH] Change response type to octet/stream parsing * Change response type to octet/stream parsing * Add contentType to avoid selfclosing manipulation --- .../acceptance/technique.controller.acceptance.ts | 2 +- src/__tests__/fixtures/MockStubs.ts | 14 +++++++++++++- .../fixtures/responses/github.response.ts | 4 +++- src/__tests__/unit/technique-getter.unit.ts | 2 +- src/misc/technique-getter.ts | 6 ++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/__tests__/acceptance/technique.controller.acceptance.ts b/src/__tests__/acceptance/technique.controller.acceptance.ts index 1d764bf..6c906ec 100644 --- a/src/__tests__/acceptance/technique.controller.acceptance.ts +++ b/src/__tests__/acceptance/technique.controller.acceptance.ts @@ -30,7 +30,7 @@ configs.forEach(conf => { .stub(BioPortalTechniques.prototype, 'getCollection') .resolves(bioportalResponse); // eslint-disable-next-line @typescript-eslint/no-explicit-any - else sandbox.stub(superagent, 'get').resolves(githubRespone as any); + else sandbox.stub(superagent, 'get').returns(githubRespone as any); ({app, client} = await setupApplication({ technique: {class: conf, cache: cache}, })); diff --git a/src/__tests__/fixtures/MockStubs.ts b/src/__tests__/fixtures/MockStubs.ts index e1a5657..1adf209 100644 --- a/src/__tests__/fixtures/MockStubs.ts +++ b/src/__tests__/fixtures/MockStubs.ts @@ -1,7 +1,19 @@ import {JSDOM} from 'jsdom'; export const xmlContent = ` - + diff --git a/src/__tests__/fixtures/responses/github.response.ts b/src/__tests__/fixtures/responses/github.response.ts index 03a4319..8e27d0c 100644 --- a/src/__tests__/fixtures/responses/github.response.ts +++ b/src/__tests__/fixtures/responses/github.response.ts @@ -1,5 +1,6 @@ export const githubRespone = { - text: ` + responseType: (value: string) => ({ + body: ` `, + }), }; diff --git a/src/__tests__/unit/technique-getter.unit.ts b/src/__tests__/unit/technique-getter.unit.ts index 110e4ad..919dbe0 100644 --- a/src/__tests__/unit/technique-getter.unit.ts +++ b/src/__tests__/unit/technique-getter.unit.ts @@ -299,7 +299,7 @@ describe('GitHubOwlTechnique', () => { sandbox .stub(superagent, 'get') // eslint-disable-next-line @typescript-eslint/no-explicit-any - .returns({text: xmlContent} as any); + .returns({responseType: () => ({body: xmlContent})} as any); const data = await GitHubOwlTechnique.getCollection(); expect(data.length).to.be.eql(3); }); diff --git a/src/misc/technique-getter.ts b/src/misc/technique-getter.ts index 52f76d8..d565c90 100644 --- a/src/misc/technique-getter.ts +++ b/src/misc/technique-getter.ts @@ -145,8 +145,10 @@ export class GitHubOwlTechnique extends OntologyTechnique { } async getCollection(): Promise { - const xmlFile = await superagent.get(this.url); - const xmlParsed = new jsdom.JSDOM(xmlFile.text); + const xmlFile = await superagent.get(this.url).responseType('blob'); + const xmlParsed = new jsdom.JSDOM(xmlFile.body.toString('utf-8'), { + contentType: 'application/xml', + }); return xmlParsed.window.document.querySelectorAll( 'owl\\:Class[rdf\\:about]', );