Emit canonical platform context preference payload
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PlatformContextStore } from './platform-context.store';
|
||||
|
||||
describe('PlatformContextStore', () => {
|
||||
let store: PlatformContextStore;
|
||||
let httpMock: HttpTestingController;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
PlatformContextStore,
|
||||
provideHttpClient(withInterceptorsFromDi()),
|
||||
provideHttpClientTesting(),
|
||||
],
|
||||
});
|
||||
|
||||
store = TestBed.inject(PlatformContextStore);
|
||||
httpMock = TestBed.inject(HttpTestingController);
|
||||
|
||||
(store as any).apiDisabled = false;
|
||||
(store as any).persistPaused = false;
|
||||
store.error.set(null);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
it('persists only the canonical Platform context payload fields', () => {
|
||||
store.selectedRegions.set(['us-east']);
|
||||
store.selectedEnvironments.set(['dev']);
|
||||
store.timeWindow.set('24h');
|
||||
store.stage.set('all');
|
||||
store.tenantId.set('demo-prod');
|
||||
|
||||
(store as any).persistPreferences();
|
||||
|
||||
const req = httpMock.expectOne('/api/v2/context/preferences');
|
||||
expect(req.request.method).toBe('PUT');
|
||||
expect(req.request.body).toEqual({
|
||||
regions: ['us-east'],
|
||||
environments: ['dev'],
|
||||
timeWindow: '24h',
|
||||
});
|
||||
expect(req.request.body.tenantId).toBeUndefined();
|
||||
expect(req.request.body.stage).toBeUndefined();
|
||||
|
||||
req.flush({
|
||||
tenantId: 'demo-prod',
|
||||
actorId: 'context-tests',
|
||||
regions: ['us-east'],
|
||||
environments: ['dev'],
|
||||
timeWindow: '24h',
|
||||
updatedAt: '2026-03-07T00:00:00Z',
|
||||
updatedBy: 'context-tests',
|
||||
});
|
||||
});
|
||||
|
||||
it('persists environment-only query scope without unsupported fields', () => {
|
||||
store.initialized.set(true);
|
||||
store.environments.set([
|
||||
{
|
||||
environmentId: 'dev',
|
||||
regionId: 'us-east',
|
||||
environmentType: 'development',
|
||||
displayName: 'Development',
|
||||
sortOrder: 10,
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
store.applyScopeQueryParams({ environment: 'dev' });
|
||||
|
||||
const req = httpMock.expectOne('/api/v2/context/preferences');
|
||||
expect(req.request.method).toBe('PUT');
|
||||
expect(req.request.body).toEqual({
|
||||
regions: [],
|
||||
environments: ['dev'],
|
||||
timeWindow: '24h',
|
||||
});
|
||||
expect(req.request.body.tenantId).toBeUndefined();
|
||||
expect(req.request.body.stage).toBeUndefined();
|
||||
|
||||
req.flush({
|
||||
tenantId: 'demo-prod',
|
||||
actorId: 'context-tests',
|
||||
regions: ['us-east', 'eu-west', 'apac'],
|
||||
environments: ['dev'],
|
||||
timeWindow: '24h',
|
||||
updatedAt: '2026-03-07T00:00:00Z',
|
||||
updatedBy: 'context-tests',
|
||||
});
|
||||
|
||||
expect(store.selectedEnvironments()).toEqual(['dev']);
|
||||
expect(store.error()).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -45,6 +45,12 @@ interface PlatformContextQueryState {
|
||||
stage: string;
|
||||
}
|
||||
|
||||
interface PlatformContextPreferencesRequestPayload {
|
||||
regions: string[];
|
||||
environments: string[];
|
||||
timeWindow: string;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PlatformContextStore {
|
||||
private readonly http = inject(HttpClient);
|
||||
@@ -378,13 +384,7 @@ export class PlatformContextStore {
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
tenantId: this.tenantId(),
|
||||
regions: this.selectedRegions(),
|
||||
environments: this.selectedEnvironments(),
|
||||
timeWindow: this.timeWindow(),
|
||||
stage: this.stage(),
|
||||
};
|
||||
const payload = this.buildPreferencesPayload();
|
||||
|
||||
this.http
|
||||
.put<PlatformContextPreferences>('/api/v2/context/preferences', payload)
|
||||
@@ -396,6 +396,14 @@ export class PlatformContextStore {
|
||||
});
|
||||
}
|
||||
|
||||
private buildPreferencesPayload(): PlatformContextPreferencesRequestPayload {
|
||||
return {
|
||||
regions: this.selectedRegions(),
|
||||
environments: this.selectedEnvironments(),
|
||||
timeWindow: this.timeWindow(),
|
||||
};
|
||||
}
|
||||
|
||||
private finishInitialization(): void {
|
||||
this.loading.set(false);
|
||||
this.initialized.set(true);
|
||||
|
||||
Reference in New Issue
Block a user