2020-04-28 09:47:35 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars-experimental */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
import 'mocha';
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import { RedundancyPendingItem } from '@cyberalien/redundancy';
|
|
|
|
import {
|
|
|
|
setAPIConfig,
|
|
|
|
getAPIConfig,
|
|
|
|
IconifyAPIConfig,
|
|
|
|
} from '../../lib/api/config';
|
|
|
|
import {
|
2020-05-31 06:44:24 +00:00
|
|
|
setAPIModule,
|
2020-04-28 09:47:35 +00:00
|
|
|
APIQueryParams,
|
|
|
|
getAPIModule,
|
|
|
|
IconifyAPIModule,
|
|
|
|
} from '../../lib/api/modules';
|
|
|
|
|
|
|
|
describe('Testing API modules', () => {
|
|
|
|
let prefixCounter = 0;
|
|
|
|
function nextPrefix(): string {
|
|
|
|
prefixCounter++;
|
|
|
|
return (
|
|
|
|
'api-mod-test-' + (prefixCounter < 10 ? '0' : '') + prefixCounter
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const prepareQuery = (
|
2020-05-29 19:08:45 +00:00
|
|
|
provider: string,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix: string,
|
|
|
|
icons: string[]
|
|
|
|
): APIQueryParams[] => {
|
|
|
|
const item: APIQueryParams = {
|
2020-05-29 19:08:45 +00:00
|
|
|
provider,
|
2020-04-28 09:47:35 +00:00
|
|
|
prefix,
|
|
|
|
icons,
|
|
|
|
};
|
|
|
|
return [item];
|
|
|
|
};
|
|
|
|
|
|
|
|
const sendQuery = (
|
|
|
|
host: string,
|
|
|
|
params: APIQueryParams,
|
|
|
|
status: RedundancyPendingItem
|
|
|
|
): void => {
|
|
|
|
throw new Error('Unexpected API call');
|
|
|
|
};
|
|
|
|
|
|
|
|
it('Empty module', () => {
|
2020-05-29 19:08:45 +00:00
|
|
|
const provider = nextPrefix();
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Set config
|
2020-05-29 19:08:45 +00:00
|
|
|
setAPIConfig(provider, {
|
|
|
|
resources: ['https://localhost:3000'],
|
|
|
|
maxURL: 500,
|
|
|
|
});
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Set fake module
|
2020-05-31 06:44:24 +00:00
|
|
|
setAPIModule(provider, {
|
2020-05-29 19:08:45 +00:00
|
|
|
prepare: prepareQuery,
|
|
|
|
send: sendQuery,
|
|
|
|
});
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Get config
|
2020-05-29 19:08:45 +00:00
|
|
|
const config = getAPIConfig(provider) as IconifyAPIConfig;
|
|
|
|
expect(config).to.not.be.equal(void 0);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
|
|
|
// Check setAPIConfig
|
|
|
|
expect(config.resources).to.be.eql(['https://localhost:3000']);
|
|
|
|
|
|
|
|
// Check getAPIModule()
|
2020-05-29 19:08:45 +00:00
|
|
|
const item = getAPIModule(provider) as IconifyAPIModule;
|
|
|
|
expect(item).to.not.be.equal(void 0);
|
2020-04-28 09:47:35 +00:00
|
|
|
expect(item.prepare).to.be.equal(prepareQuery);
|
|
|
|
expect(item.send).to.be.equal(sendQuery);
|
|
|
|
|
2020-05-29 19:08:45 +00:00
|
|
|
// Get module for different provider to make sure it is empty
|
|
|
|
const provider2 = nextPrefix();
|
|
|
|
const item2 = getAPIModule(provider2);
|
|
|
|
expect(item2).to.be.equal(void 0);
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
});
|