Skip to content

Commit

Permalink
Change response type to octet/stream parsing
Browse files Browse the repository at this point in the history
* Change response type to octet/stream parsing

* Add contentType to avoid selfclosing manipulation
  • Loading branch information
minottic authored Jul 30, 2024
1 parent ae1916b commit 19b2f90
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}));
Expand Down
14 changes: 13 additions & 1 deletion src/__tests__/fixtures/MockStubs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import {JSDOM} from 'jsdom';

export const xmlContent = `<?xml version="1.0"?>
<rdf:RDF xmlns="aXML">
<rdf:RDF xmlns="http://purl.org/pan-science/PaNET/PaNET.owl#"
xml:base="http://purl.org/pan-science/PaNET/PaNET.owl"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:vann="http://purl.org/vocab/vann/"
xmlns:PaNET="PaNET:"
xmlns:terms="http://purl.org/dc/terms/">
<owl:Class rdf:about="class1">
<owl:equivalentClass rdf:resource="http://class2/label2"/>
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/fixtures/responses/github.response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const githubRespone = {
text: `<?xml version="1.0"?>
responseType: (value: string) => ({
body: `<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.org/pan-science/PaNET/PaNET.owl#"
xml:base="http://purl.org/pan-science/PaNET/PaNET.owl"
xmlns:obo="http://purl.obolibrary.org/obo/"
Expand Down Expand Up @@ -4256,4 +4257,5 @@ export const githubRespone = {
<!-- Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi -->`,
}),
};
2 changes: 1 addition & 1 deletion src/__tests__/unit/technique-getter.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 4 additions & 2 deletions src/misc/technique-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ export class GitHubOwlTechnique extends OntologyTechnique {
}

async getCollection(): Promise<NodeList> {
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]',
);
Expand Down

0 comments on commit 19b2f90

Please sign in to comment.