Skip to content

Commit

Permalink
NAS-131557: Rename mockWebsocket to mockApi
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 committed Nov 13, 2024
1 parent 8b1f809 commit 64eb9f6
Show file tree
Hide file tree
Showing 342 changed files with 691 additions and 691 deletions.
18 changes: 9 additions & 9 deletions src/app/core/testing/utils/mock-websocket.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import { ApiService } from 'app/services/api.service';
import { WebSocketConnectionService } from 'app/services/websocket-connection.service';

/**
* This is a sugar syntax for creating simple websocket mocks.
* This is a sugar syntax for creating simple api mocks.
* @example
* providers: [
* mockWebSocket([
* mockApi([
* mockCall('filesystem.stat': { gid: 0 } as FileSystemStat),
* mockCall('filesystem.stat', () => ({ gid: 0 } as FileSystemStat)),
* mockJob('filesystem.setacl', fakeSuccessfulJob()),
* ...
* }),
* ]
*
* It also makes available MockWebSocketService, which allows customizing calls on the fly.
* It also makes available MockApiService, which allows customizing calls on the fly.
*
* If you need more customization, use ordinary mockProvider().
* @example
* providers: [
* mockProvider(WebSocketService, {
* mockProvider(ApiService, {
* call: jest.fn((method) => {
* if (method === 'filesystem.stat') {
* return of({ user: 'john' } as FileSystemStat);
Expand All @@ -42,25 +42,25 @@ import { WebSocketConnectionService } from 'app/services/websocket-connection.se
* ]
*/

