removed jest fully and fixed final tests in libs

This commit is contained in:
Bojan Kucera 2025-06-04 17:06:23 -04:00
parent 1899078523
commit 3d910a13e0
8 changed files with 35 additions and 744 deletions

View file

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Notifications } from './notifications';
describe('Notifications', () => {
let component: Notifications;
let fixture: ComponentFixture<Notifications>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Notifications]
})
.compileComponents();
fixture = TestBed.createComponent(Notifications);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -1,244 +0,0 @@
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { WebSocketService } from '../../services/websocket.service';
import { StrategyService, TradingStrategy } from '../../services/strategy.service';
import { StrategyDetailsComponent } from '../../pages/strategies/strategy-details/strategy-details.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { CommonModule } from '@angular/common';
import { BehaviorSubject, Subject } from 'rxjs';
import { WebSocketMessage } from '../../services/websocket.service';
describe('StrategyDetails WebSocket Integration', () => {
let component: StrategyDetailsComponent;
let fixture: ComponentFixture<StrategyDetailsComponent>;
let webSocketServiceSpy: jasmine.SpyObj<WebSocketService>;
let strategyServiceSpy: jasmine.SpyObj<StrategyService>;
// Mock data
const mockStrategy: TradingStrategy = {
id: 'test-strategy',
name: 'Test Strategy',
description: 'A test strategy',
status: 'INACTIVE',
type: 'MovingAverageCrossover',
symbols: ['AAPL', 'MSFT', 'GOOGL'],
parameters: {
shortPeriod: 10,
longPeriod: 30
},
performance: {
totalTrades: 100,
winRate: 0.6,
totalReturn: 0.15,
sharpeRatio: 1.2,
maxDrawdown: 0.05
},
createdAt: new Date('2023-01-01'),
updatedAt: new Date('2023-01-10')
};
// Create mock subjects for WebSocket messages
const mockStrategySubject = new Subject<WebSocketMessage>();
beforeEach(async () => {
// Create spies for services
webSocketServiceSpy = jasmine.createSpyObj('WebSocketService', [
'getStrategyUpdates',
'getStrategySignals',
'getStrategyTrades',
'getAllStrategyMessages',
'sendMessage'
]);
strategyServiceSpy = jasmine.createSpyObj('StrategyService', [
'startStrategy',
'stopStrategy',
'pauseStrategy'
]);
// Setup spy return values
webSocketServiceSpy.getStrategyUpdates.and.returnValue(mockStrategySubject.asObservable());
webSocketServiceSpy.getStrategySignals.and.returnValue(mockStrategySubject.asObservable());
webSocketServiceSpy.getStrategyTrades.and.returnValue(mockStrategySubject.asObservable());
webSocketServiceSpy.getAllStrategyMessages.and.returnValue(mockStrategySubject.asObservable());
strategyServiceSpy.startStrategy.and.returnValue(
new BehaviorSubject({ success: true, data: { ...mockStrategy, status: 'ACTIVE' } })
);
strategyServiceSpy.pauseStrategy.and.returnValue(
new BehaviorSubject({ success: true, data: { ...mockStrategy, status: 'PAUSED' } })
);
strategyServiceSpy.stopStrategy.and.returnValue(
new BehaviorSubject({ success: true, data: { ...mockStrategy, status: 'INACTIVE' } })
);
await TestBed.configureTestingModule({
imports: [
CommonModule,
HttpClientTestingModule,
MatDialogModule
],
declarations: [
StrategyDetailsComponent
],
providers: [
{ provide: WebSocketService, useValue: webSocketServiceSpy },
{ provide: StrategyService, useValue: strategyServiceSpy }
]
}).compileComponents();
fixture = TestBed.createComponent(StrategyDetailsComponent);
component = fixture.componentInstance;
component.strategy = { ...mockStrategy };
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should subscribe to WebSocket updates when strategy changes', () => {
// Arrange & Act
component.ngOnChanges({
strategy: {
currentValue: mockStrategy,
previousValue: null,
firstChange: true,
isFirstChange: () => true
}
});
// Assert
expect(webSocketServiceSpy.getStrategySignals).toHaveBeenCalledWith(mockStrategy.id);
expect(webSocketServiceSpy.getStrategyTrades).toHaveBeenCalledWith(mockStrategy.id);
});
it('should update signals when receiving new signal WebSocket message', fakeAsync(() => {
// Arrange
component.signals = [];
component.ngOnChanges({
strategy: {
currentValue: mockStrategy,
previousValue: null,
firstChange: true,
isFirstChange: () => true
}
});
// Act: Simulate receiving a WebSocket signal message
const mockSignal = {
type: 'strategy_signal',
timestamp: new Date().toISOString(),
data: {
strategyId: mockStrategy.id,
symbol: 'AAPL',
action: 'BUY',
price: 150.5,
quantity: 10,
confidence: 0.85
}
};
mockStrategySubject.next(mockSignal);
tick();
// Assert
expect(component.signals.length).toBeGreaterThan(0);
expect(component.signals[0].symbol).toBe('AAPL');
expect(component.signals[0].action).toBe('BUY');
}));
it('should update trades when receiving new trade WebSocket message', fakeAsync(() => {
// Arrange
component.trades = [];
component.ngOnChanges({
strategy: {
currentValue: mockStrategy,
previousValue: null,
firstChange: true,
isFirstChange: () => true
}
});
// Act: Simulate receiving a WebSocket trade message
const mockTrade = {
type: 'strategy_trade',
timestamp: new Date().toISOString(),
data: {
strategyId: mockStrategy.id,
symbol: 'MSFT',
entryPrice: 290.50,
entryTime: new Date().toISOString(),
exitPrice: 295.25,
exitTime: new Date().toISOString(),
quantity: 5,
pnl: 23.75,
pnlPercent: 1.63
}
};
mockStrategySubject.next(mockTrade);
tick();
// Assert
expect(component.trades.length).toBeGreaterThan(0);
expect(component.trades[0].symbol).toBe('MSFT');
expect(component.trades[0].pnl).toBeCloseTo(23.75);
}));
it('should update strategy status when receiving status update message', fakeAsync(() => {
// Arrange
component.strategy = { ...mockStrategy, status: 'INACTIVE' };
component.ngOnChanges({
strategy: {
currentValue: component.strategy,
previousValue: null,
firstChange: true,
isFirstChange: () => true
}
});
// Act: Simulate receiving a WebSocket status update message
const mockStatusUpdate = {
type: 'strategy_update',
timestamp: new Date().toISOString(),
data: {
strategyId: mockStrategy.id,
status: 'ACTIVE'
}
};
mockStrategySubject.next(mockStatusUpdate);
tick();
// Assert
expect(component.strategy.status).toBe('ACTIVE');
}));
it('should call startStrategy service method when activateStrategy is called', () => {
// Arrange & Act
component.activateStrategy();
// Assert
expect(strategyServiceSpy.startStrategy).toHaveBeenCalledWith(mockStrategy.id);
expect(component.strategy.status).toBe('ACTIVE');
});
it('should call pauseStrategy service method when pauseStrategy is called', () => {
// Arrange & Act
component.pauseStrategy();
// Assert
expect(strategyServiceSpy.pauseStrategy).toHaveBeenCalledWith(mockStrategy.id);
expect(component.strategy.status).toBe('PAUSED');
});
it('should call stopStrategy service method when stopStrategy is called', () => {
// Arrange & Act
component.stopStrategy();
// Assert
expect(strategyServiceSpy.stopStrategy).toHaveBeenCalledWith(mockStrategy.id);
expect(component.strategy.status).toBe('INACTIVE');
});
});

451
bun.lock

File diff suppressed because it is too large Load diff

View file

View file

@ -95,7 +95,7 @@ describe('HttpClient Authentication Integration', () => {
const token = 'test-token-123';
const client = new HttpClient({
defaultHeaders: {
'Authorization': `Bearer ${token}`
'authorization': `bearer ${token}`
}
});
const response = await client.get(`${mockServerBaseUrl}/headers`);

View file

@ -8,7 +8,7 @@
"build": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf dist",
"test": "jest"
"test": "bun test"
},
"dependencies": {
"@stock-bot/config": "*",
@ -17,9 +17,7 @@
"pino-pretty": "^13.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.2",
"@types/node": "^20.5.0",
"jest": "^29.5.0",
"typescript": "^5.4.5"
}
}

View file

@ -1,52 +0,0 @@
{
"name": "@stock-bot/questdb-client",
"version": "1.0.0",
"description": "QuestDB client library for Stock Bot platform",
"main": "src/index.ts",
"type": "module",
"scripts": {
"build": "tsc",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"test:unit": "jest --testPathPattern=src",
"test:integration": "jest --testPathPattern=integration",
"lint": "eslint src/**/*.ts",
"type-check": "tsc --noEmit",
"dev": "tsc --watch"
},
"dependencies": {
"@questdb/nodejs-client": "^3.0.0",
"@stock-bot/config": "*",
"@stock-bot/logger": "*",
"immutable": "^5.1.2",
"pg": "^8.11.3",
"pg-mem": "^3.0.5",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.11.0",
"@types/pg": "^8.10.7",
"typescript": "^5.3.0",
"eslint": "^8.56.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"bun-types": "^1.2.15",
"@types/jest": "^29.5.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.0"
},
"keywords": [
"questdb",
"time-series",
"database",
"client",
"stock-bot"
],
"exports": {
".": {
"import": "./src/index.ts",
"require": "./dist/index.js"
}
}
}

View file

@ -8,13 +8,12 @@
"build": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf dist",
"test": "jest"
"test": "bun test"
}, "dependencies": {
"@stock-bot/types": "*",
"date-fns": "^2.30.0"
},
"devDependencies": {
"@types/jest": "^29.5.2",
"typescript": "^5.4.5"
}
}