Skip to content

Commit

Permalink
NAS-132644: More websocket renaming (#11077)
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft authored Nov 21, 2024
1 parent 64cc717 commit 5a65278
Show file tree
Hide file tree
Showing 138 changed files with 353 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const dummyAlert = {

describe('AlertComponent', () => {
let spectator: Spectator<AlertComponent>;
let websocket: ApiService;
let api: ApiService;
let alert: AlertPageObject;
const createComponent = createComponentFactory({
component: AlertComponent,
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('AlertComponent', () => {
},
});

websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
alert = new AlertPageObject(spectator);
});

Expand Down Expand Up @@ -103,7 +103,7 @@ describe('AlertComponent', () => {
it('dismisses an open alert when Dismiss link is pressed', async () => {
alert.clickDismissLink();

expect(websocket.call).toHaveBeenCalledWith('alert.dismiss', ['79']);
expect(api.call).toHaveBeenCalledWith('alert.dismiss', ['79']);

const state = await firstValueFrom(spectator.inject(Store).pipe(map(selectAlerts)));
expect(state).toEqual([
Expand All @@ -122,7 +122,7 @@ describe('AlertComponent', () => {

alert.clickReopenLink();

expect(websocket.call).toHaveBeenCalledWith('alert.restore', ['79']);
expect(api.call).toHaveBeenCalledWith('alert.restore', ['79']);

const state = await firstValueFrom(spectator.inject(Store).pipe(map(selectAlerts)));
expect(state).toEqual([dummyAlert]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const dismissedAlerts = [

describe('AlertsPanelComponent', () => {
let spectator: Spectator<AlertsPanelComponent>;
let websocket: ApiService;
let api: ApiService;
let alertPanel: AlertsPanelPageObject;

const createComponent = createComponentFactory({
Expand Down Expand Up @@ -100,14 +100,14 @@ describe('AlertsPanelComponent', () => {
beforeEach(() => {
spectator = createComponent();

websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
alertPanel = new AlertsPanelPageObject(spectator);
});

it('loads alerts when adminUiInitialized is dispatched', () => {
spectator.inject(Store).dispatch(adminUiInitialized());

expect(websocket.call).toHaveBeenCalledWith('alert.list');
expect(api.call).toHaveBeenCalledWith('alert.list');
});

it('selects HA status from store and passes it to the ix-alert', () => {
Expand All @@ -134,8 +134,8 @@ describe('AlertsPanelComponent', () => {
it('dismisses all alerts when Dismiss All Alerts is pressed', () => {
spectator.click(alertPanel.dismissAllButton);

expect(websocket.call).toHaveBeenCalledWith('alert.dismiss', ['1']);
expect(websocket.call).toHaveBeenCalledWith('alert.dismiss', ['2']);
expect(api.call).toHaveBeenCalledWith('alert.dismiss', ['1']);
expect(api.call).toHaveBeenCalledWith('alert.dismiss', ['2']);

expect(alertPanel.dismissAllButton).not.toExist();

Expand All @@ -146,8 +146,8 @@ describe('AlertsPanelComponent', () => {
it('reopens all alerts when Reopen All Alerts is pressed', () => {
spectator.click(alertPanel.reopenAllButton);

expect(websocket.call).toHaveBeenCalledWith('alert.restore', ['3']);
expect(websocket.call).toHaveBeenCalledWith('alert.restore', ['4']);
expect(api.call).toHaveBeenCalledWith('alert.restore', ['3']);
expect(api.call).toHaveBeenCalledWith('alert.restore', ['4']);

expect(alertPanel.reopenAllButton).not.toExist();

Expand Down Expand Up @@ -196,6 +196,6 @@ describe('AlertsPanelComponent', () => {

it('calls alert.list when alerts panel is open', () => {
spectator.inject(Store).dispatch(alertIndicatorPressed());
expect(websocket.call).toHaveBeenCalledWith('alert.list');
expect(api.call).toHaveBeenCalledWith('alert.list');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class FileTicketLicensedComponent {
untilDestroyed(this),
).subscribe({
next: (createdTicket) => this.onSuccess(createdTicket.url),
error: (error) => this.formErrorHandler.handleWsFormError(error, this.form),
error: (error) => this.formErrorHandler.handleValidationErrors(error, this.form),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class FileTicketComponent {
untilDestroyed(this),
).subscribe({
next: (createdTicket) => this.onSuccess(createdTicket.url),
error: (error) => this.formErrorHandler.handleWsFormError(error, this.form),
error: (error) => this.formErrorHandler.handleValidationErrors(error, this.form),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('FormErrorHandlerService', () => {
jest.spyOn(formGroup.controls.test_control_1, 'setErrors').mockImplementation();
jest.spyOn(formGroup.controls.test_control_1, 'markAsTouched').mockImplementation();

spectator.service.handleWsFormError(fakeError, formGroup);
spectator.service.handleValidationErrors(fakeError, formGroup);

expect(formGroup.controls.test_control_1.setErrors).toHaveBeenCalledWith({
ixManualValidateError: {
Expand All @@ -77,7 +77,7 @@ describe('FormErrorHandlerService', () => {
});

it('shows error dialog and error message in logs when control is not found', () => {
spectator.service.handleWsFormError(fakeError, formGroup);
spectator.service.handleValidationErrors(fakeError, formGroup);

expect(console.error).not.toHaveBeenCalledWith('Could not find control test_control_1.');
expect(console.error).toHaveBeenCalledWith('Could not find control test_control_2.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FormErrorHandlerService {
* @param fieldsMap Overrides backend field names with frontend field names.
* TODO: See if second `string` in fieldsMap can be typed to key of formGroup.
*/
handleWsFormError(
handleValidationErrors(
error: unknown,
formGroup: UntypedFormGroup,
fieldsMap: Record<string, string> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const transientRunningJob = {

describe('JobsPanelComponent', () => {
let spectator: Spectator<JobsPanelComponent>;
let websocket: ApiService;
let api: ApiService;
let loader: HarnessLoader;
let jobPanel: JobsPanelPageObject;

Expand Down Expand Up @@ -115,19 +115,19 @@ describe('JobsPanelComponent', () => {

beforeEach(() => {
spectator = createComponent();
websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
loader = TestbedHarnessEnvironment.loader(spectator.fixture);
jobPanel = new JobsPanelPageObject(spectator);
});

it('loads jobs when adminUiInitialized is dispatched', () => {
spectator.inject(Store).dispatch(adminUiInitialized());

expect(websocket.call).toHaveBeenCalledWith(
expect(api.call).toHaveBeenCalledWith(
'core.get_jobs',
[[['state', '!=', JobState.Success]]],
);
expect(websocket.call).toHaveBeenCalledWith(
expect(api.call).toHaveBeenCalledWith(
'core.get_jobs',
[[['state', '=', JobState.Success]], { limit: 30, order_by: ['-id'] }],
);
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('JobsPanelComponent', () => {
const abortButton = spectator.query('.job-button-abort');
spectator.click(abortButton);

expect(websocket.call).toHaveBeenCalledWith('core.job_abort', [1]);
expect(api.call).toHaveBeenCalledWith('core.job_abort', [1]);
});

it('checks redirect when "History" button is pressed', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ApiService } from 'app/services/websocket/api.service';
describe('ChangePasswordDialogComponent', () => {
let spectator: Spectator<ChangePasswordDialogComponent>;
let loader: HarnessLoader;
let websocket: ApiService;
let api: ApiService;
const createComponent = createComponentFactory({
component: ChangePasswordDialogComponent,
imports: [
Expand All @@ -36,7 +36,7 @@ describe('ChangePasswordDialogComponent', () => {
beforeEach(() => {
spectator = createComponent();
loader = TestbedHarnessEnvironment.loader(spectator.fixture);
websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
});

it('does not show current password field for full admin', async () => {
Expand All @@ -61,7 +61,7 @@ describe('ChangePasswordDialogComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();

expect(websocket.call).toHaveBeenCalledWith('user.set_password', [{
expect(api.call).toHaveBeenCalledWith('user.set_password', [{
old_password: 'correct',
new_password: '123456',
username: 'root',
Expand All @@ -74,7 +74,7 @@ describe('ChangePasswordDialogComponent', () => {
authMock.setRoles([Role.ReadonlyAdmin]);

const error = new Error('error');
jest.spyOn(websocket, 'call').mockReturnValue(throwError(() => error));
jest.spyOn(api, 'call').mockReturnValue(throwError(() => error));

const form = await loader.getHarness(IxFormHarness);
await form.fillForm({
Expand All @@ -86,7 +86,7 @@ describe('ChangePasswordDialogComponent', () => {
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' }));
await saveButton.click();

expect(spectator.inject(FormErrorHandlerService).handleWsFormError)
expect(spectator.inject(FormErrorHandlerService).handleValidationErrors)
.toHaveBeenCalledWith(error, expect.any(FormGroup));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ChangePasswordDialogComponent {
this.dialogRef.close();
},
error: (error: unknown) => {
this.formErrorHandler.handleWsFormError(error, this.form);
this.formErrorHandler.handleValidationErrors(error, this.form);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApiService } from 'app/services/websocket/api.service';

describe('AppResourcesCardComponent', () => {
let spectator: Spectator<AppResourcesCardComponent>;
let websocket: ApiService;
let api: ApiService;

const createComponent = createComponentFactory({
component: AppResourcesCardComponent,
Expand All @@ -32,23 +32,23 @@ describe('AppResourcesCardComponent', () => {
isLoading: false,
},
});
websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
});

it('shows header', () => {
expect(spectator.query('h3')).toHaveText('Available Resources');
});

it('shows information about available resources', () => {
expect(websocket.subscribe).toHaveBeenCalledWith('reporting.realtime');
expect(api.subscribe).toHaveBeenCalledWith('reporting.realtime');

expect(spectator.queryAll('.app-list-item')[0]).toHaveText('CPU Usage:0% Avg. Usage');
expect(spectator.queryAll('.app-list-item')[1]).toHaveText('Memory Usage: N/A');
expect(spectator.queryAll('.app-list-item')[2]).toHaveText('Pool: pool');
});

it('loads and reports available space on apps dataset', () => {
expect(websocket.call).toHaveBeenCalledWith('app.available_space');
expect(api.call).toHaveBeenCalledWith('app.available_space');
expect(spectator.queryAll('.app-list-item')[3]).toHaveText('Available Space: 2.44 KiB');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class AppsSettingsComponent implements OnInit {
},
error: (error: unknown) => {
this.isFormLoading.set(false);
this.errorHandler.handleWsFormError(error, this.form);
this.errorHandler.handleValidationErrors(error, this.form);
},
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/pages/apps/store/docker.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ describe('DockerStore', () => {
enable_image_updates: false,
} as DockerConfig;

const mockWebsocket = spectator.inject(MockApiService);
const mockedApi = spectator.inject(MockApiService);
jest.resetAllMocks();
mockWebsocket.mockCall('docker.config', newDockerConfig);
mockedApi.mockCall('docker.config', newDockerConfig);

spectator.service.reloadDockerConfig().subscribe();
spectator.service.reloadDockerNvidiaStatus().subscribe();

expect(mockWebsocket.call).toHaveBeenCalledWith('docker.config');
expect(mockedApi.call).toHaveBeenCalledWith('docker.config');
expect(spectator.service.state().dockerConfig).toEqual(newDockerConfig);
});
});

describe('reloadDockerNvidiaStatus', () => {
it('reloads docker nvidia status and updates the state', () => {
const mockWebsocket = spectator.inject(MockApiService);
const mockedApi = spectator.inject(MockApiService);
jest.resetAllMocks();
mockWebsocket.mockCall('docker.nvidia_status', { status: DockerNvidiaStatus.Installed });
mockedApi.mockCall('docker.nvidia_status', { status: DockerNvidiaStatus.Installed });

spectator.service.reloadDockerConfig().subscribe();
spectator.service.reloadDockerNvidiaStatus().subscribe();

expect(mockWebsocket.call).toHaveBeenCalledWith('docker.nvidia_status');
expect(mockedApi.call).toHaveBeenCalledWith('docker.nvidia_status');
expect(spectator.service.state().nvidiaStatus).toEqual(DockerNvidiaStatus.Installed);
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/app/pages/audit/audit.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { selectAdvancedConfig } from 'app/store/system-config/system-config.sele

describe('AuditComponent', () => {
let spectator: Spectator<AuditComponent>;
let websocket: ApiService;
let api: ApiService;
let table: IxTableHarness;

const auditEntries = [
Expand Down Expand Up @@ -112,13 +112,13 @@ describe('AuditComponent', () => {

beforeEach(async () => {
spectator = createComponent();
websocket = spectator.inject(ApiService);
api = spectator.inject(ApiService);
// Do it in this weird way because table header is outside the table element.
table = await TestbedHarnessEnvironment.harnessForFixture(spectator.fixture, IxTableHarness);
});

it('loads and shows a table with audit entries', async () => {
expect(websocket.call).toHaveBeenCalledWith(
expect(api.call).toHaveBeenCalledWith(
'audit.query',
[{ 'query-filters': [], 'query-options': { limit: 50, offset: 0, order_by: ['-message_timestamp'] } }],
);
Expand All @@ -141,7 +141,7 @@ describe('AuditComponent', () => {

search.runSearch.emit();

expect(websocket.call).toHaveBeenLastCalledWith(
expect(api.call).toHaveBeenLastCalledWith(
'audit.query',
[{
'query-filters': [['OR', [['event', '~', '(?i)search'], ['username', '~', '(?i)search'], ['service', '~', '(?i)search']]]],
Expand All @@ -155,7 +155,7 @@ describe('AuditComponent', () => {
spectator.component.controllerTypeChanged({ value: ControllerType.Standby } as MatButtonToggleChange);
spectator.detectChanges();

expect(websocket.call).toHaveBeenLastCalledWith(
expect(api.call).toHaveBeenLastCalledWith(
'audit.query',
[{
'query-filters': [],
Expand All @@ -176,7 +176,7 @@ describe('AuditComponent', () => {
};
search.runSearch.emit();

expect(websocket.call).toHaveBeenLastCalledWith(
expect(api.call).toHaveBeenLastCalledWith(
'audit.query',
[{
'query-filters': [['event', '=', 'Authentication'], ['username', '~', 'bob']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class CloudCredentialsFormComponent implements OnInit {
error: (error: unknown) => {
// TODO: Errors for nested provider form will be shown in a modal. Can be improved.
this.isLoading = false;
this.formErrorHandler.handleWsFormError(error, this.commonForm);
this.formErrorHandler.handleValidationErrors(error, this.commonForm);
this.cdr.markForCheck();
},
});
Expand Down Expand Up @@ -209,7 +209,7 @@ export class CloudCredentialsFormComponent implements OnInit {
},
error: (error: unknown) => {
this.isLoading = false;
this.formErrorHandler.handleWsFormError(error, this.commonForm);
this.formErrorHandler.handleValidationErrors(error, this.commonForm);
this.cdr.markForCheck();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ describe('SftpProviderFormComponent', () => {

await lastValueFrom(spectator.component.beforeSubmit());

const websocket = spectator.inject(ApiService);
expect(websocket.call).toHaveBeenCalledWith('keychaincredential.generate_ssh_key_pair');
expect(websocket.call).toHaveBeenCalledWith('keychaincredential.create', [{
const api = spectator.inject(ApiService);
expect(api.call).toHaveBeenCalledWith('keychaincredential.generate_ssh_key_pair');
expect(api.call).toHaveBeenCalledWith('keychaincredential.create', [{
attributes: {
private_key: 'private key',
public_key: 'public key',
Expand Down
Loading

0 comments on commit 5a65278

Please sign in to comment.