export function mockWebSocket(
export function mockApi(
mockResponses?: (MockApiCallResponse | MockApiJobResponse)[],
): (FactoryProvider | ExistingProvider | ValueProvider)[] {
return [
{
provide: ApiService,
useFactory: (router: Router, wsManager: WebSocketConnectionService, translate: TranslateService) => {
const mockWebSocketService = new MockWebSocketService(router, wsManager, translate);
const mockApiService = new MockWebSocketService(router, wsManager, translate);
(mockResponses || []).forEach((mockResponse) => {
if (mockResponse.type === MockApiResponseType.Call) {
mockWebSocketService.mockCall(mockResponse.method, mockResponse.response);
mockApiService.mockCall(mockResponse.method, mockResponse.response);
} else if (mockResponse.type === MockApiResponseType.Job) {
mockWebSocketService.mockJob(
mockApiService.mockJob(
mockResponse.method,
mockResponse.response as Job<ApiJobDirectory[ApiJobMethod]['response']>,
);
}
});
return mockWebSocketService;
return mockApiService;
},
deps: [Router, WebSocketConnectionService, TranslateService],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { firstValueFrom } from 'rxjs';
import { map } from 'rxjs/operators';
import { FakeFormatDateTimePipe } from 'app/core/testing/classes/fake-format-datetime.pipe';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { AlertLevel } from 'app/enums/alert-level.enum';
import { Alert } from 'app/interfaces/alert.interface';
import { AlertComponent } from 'app/modules/alerts/components/alert/alert.component';
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('AlertComponent', () => {
],
providers: [
mockAuth(),
mockWebSocket([
mockApi([
mockCall('alert.dismiss'),
mockCall('alert.restore'),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Store, StoreModule } from '@ngrx/store';
import { MockComponent } from 'ng-mocks';
import { MockWebSocketService } from 'app/core/testing/classes/mock-websocket.service';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { LetDirective } from 'app/directives/app-let.directive';
import { NavigateAndInteractDirective } from 'app/directives/navigate-and-interact/navigate-and-interact.directive';
import { AlertLevel } from 'app/enums/alert-level.enum';
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('AlertsPanelComponent', () => {
],
providers: [
mockAuth(),
mockWebSocket([
mockApi([
mockCall('alert.list', [...unreadAlerts, ...dismissedAlerts]),
mockCall('alert.dismiss'),
mockCall('alert.restore'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatButtonHarness } from '@angular/material/button/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { provideMockStore } from '@ngrx/store/testing';
import { mockCall, mockJob, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockJob, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { ControllerType } from 'app/enums/controller-type.enum';
import { JobState } from 'app/enums/job-state.enum';
import { ApiJobMethod } from 'app/interfaces/api/api-job-directory.interface';
Expand All @@ -25,7 +25,7 @@ describe('ExportButtonComponent', () => {
const createComponent = createComponentFactory({
component: ExportButtonComponent<EntryType, typeof jobMethod>,
providers: [
mockWebSocket([
mockApi([
mockJob(jobMethod, { result: '/path/data.csv', state: JobState.Success } as Job<string>),
mockCall('core.download', [33456, '/_download/33456?auth_token=1234567890']),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MatDialogHarness } from '@angular/material/dialog/testing';
import { MatProgressBarHarness } from '@angular/material/progress-bar/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { BehaviorSubject, of } from 'rxjs';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { JobState } from 'app/enums/job-state.enum';
import { Job } from 'app/interfaces/job.interface';
import {
Expand All @@ -24,7 +24,7 @@ describe('JobProgressDialogComponent', () => {
const createComponent = createComponentFactory({
component: JobProgressDialogComponent<unknown>,
providers: [
mockWebSocket([
mockApi([
mockCall('core.job_abort', null),
]),
mockProvider(MatDialogRef),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MatButtonHarness } from '@angular/material/button/testing';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { MockComponent } from 'ng-mocks';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { Job } from 'app/interfaces/job.interface';
import { CopyButtonComponent } from 'app/modules/buttons/copy-button/copy-button.component';
import { ShowLogsDialogComponent } from 'app/modules/dialog/components/show-logs-dialog/show-logs-dialog.component';
Expand All @@ -26,7 +26,7 @@ describe('ShowLogsDialogComponent', () => {
mockProvider(DownloadService, {
downloadUrl: jest.fn(),
}),
mockWebSocket([
mockApi([
mockCall('core.job_download_logs', 'http://localhost/download/log'),
]),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectat
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { Subject } from 'rxjs';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { ServiceName } from 'app/enums/service-name.enum';
import { ServiceStatus } from 'app/enums/service-status.enum';
import { Service } from 'app/interfaces/service.interface';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('StartServiceDialogComponent', () => {
],
providers: [
mockAuth(),
mockWebSocket([
mockApi([
mockCall('service.update'),
mockCall('service.start'),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { fakeFile } from 'app/core/testing/utils/fake-file.uitls';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { mockWindow } from 'app/core/testing/utils/mock-window.utils';
import { TicketCategory, TicketCriticality, TicketEnvironment } from 'app/enums/file-ticket.enum';
import { WINDOW } from 'app/helpers/window.helper';
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('FileTicketLicensedFormComponent', () => {
navigate: jest.fn(() => Promise.resolve(true)),
}),
mockWindow(),
mockWebSocket([
mockApi([
mockCall('support.attach_ticket_max_size', 5),
]),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { fakeFile } from 'app/core/testing/utils/fake-file.uitls';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { OauthButtonType } from 'app/modules/buttons/oauth-button/interfaces/oauth-button.interface';
import { OauthButtonComponent } from 'app/modules/buttons/oauth-button/oauth-button.component';
import { FileTicketComponent } from 'app/modules/feedback/components/file-ticket/file-ticket.component';
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('FileTicketComponent', () => {
mockProvider(ImageValidatorService, {
getImagesValidator: () => () => of(null as ValidationErrors),
}),
mockWebSocket([
mockApi([
mockCall('support.attach_ticket_max_size', 5),
]),
],
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/feedback/services/feedback.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { provideMockStore } from '@ngrx/store/testing';
import { lastValueFrom, of } from 'rxjs';
import { fakeFile } from 'app/core/testing/utils/fake-file.uitls';
import { fakeSuccessfulJob } from 'app/core/testing/utils/fake-job.utils';
import { mockCall, mockJob, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockJob, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { mockWindow } from 'app/core/testing/utils/mock-window.utils';
import {
TicketCategory, TicketCriticality, TicketEnvironment, TicketType,
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('FeedbackService', () => {
const createService = createServiceFactory({
service: FeedbackService,
providers: [
mockWebSocket([
mockApi([
mockJob('support.new_ticket', fakeSuccessfulJob(newTicket)),
mockCall('system.host_id', 'testHostId'),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MatButtonHarness } from '@angular/material/button/testing';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { DatasetAclType, DatasetCaseSensitivity } from 'app/enums/dataset.enum';
import { Dataset, DatasetCreate } from 'app/interfaces/dataset.interface';
import { CreateDatasetDialogComponent } from 'app/modules/forms/ix-forms/components/ix-explorer/create-dataset-dialog/create-dataset-dialog.component';
Expand All @@ -23,7 +23,7 @@ describe('CreateDatasetDialogComponent', () => {
],
providers: [
mockAuth(),
mockWebSocket([
mockApi([
mockCall('pool.dataset.query', [{
name: 'parent_name',
casesensitivity: { value: DatasetCaseSensitivity.Sensitive },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EffectsModule } from '@ngrx/effects';
import { Store, StoreModule } from '@ngrx/store';
import { of } from 'rxjs';
import { FakeFormatDateTimePipe } from 'app/core/testing/classes/fake-format-datetime.pipe';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { LetDirective } from 'app/directives/app-let.directive';
import { JobState } from 'app/enums/job-state.enum';
import { Job } from 'app/interfaces/job.interface';
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('JobsPanelComponent', () => {
afterClosed: () => of(undefined),
})),
}),
mockWebSocket([
mockApi([
mockCall('core.get_jobs', (query) => {
if (query[0][0][2] === JobState.Success) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectat
import { throwError } from 'rxjs';
import { MockAuthService } from 'app/core/testing/classes/mock-auth.service';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { Role } from 'app/enums/role.enum';
import { FormErrorHandlerService } from 'app/modules/forms/ix-forms/services/form-error-handler.service';
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness';
Expand All @@ -24,7 +24,7 @@ describe('ChangePasswordDialogComponent', () => {
ReactiveFormsModule,
],
providers: [
mockWebSocket([
mockApi([
mockCall('user.set_password'),
]),
mockProvider(FormErrorHandlerService),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MatIconHarness } from '@angular/material/icon/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { MockWebSocketService } from 'app/core/testing/classes/mock-websocket.service';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { DirectoryServiceState } from 'app/enums/directory-service-state.enum';
import { ApiEvent } from 'app/interfaces/api-message.interface';
import { DirectoryServicesState } from 'app/interfaces/directory-services-state.interface';
Expand All @@ -25,7 +25,7 @@ describe('DirectoryServicesIndicatorComponent', () => {
const createComponent = createComponentFactory({
component: DirectoryServicesIndicatorComponent,
providers: [
mockWebSocket([
mockApi([
mockCall('directoryservices.get_state', {
activedirectory: DirectoryServiceState.Healthy,
ldap: DirectoryServiceState.Disabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { DirectoryServiceState } from 'app/enums/directory-service-state.enum';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
import {
Expand All @@ -19,7 +19,7 @@ describe('DirectoryServicesMonitorComponent', () => {
MapValuePipe,
],
providers: [
mockWebSocket([
mockApi([
mockCall('directoryservices.get_state', {
activedirectory: DirectoryServiceState.Disabled,
ldap: DirectoryServiceState.Healthy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { dummyUser } from 'app/core/testing/utils/mock-auth.utils';
import { mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { IxIconComponent } from 'app/modules/ix-icon/ix-icon.component';
import { AboutDialogComponent } from 'app/modules/layout/topbar/about-dialog/about-dialog.component';
import {
Expand All @@ -30,7 +30,7 @@ describe('UserMenuComponent', () => {
],
providers: [
mockProvider(MatDialog),
mockWebSocket(),
mockApi(),
mockProvider(AuthService, {
logout: jest.fn(() => of()),
user$: of(dummyUser),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { TrueCommandStatus } from 'app/enums/true-command-status.enum';
import { TrueCommandConfig } from 'app/interfaces/true-command-config.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('TruecommandConnectModalComponent', () => {
ReactiveFormsModule,
],
providers: [
mockWebSocket([
mockApi([
mockCall('truecommand.update'),
]),
mockProvider(AppLoaderService),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Spectator, createComponentFactory, mockProvider, SpectatorFactory,
} from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { mockWebSocket, mockCall } from 'app/core/testing/utils/mock-websocket.utils';
import { mockApi, mockCall } from 'app/core/testing/utils/mock-websocket.utils';
import { TrueCommandStatus } from 'app/enums/true-command-status.enum';
import { TrueCommandConfig } from 'app/interfaces/true-command-config.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('TruecommandButtonComponent', () => {
TruecommandStatusModalComponent,
],
providers: [
mockWebSocket([
mockApi([
mockCall('truecommand.config', getFakeConfig(config)),
]),
mockProvider(DialogService, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createRoutingFactory, mockProvider, Spectator } from '@ngneat/spectator
import { MockComponents } from 'ng-mocks';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { of } from 'rxjs';
import { mockCall, mockJob, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockJob, mockApi } from 'app/core/testing/utils/mock-websocket.utils';
import { App } from 'app/interfaces/app.interface';
import { AvailableApp } from 'app/interfaces/available-app.interface';
import { CatalogApp } from 'app/interfaces/catalog.interface';
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('AppDetailViewComponent', () => {
],
providers: [
InstalledAppsStore,
mockWebSocket([
mockApi([
mockJob('app.create'),
mockJob('app.update'),
mockCall('catalog.get_app_details', existingCatalogApp),
Expand Down
Loading

0 comments on commit 64eb9f6

Please sign in to comment.