Skip to content

Commit

Permalink
NAS-133308: Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 committed Jan 7, 2025
1 parent 9b91f96 commit 2bd9350
Showing 1 changed file with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ import { mntPath } from 'app/enums/mnt-path.enum';
import { TransferMode } from 'app/enums/transfer-mode.enum';
import { CloudSyncTaskUi } from 'app/interfaces/cloud-sync-task.interface';
import { CloudSyncCredential } from 'app/interfaces/cloudsync-credential.interface';
import { AuthService } from 'app/modules/auth/auth.service';
import { DialogService } from 'app/modules/dialog/dialog.service';
import {
CloudCredentialsSelectComponent,
} from 'app/modules/forms/custom-selects/cloud-credentials-select/cloud-credentials-select.component';
import { IxSelectHarness } from 'app/modules/forms/ix-forms/components/ix-select/ix-select.harness';
import { SlideIn } from 'app/modules/slide-ins/slide-in';
import { SlideInRef } from 'app/modules/slide-ins/slide-in-ref';
import { ApiService } from 'app/modules/websocket/api.service';
import { CloudSyncFormComponent } from 'app/pages/data-protection/cloudsync/cloudsync-form/cloudsync-form.component';
import {
TransferModeExplanationComponent,
} from 'app/pages/data-protection/cloudsync/transfer-mode-explanation/transfer-mode-explanation.component';
import { CloudCredentialService } from 'app/services/cloud-credential.service';
import { FilesystemService } from 'app/services/filesystem.service';

describe('CloudSyncFormComponent', () => {
Expand Down Expand Up @@ -76,6 +79,59 @@ describe('CloudSyncFormComponent', () => {
state: { state: JobState.Pending },
} as CloudSyncTaskUi;

const existingTask2 = {
id: 1,
description: 'test3',
path: '/mnt/dozer',
attributes: {
folder: '/',
bucket: 'test3',
fast_list: false,
},
next_run: 'Disabled',
pre_script: '',
post_script: '',
snapshot: false,
include: [],
exclude: [],
args: '',
enabled: true,
job: null,
direction: 'PULL',
transfer_mode: 'COPY',
bwlimit: [],
transfers: 4,
encryption: false,
filename_encryption: false,
encryption_password: '',
encryption_salt: '',
create_empty_src_dirs: false,
follow_symlinks: false,
credentials: {
id: 1,
name: 'Storj',
provider: {
type: 'STORJ_IX',
access_key_id: 'julzdrlwyv37oixflnbyysbumg3q',
secret_access_key: 'jyncyw7oup4ad2fv3tectsaksdag73oi7633arrzdlj77gmmywmvo',
},
},
schedule: {
minute: '0',
hour: '0',
dom: '*',
month: '*',
dow: '*',
},
locked: false,
credential: 'Storj',
next_run_time: '2025-01-08T08:00:00.000Z',
state: {
state: 'PENDING',
},
last_run: 'Disabled',
} as CloudSyncTaskUi;

let loader: HarnessLoader;
let spectator: Spectator<CloudSyncFormComponent>;
const getData = jest.fn(() => existingTask);
Expand Down Expand Up @@ -280,4 +336,84 @@ describe('CloudSyncFormComponent', () => {
expect(slideInRef.close).toHaveBeenCalledWith({ response: existingTask, error: null });
});
});
describe('doesnt load buckets when user doesnt has roles', () => {
beforeEach(() => {
spectator = createComponent({
providers: [
mockProvider(SlideInRef, {
...slideInRef,
getData: jest.fn(() => existingTask2),
}),
mockProvider(CloudCredentialService, {
getProviders: jest.fn(() => {
return of([{
name: CloudSyncProviderName.Http,
title: 'Http',
buckets: false,
bucket_title: 'Bucket',
task_schema: [],
credentials_schema: [],
credentials_oauth: null,
},
{
name: CloudSyncProviderName.Mega,
title: 'Mega',
buckets: false,
bucket_title: 'Bucket',
task_schema: [],
credentials_schema: [],
credentials_oauth: null,
},
{
name: CloudSyncProviderName.Storj,
title: 'Storj iX',
credentials_oauth: null,
credentials_schema: [],
buckets: true,
bucket_title: 'Bucket',
task_schema: [
{
property: 'fast_list',
schema: {
type: 'boolean',
_name_: 'fast_list',
title: 'Use --fast-list',
description: 'Use fewer transactions in exchange for more RAM. This may also speed up or slow down your\ntransfer. See [rclone documentation](https://rclone.org/docs/#fast-list) for more details.',
default: false,
_required_: false,
},
},
],
}]);
}),
getCloudSyncCredentials: jest.fn(() => {
return of([
{
id: 1,
name: 'Storj',
provider: {
type: CloudSyncProviderName.Storj,
url: '',
access_key_id: 'julzdrlwyv37oixflnbyysbumg3q',
secret_access_key: 'jyncyw7oup4ad2fv3tectsaksdag73oi7633arrzdlj77gmmywmvo',
},
},
]);
}),
}),
mockProvider(AuthService, {
hasRole: jest.fn(() => of(false)),
}),
],
});
loader = TestbedHarnessEnvironment.loader(spectator.fixture);
spectator.detectChanges();
});

it('doesnt load buckets', async () => {
const buckets = await loader.getHarness(IxSelectHarness.with({ label: 'Bucket' }));
const options = await buckets.getOptionLabels();
expect(options).toEqual(['--', 'test3']);
});
});
});

0 comments on commit 2bd9350

Please sign in to comment.