Skip to content
Snippets Groups Projects
Commit 6145c4cf authored by Millicent Billette's avatar Millicent Billette
Browse files

ADD: mockableDeps to data-pod-client

parent 24de8697
No related branches found
No related tags found
No related merge requests found
Pipeline #12961 passed with warnings
import {fetch} from './context-dependant/generics.mjs';
export const mockableDeps = {
fetch
};
export function DataPodClient(hosts) {
const self = this;
self.hosts = hosts;
......@@ -8,5 +10,5 @@ export function DataPodClient(hosts) {
}
async function query(self, queryStr) {
return await (await fetch(self.hosts[0] + queryStr)).json();
return await (await mockableDeps.fetch(self.hosts[0] + queryStr)).json();
}
import test from 'ava';
import * as app from './data-pod-client.mjs';
test('dummy', async t => {
t.true(true);
});
test('data-pod-client dummy request', async t => {
const hosts = ['https://dummy/'];
const query = 'user/profile/2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT?&_source=title';
const expectedResult = JSON.parse(`{
"_index":"user","_type":"profile","_id":"2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT","_version":11,
"found":true,
"_source":{"title":"[1000i100] Millicent BILLETTE"}
}`);
app.mockableDeps.fetch = (str)=> {return {json:()=>expectedResult};};
const client = new app.DataPodClient(hosts);
const result = await client.query(query);
t.is(result._source.title, expectedResult._source.title);
});
......@@ -23,8 +23,8 @@ test('multi altCount', t => t.is(app.altCount(app.buildTreeStruct('(a|b|c)(d|e|f
test('multi level tree altCount', t => t.is(app.altCount(app.buildTreeStruct('a(b(c|d)|e(f|g|h)ij(k|l)|@@@@m)')), 9));
const exampleTree = () => app.buildTreeStruct('a(b(c|d)|e(f|g(h|i)|j)kl(m|n(o|p)|q(r|s)|t)|(u|v)w)');
console.log(JSON.stringify(exampleTree()));
console.log(app.serialize(exampleTree()));
//console.log(JSON.stringify(exampleTree()));
//console.log(app.serialize(exampleTree()));
test('getAlternative 0', t => t.is(app.getAlternative(0, exampleTree()), 'abc'));
test('getAlternative 1', t => t.is(app.getAlternative(1, exampleTree()), 'abd'));
test('getAlternative 2', t => t.is(app.getAlternative(2, exampleTree()), 'aefklm'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment