Refactor API and enhance Angular integration
- Removed `ciTargetName` from `nx.json`. - Updated `package.json` to include new dependencies: `@types/seedrandom`, `fast-check`, `happy-dom`, and `@nestjs/schedule`. - Modified `pnpm-lock.yaml` to reflect the addition of new packages and their versions. - Improved project documentation in `PROJECT_CONTEXT.md` to clarify the use of Zod schemas and Angular framework decisions. - Introduced new Angular components and patterns in the `.agents/skills/frontend-angular` directory, including examples and reference materials for Angular 21+ features.
This commit is contained in:
78
apps/overlay/src/app/ebs/ebs-api.service.spec.ts
Normal file
78
apps/overlay/src/app/ebs/ebs-api.service.spec.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import {
|
||||
HttpTestingController,
|
||||
provideHttpClientTesting,
|
||||
} from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { EbsApiService, EBS_BASE_URL } from './ebs-api.service';
|
||||
|
||||
const BASE = 'https://test.local';
|
||||
|
||||
describe('EbsApiService', () => {
|
||||
let service: EbsApiService;
|
||||
let controller: HttpTestingController;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
provideHttpClient(),
|
||||
provideHttpClientTesting(),
|
||||
{ provide: EBS_BASE_URL, useValue: BASE },
|
||||
],
|
||||
});
|
||||
service = TestBed.inject(EbsApiService);
|
||||
controller = TestBed.inject(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => controller.verify());
|
||||
|
||||
describe('getMissionState', () => {
|
||||
it('GETs /missions/state and returns null for no active mission', () => {
|
||||
let result: unknown;
|
||||
service.getMissionState().subscribe((v) => (result = v));
|
||||
|
||||
controller.expectOne(`${BASE}/missions/state`).flush(null);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('throws ZodError when server returns invalid shape', () => {
|
||||
let error: unknown;
|
||||
service.getMissionState().subscribe({ error: (e) => (error = e) });
|
||||
|
||||
controller.expectOne(`${BASE}/missions/state`).flush({ bad: 'data' });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('startMission', () => {
|
||||
it('POSTs to /missions/start with difficulty', () => {
|
||||
service.startMission({ difficulty: 2 }).subscribe({ error: () => undefined });
|
||||
|
||||
const req = controller.expectOne(`${BASE}/missions/start`);
|
||||
expect(req.request.method).toBe('POST');
|
||||
expect(req.request.body).toEqual({ difficulty: 2 });
|
||||
req.flush({ bad: 'shape' });
|
||||
});
|
||||
|
||||
it('throws ZodError for invalid difficulty before sending request', () => {
|
||||
expect(() => service.startMission({ difficulty: 99 })).toThrow();
|
||||
controller.expectNone(`${BASE}/missions/start`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('choosePerk', () => {
|
||||
it('POSTs to /missions/choose-perk with perkKey', () => {
|
||||
service.choosePerk({ perkKey: 'iron_will' }).subscribe({ error: () => undefined });
|
||||
|
||||
const req = controller.expectOne(`${BASE}/missions/choose-perk`);
|
||||
expect(req.request.method).toBe('POST');
|
||||
expect(req.request.body).toEqual({ perkKey: 'iron_will' });
|
||||
req.flush({ bad: 'shape' });
|
||||
});
|
||||
|
||||
it('throws ZodError for empty perkKey before sending request', () => {
|
||||
expect(() => service.choosePerk({ perkKey: '' })).toThrow();
|
||||
controller.expectNone(`${BASE}/missions/choose-perk`);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user