mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
13 changed files with 219 additions and 128 deletions
@ -1,9 +1,12 @@ |
|||||
|
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
||||
|
|
||||
import { Module } from '@nestjs/common'; |
import { Module } from '@nestjs/common'; |
||||
|
|
||||
import { CryptocurrencyService } from './cryptocurrency.service'; |
import { CryptocurrencyService } from './cryptocurrency.service'; |
||||
|
|
||||
@Module({ |
@Module({ |
||||
providers: [CryptocurrencyService], |
exports: [CryptocurrencyService], |
||||
exports: [CryptocurrencyService] |
imports: [PropertyModule], |
||||
|
providers: [CryptocurrencyService] |
||||
}) |
}) |
||||
export class CryptocurrencyModule {} |
export class CryptocurrencyModule {} |
||||
|
|||||
@ -1,31 +1,39 @@ |
|||||
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; |
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
||||
|
import { |
||||
|
DEFAULT_CURRENCY, |
||||
|
PROPERTY_CUSTOM_CRYPTOCURRENCIES |
||||
|
} from '@ghostfolio/common/config'; |
||||
|
|
||||
import { Injectable } from '@nestjs/common'; |
import { Injectable, OnModuleInit } from '@nestjs/common'; |
||||
|
|
||||
const cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json'); |
const cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json'); |
||||
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); |
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); |
||||
|
|
||||
@Injectable() |
@Injectable() |
||||
export class CryptocurrencyService { |
export class CryptocurrencyService implements OnModuleInit { |
||||
private combinedCryptocurrencies: string[]; |
private combinedCryptocurrencies: string[]; |
||||
|
|
||||
|
public constructor(private readonly propertyService: PropertyService) {} |
||||
|
|
||||
|
public async onModuleInit() { |
||||
|
const customCryptocurrenciesFromDatabase = |
||||
|
await this.propertyService.getByKey<Record<string, string>>( |
||||
|
PROPERTY_CUSTOM_CRYPTOCURRENCIES |
||||
|
); |
||||
|
|
||||
|
this.combinedCryptocurrencies = [ |
||||
|
...Object.keys(cryptocurrencies), |
||||
|
...Object.keys(customCryptocurrencies), |
||||
|
...Object.keys(customCryptocurrenciesFromDatabase ?? {}) |
||||
|
]; |
||||
|
} |
||||
|
|
||||
public isCryptocurrency(aSymbol = '') { |
public isCryptocurrency(aSymbol = '') { |
||||
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); |
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); |
||||
|
|
||||
return ( |
return ( |
||||
aSymbol.endsWith(DEFAULT_CURRENCY) && |
aSymbol.endsWith(DEFAULT_CURRENCY) && |
||||
this.getCryptocurrencies().includes(cryptocurrencySymbol) |
this.combinedCryptocurrencies.includes(cryptocurrencySymbol) |
||||
); |
); |
||||
} |
} |
||||
|
|
||||
private getCryptocurrencies() { |
|
||||
if (!this.combinedCryptocurrencies) { |
|
||||
this.combinedCryptocurrencies = [ |
|
||||
...Object.keys(cryptocurrencies), |
|
||||
...Object.keys(customCryptocurrencies) |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
return this.combinedCryptocurrencies; |
|
||||
} |
|
||||
} |
} |
||||
|
|||||
@ -0,0 +1,60 @@ |
|||||
|
import { DataService } from '@ghostfolio/ui/services'; |
||||
|
|
||||
|
import { signal } from '@angular/core'; |
||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
|
import { FormBuilder } from '@angular/forms'; |
||||
|
import { MatDialog } from '@angular/material/dialog'; |
||||
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
||||
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
||||
|
|
||||
|
import { GfHistoricalMarketDataEditorComponent } from './historical-market-data-editor.component'; |
||||
|
|
||||
|
jest.mock( |
||||
|
'./historical-market-data-editor-dialog/historical-market-data-editor-dialog.component', |
||||
|
() => ({ |
||||
|
GfHistoricalMarketDataEditorDialogComponent: class {} |
||||
|
}) |
||||
|
); |
||||
|
|
||||
|
describe('GfHistoricalMarketDataEditorComponent', () => { |
||||
|
let component: GfHistoricalMarketDataEditorComponent; |
||||
|
let fixture: ComponentFixture<GfHistoricalMarketDataEditorComponent>; |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
await TestBed.configureTestingModule({ |
||||
|
imports: [GfHistoricalMarketDataEditorComponent], |
||||
|
providers: [ |
||||
|
FormBuilder, |
||||
|
{ provide: DataService, useValue: {} }, |
||||
|
{ |
||||
|
provide: DeviceDetectorService, |
||||
|
useValue: { |
||||
|
deviceInfo: signal({ deviceType: 'desktop' }) |
||||
|
} |
||||
|
}, |
||||
|
{ provide: MatDialog, useValue: {} }, |
||||
|
{ provide: MatSnackBar, useValue: {} } |
||||
|
] |
||||
|
}).compileComponents(); |
||||
|
|
||||
|
fixture = TestBed.createComponent(GfHistoricalMarketDataEditorComponent); |
||||
|
component = fixture.componentInstance; |
||||
|
fixture.detectChanges(); |
||||
|
}); |
||||
|
|
||||
|
it('should create', () => { |
||||
|
expect(component).toBeTruthy(); |
||||
|
}); |
||||
|
|
||||
|
describe('formatDay', () => { |
||||
|
it('should pad single digit days with zero', () => { |
||||
|
expect(component.formatDay(1)).toBe('01'); |
||||
|
expect(component.formatDay(9)).toBe('09'); |
||||
|
}); |
||||
|
|
||||
|
it('should not pad double digit days', () => { |
||||
|
expect(component.formatDay(10)).toBe('10'); |
||||
|
expect(component.formatDay(31)).toBe('31'); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue