Browse Source

Clean up

pull/2002/head
Thomas 2 years ago
parent
commit
a981d278d6
  1. 97
      apps/api/src/app/benchmark/benchmark.service.spec.ts
  2. 2
      apps/client/src/app/app.component.ts
  3. 12
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  4. 2
      apps/client/src/app/components/admin-overview/admin-overview.component.ts
  5. 2
      apps/client/src/app/components/admin-users/admin-users.component.ts
  6. 2
      apps/client/src/app/components/home-market/home-market.component.ts
  7. 2
      apps/client/src/app/components/home-summary/home-summary.component.ts
  8. 2
      apps/client/src/app/core/http-response.interceptor.ts
  9. 2
      apps/client/src/app/pages/about/about-page.component.ts
  10. 2
      apps/client/src/app/pages/account/account-page.component.ts
  11. 2
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts
  12. 2
      apps/client/src/app/pages/admin/admin-page.component.ts
  13. 2
      apps/client/src/app/pages/blog/blog-page.component.ts
  14. 2
      apps/client/src/app/pages/demo/demo-page.component.ts
  15. 2
      apps/client/src/app/pages/features/features-page.component.ts
  16. 2
      apps/client/src/app/pages/home/home-page.component.ts
  17. 2
      apps/client/src/app/pages/landing/landing-page.component.ts
  18. 2
      apps/client/src/app/pages/open/open-page.component.ts
  19. 2
      apps/client/src/app/pages/portfolio/activities/activities-page.component.ts
  20. 2
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts
  21. 2
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts
  22. 2
      apps/client/src/app/pages/portfolio/portfolio-page.component.ts
  23. 2
      apps/client/src/app/pages/pricing/pricing-page.component.ts
  24. 4
      apps/client/src/app/pages/register/register-page.component.ts
  25. 33
      apps/client/src/app/services/data.service.ts

97
apps/api/src/app/benchmark/benchmark.service.spec.ts

@ -1,97 +0,0 @@
import { BenchmarkService } from './benchmark.service';
import { PropertyService } from '@ghostfolio/api/services/property/property.service';
import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config';
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
import { NotFoundError } from '@ghostfolio/common/exceptions';
jest.mock('@ghostfolio/api/services/property/property.service', () => {
return {
PropertyService: jest.fn().mockImplementation(() => {
return {
getByKey: jest.fn().mockImplementation((key: string) => {
return [{ symbolProfileId: 'profile-id-1' }];
}),
put: jest.fn().mockImplementation(({ key, value }) => {
return Promise.resolve();
})
};
})
};
});
jest.mock('@ghostfolio/api/services/prisma/prisma.service', () => {
return {
PrismaService: jest.fn().mockImplementation(() => {
return {
symbolProfile: {
findFirst: jest.fn()
}
};
})
};
});
describe('BenchmarkService', () => {
let benchmarkService: BenchmarkService;
let prismaService: PrismaService = new PrismaService();
let propertyService: PropertyService = new PropertyService(prismaService);
beforeAll(async () => {
benchmarkService = new BenchmarkService(
null,
null,
prismaService,
propertyService,
null,
null,
null
);
});
it('calculateChangeInPercentage', async () => {
expect(benchmarkService.calculateChangeInPercentage(1, 2)).toEqual(1);
expect(benchmarkService.calculateChangeInPercentage(2, 2)).toEqual(0);
expect(benchmarkService.calculateChangeInPercentage(2, 1)).toEqual(-0.5);
});
it('should add new benchmark', async () => {
prismaService.symbolProfile.findFirst = jest
.fn()
.mockResolvedValueOnce(
Promise.resolve({ id: 'profile-id-2', name: 'Test Profile' })
);
const result = await benchmarkService.addBenchmark({
dataSource: 'YAHOO',
symbol: 'symbol-2'
});
expect(propertyService.put).toHaveBeenCalledWith({
key: PROPERTY_BENCHMARKS,
value: JSON.stringify([
{ symbolProfileId: 'profile-id-1' },
{ symbolProfileId: 'profile-id-2' }
])
});
expect(result).toEqual({
dataSource: 'YAHOO',
id: 'profile-id-2',
name: 'Test Profile',
symbol: 'symbol-2'
});
});
it('should throw error if symbol profile not found', async () => {
prismaService.symbolProfile.findFirst = jest
.fn()
.mockResolvedValueOnce(Promise.resolve(null));
try {
await benchmarkService.addBenchmark({
dataSource: 'YAHOO',
symbol: 'symbol-2'
});
} catch (e) {
expect(e).toEqual(new NotFoundError('Symbol profile not found'));
}
});
});

