Skip to content

Commit

Permalink
Tools: Fixed unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Aug 9, 2024
1 parent 41b77a7 commit bd2f205
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
13 changes: 13 additions & 0 deletions src/CLI/morningstar-connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ export async function main (): Promise<void> {

console.info(`Content available at http://localhost:${port}.`);

process.stdin.on('data', (data) => {
const input = data.toString('utf8');

if (
input.startsWith('exit') ||
input.startsWith('quit') ||
input.startsWith('stop')
) {
server.stop();
process.exit(0);
}
});

}


Expand Down
6 changes: 4 additions & 2 deletions src/RNANews/RNANewsConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export class RNANewsConnector extends MorningstarConnector {
* Same connector instance with modified table.
*/
public override async load (): Promise<this> {
await super.load();

const options = this.options;
const {
security,
Expand All @@ -146,8 +148,8 @@ export class RNANewsConnector extends MorningstarConnector {
return this;
}

const api = new MorningstarAPI(options.api);
const url = new MorningstarURL('timeseries/rna-news');
const api = this.api = this.api || new MorningstarAPI(options.api);
const url = new MorningstarURL('timeseries/rna-news', api.baseURL);

url.setSecuritiesOptions([security]);

Expand Down
48 changes: 26 additions & 22 deletions src/TimeSeries/TimeSeriesConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,47 @@ export class TimeSeriesConnector extends MorningstarConnector {


public override async load (): Promise<this> {
await super.load();

const options = this.options;
const currencyId = options.currencyId;
const endDate = options.endDate;
const securities = options.securities;
const startDate = options.startDate;
const tax = options.tax;

if (securities) {
const api = new MorningstarAPI(options.api);
const url = new MorningstarURL(this.path, api.baseURL);
if (!securities) {
return this;
}

const api = this.api = this.api || new MorningstarAPI(options.api);
const url = new MorningstarURL(this.path, api.baseURL);

url.setSecuritiesOptions(securities);
url.setSecuritiesOptions(securities);

if (currencyId) {
url.searchParams.set('currencyId', currencyId);
}
if (currencyId) {
url.searchParams.set('currencyId', currencyId);
}

if (endDate) {
url.setDate('endDate', endDate);
}
if (endDate) {
url.setDate('endDate', endDate);
}

if (startDate) {
url.setDate('startDate', startDate);
}
if (startDate) {
url.setDate('startDate', startDate);
}

if (tax) {
url.searchParams.set('tax', tax);
}
if (tax) {
url.searchParams.set('tax', tax);
}

const response = await api.fetch(url);
const json = await response.json() as unknown;
const response = await api.fetch(url);
const json = await response.json() as unknown;

this.converter.parse({ json });
this.converter.parse({ json });

this.table.deleteColumns();
this.table.setColumns(this.converter.getTable().getColumns());
}
this.table.deleteColumns();
this.table.setColumns(this.converter.getTable().getColumns());

return this;
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit-tests/TimeSeries/DividendConverter.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Assert from 'node:assert/strict';
import * as MorningstarConnectors from '../../../code/morningstar-connectors.src';
import * as MC from '../../../code/morningstar-connectors.src';

export async function ratingLoad (
api: MorningstarConnectors.Shared.MorningstarAPIOptions
api: MC.Shared.MorningstarAPIOptions
) {
const connector = new MorningstarConnectors.TimeSeriesConnector({
const connector = new MC.TimeSeriesConnector({
api,
currencyId: 'EUR',
endDate: '2020-12-31',
Expand All @@ -19,13 +19,13 @@ export async function ratingLoad (
});

Assert.ok(
connector instanceof MorningstarConnectors.TimeSeriesConnector,
connector instanceof MC.TimeSeriesConnector,
'Connector should be instance of TimeSeries class.'
);

Assert.ok(
connector.converter instanceof
MorningstarConnectors.TimeSeriesConverters.DividendSeriesConverter,
MC.TimeSeriesConverters.DividendSeriesConverter,
'Converter should be instance of TimeSeries DividendSeriesConverter.'
);

Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function runUnitTests () {
for (let testName of Object.keys(unitTests)) {

test = unitTests[testName];
testName = testName.replace(/[A-Z]+/u, ' $0').toLowerCase();
testName = testName.replace(/([A-Z]+)/u, ' $1').toLowerCase();

if (typeof test === 'function') {

Expand Down

0 comments on commit bd2f205

Please sign in to comment.