2
apps/client/src/app/app.component.ts

@ -64,7 +64,7 @@ export class AppComponent implements OnDestroy, OnInit {
const urlSegments = urlSegmentGroup.segments; const urlSegments = urlSegmentGroup.segments;
this.currentRoute = urlSegments[0].path; this.currentRoute = urlSegments[0].path;
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
if (this.deviceType === 'mobile') { if (this.deviceType === 'mobile') {
setTimeout(() => { setTimeout(() => {

12
apps/client/src/app/components/admin-market-data/admin-market-data.component.ts

@ -127,7 +127,7 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.benchmarks = this.dataService.getInfo().benchmarks; this.benchmarks = this.dataService.fetchInfo().benchmarks;
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;
this.filters$ this.filters$
@ -209,15 +209,7 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
this.dataService this.dataService
.postBenchmark(benchmark) .postBenchmark(benchmark)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((_) => { .subscribe(() => {});
this.dataService
.fetchInfo()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((info: InfoItem) => {
this.benchmarks = info.benchmarks;
(window as any) = info;
});
});
} }
public onGatherSymbol({ dataSource, symbol }: UniqueAsset) { public onGatherSymbol({ dataSource, symbol }: UniqueAsset) {

2
apps/client/src/app/components/admin-overview/admin-overview.component.ts

@ -50,7 +50,7 @@ export class AdminOverviewComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.userService.stateChanged this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))

2
apps/client/src/app/components/admin-users/admin-users.component.ts

@ -35,7 +35,7 @@ export class AdminUsersComponent implements OnDestroy, OnInit {
private impersonationStorageService: ImpersonationStorageService, private impersonationStorageService: ImpersonationStorageService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.hasPermissionForSubscription = hasPermission( this.hasPermissionForSubscription = hasPermission(
this.info?.globalPermissions, this.info?.globalPermissions,

2
apps/client/src/app/components/home-market/home-market.component.ts

@ -37,7 +37,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.isLoading = true; this.isLoading = true;
this.userService.stateChanged this.userService.stateChanged

2
apps/client/src/app/components/home-summary/home-summary.component.ts

@ -42,7 +42,7 @@ export class HomeSummaryComponent implements OnDestroy, OnInit {
private snackBar: MatSnackBar, private snackBar: MatSnackBar,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.hasPermissionForSubscription = hasPermission( this.hasPermissionForSubscription = hasPermission(
this.info?.globalPermissions, this.info?.globalPermissions,

2
apps/client/src/app/core/http-response.interceptor.ts

@ -35,7 +35,7 @@ export class HttpResponseInterceptor implements HttpInterceptor {
private snackBar: MatSnackBar, private snackBar: MatSnackBar,
private webAuthnService: WebAuthnService private webAuthnService: WebAuthnService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.hasPermissionForSubscription = hasPermission( this.hasPermissionForSubscription = hasPermission(
this.info?.globalPermissions, this.info?.globalPermissions,

2
apps/client/src/app/pages/about/about-page.component.ts

@ -31,7 +31,7 @@ export class AboutPageComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
const { globalPermissions, statistics } = this.dataService.getInfo(); const { globalPermissions, statistics } = this.dataService.fetchInfo();
this.hasPermissionForBlog = hasPermission( this.hasPermissionForBlog = hasPermission(
globalPermissions, globalPermissions,

2
apps/client/src/app/pages/account/account-page.component.ts

@ -85,7 +85,7 @@ export class AccountPageComponent implements OnDestroy, OnInit {
public webAuthnService: WebAuthnService public webAuthnService: WebAuthnService
) { ) {
const { baseCurrency, currencies, globalPermissions, subscriptions } = const { baseCurrency, currencies, globalPermissions, subscriptions } =
this.dataService.getInfo(); this.dataService.fetchInfo();
this.baseCurrency = baseCurrency; this.baseCurrency = baseCurrency;
this.currencies = currencies; this.currencies = currencies;

2
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

@ -30,7 +30,7 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
) {} ) {}
ngOnInit() { ngOnInit() {
const { currencies, platforms } = this.dataService.getInfo(); const { currencies, platforms } = this.dataService.fetchInfo();
this.currencies = currencies; this.currencies = currencies;
this.platforms = platforms; this.platforms = platforms;

2
apps/client/src/app/pages/admin/admin-page.component.ts

@ -18,7 +18,7 @@ export class AdminPageComponent implements OnDestroy, OnInit {
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
public constructor(private dataService: DataService) { public constructor(private dataService: DataService) {
const { systemMessage } = this.dataService.getInfo(); const { systemMessage } = this.dataService.fetchInfo();
this.hasMessage = !!systemMessage; this.hasMessage = !!systemMessage;
} }

2
apps/client/src/app/pages/blog/blog-page.component.ts

@ -15,7 +15,7 @@ export class BlogPageComponent implements OnDestroy {
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
public constructor(private dataService: DataService) { public constructor(private dataService: DataService) {
const info = this.dataService.getInfo(); const info = this.dataService.fetchInfo();
this.hasPermissionForSubscription = hasPermission( this.hasPermissionForSubscription = hasPermission(
info?.globalPermissions, info?.globalPermissions,

2
apps/client/src/app/pages/demo/demo-page.component.ts

@ -20,7 +20,7 @@ export class DemoPageComponent implements OnDestroy {
private router: Router, private router: Router,
private tokenStorageService: TokenStorageService private tokenStorageService: TokenStorageService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
} }
public ngOnInit() { public ngOnInit() {

2
apps/client/src/app/pages/features/features-page.component.ts

@ -23,7 +23,7 @@ export class FeaturesPageComponent implements OnDestroy {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
} }
public ngOnInit() { public ngOnInit() {

2
apps/client/src/app/pages/home/home-page.component.ts

@ -35,7 +35,7 @@ export class HomePageComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.userService.stateChanged this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))

2
apps/client/src/app/pages/landing/landing-page.component.ts

@ -73,7 +73,7 @@ export class LandingPageComponent implements OnDestroy, OnInit {
demoAuthToken, demoAuthToken,
globalPermissions, globalPermissions,
statistics statistics
} = this.dataService.getInfo(); } = this.dataService.fetchInfo();
for (const country of countriesOfSubscribers) { for (const country of countriesOfSubscribers) {
this.countriesOfSubscribersMap[country] = { this.countriesOfSubscribersMap[country] = {

2
apps/client/src/app/pages/open/open-page.component.ts

@ -21,7 +21,7 @@ export class OpenPageComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
const { statistics } = this.dataService.getInfo(); const { statistics } = this.dataService.fetchInfo();
this.statistics = statistics; this.statistics = statistics;
} }

2
apps/client/src/app/pages/portfolio/activities/activities-page.component.ts

@ -81,7 +81,7 @@ export class ActivitiesPageComponent implements OnDestroy, OnInit {
} }
public ngOnInit() { public ngOnInit() {
const { globalPermissions } = this.dataService.getInfo(); const { globalPermissions } = this.dataService.fetchInfo();
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;

2
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts

@ -81,7 +81,7 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
this.locale = this.data.user?.settings?.locale; this.locale = this.data.user?.settings?.locale;
this.dateAdapter.setLocale(this.locale); this.dateAdapter.setLocale(this.locale);
const { currencies, platforms, tags } = this.dataService.getInfo(); const { currencies, platforms, tags } = this.dataService.fetchInfo();
this.currencies = currencies; this.currencies = currencies;
this.defaultDateFormat = getDateFormatString(this.locale); this.defaultDateFormat = getDateFormatString(this.locale);

2
apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

@ -73,7 +73,7 @@ export class AnalysisPageComponent implements OnDestroy, OnInit {
private router: Router, private router: Router,
private userService: UserService private userService: UserService
) { ) {
const { benchmarks } = this.dataService.getInfo(); const { benchmarks } = this.dataService.fetchInfo();
this.benchmarks = benchmarks; this.benchmarks = benchmarks;
route.queryParams route.queryParams

2
apps/client/src/app/pages/portfolio/portfolio-page.component.ts

@ -34,7 +34,7 @@ export class PortfolioPageComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.userService.stateChanged this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))

2
apps/client/src/app/pages/pricing/pricing-page.component.ts

@ -41,7 +41,7 @@ export class PricingPageComponent implements OnDestroy, OnInit {
) {} ) {}
public ngOnInit() { public ngOnInit() {
const { baseCurrency, subscriptions } = this.dataService.getInfo(); const { baseCurrency, subscriptions } = this.dataService.fetchInfo();
this.baseCurrency = baseCurrency; this.baseCurrency = baseCurrency;
this.coupon = subscriptions?.default?.coupon; this.coupon = subscriptions?.default?.coupon;

4
apps/client/src/app/pages/register/register-page.component.ts

@ -39,13 +39,13 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
private tokenStorageService: TokenStorageService, private tokenStorageService: TokenStorageService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.getInfo(); this.info = this.dataService.fetchInfo();
this.tokenStorageService.signOut(); this.tokenStorageService.signOut();
} }
public ngOnInit() { public ngOnInit() {
const { demoAuthToken, globalPermissions } = this.dataService.getInfo(); const { demoAuthToken, globalPermissions } = this.dataService.fetchInfo();
this.demoAuthToken = demoAuthToken; this.demoAuthToken = demoAuthToken;
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;

33
apps/client/src/app/services/data.service.ts

@ -43,7 +43,7 @@ import { DataSource, Order as OrderModel } from '@prisma/client';
import { format, parseISO } from 'date-fns'; import { format, parseISO } from 'date-fns';
import { cloneDeep, groupBy, isNumber } from 'lodash'; import { cloneDeep, groupBy, isNumber } from 'lodash';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -193,21 +193,18 @@ export class DataService {
}); });
} }
public fetchInfo(): Observable<InfoItem> { public fetchInfo(): InfoItem {
const info = cloneDeep((window as any).info);
const utmSource = <'ios' | 'trusted-web-activity'>( const utmSource = <'ios' | 'trusted-web-activity'>(
window.localStorage.getItem('utm_source') window.localStorage.getItem('utm_source')
); );
return this.http.get<InfoItem>('/api/v1/info').pipe( info.globalPermissions = filterGlobalPermissions(
take(1), info.globalPermissions,
map((info: InfoItem) => { utmSource
info.globalPermissions = filterGlobalPermissions(
info.globalPermissions,
utmSource
);
return info;
})
); );
return info;
} }
public fetchInvestments({ public fetchInvestments({
@ -394,20 +391,6 @@ export class DataService {
); );
} }
public getInfo(): InfoItem {
const info = cloneDeep((window as any).info);
const utmSource = <'ios' | 'trusted-web-activity'>(
window.localStorage.getItem('utm_source')
);
info.globalPermissions = filterGlobalPermissions(
info.globalPermissions,
utmSource
);
return info;
}
public loginAnonymous(accessToken: string) { public loginAnonymous(accessToken: string) {
return this.http.post<OAuthResponse>(`/api/v1/auth/anonymous`, { return this.http.post<OAuthResponse>(`/api/v1/auth/anonymous`, {
accessToken accessToken

Loading…
Cancel
Save