Skip to content

Commit

Permalink
NAS-132767 / 25.04 / Fix payload for cloud sync task (#11133)
Browse files Browse the repository at this point in the history
* NAS-132767: Fix payload for cloud sync task

* NAS-132767: Add unit test
  • Loading branch information
denysbutenko authored Dec 5, 2024
1 parent 8570a11 commit 373844d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { of } from 'rxjs';
import { mockCall, mockApi } from 'app/core/testing/utils/mock-api.utils';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { IxInputHarness } from 'app/modules/forms/ix-forms/components/ix-input/ix-input.harness';
import { IxSelectHarness } from 'app/modules/forms/ix-forms/components/ix-select/ix-select.harness';
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness';
import { ChainedRef } from 'app/modules/slide-ins/chained-component-ref';
import { SlideInRef } from 'app/modules/slide-ins/slide-in-ref';
Expand Down Expand Up @@ -132,4 +134,28 @@ describe('CloudSyncWhatAndWhenComponent', () => {
});
expect(chainedRef.swap).toHaveBeenCalledWith(CloudSyncFormComponent, true);
});

it('checks payload when use invalid s3 credentials', async () => {
const bucketSelect = await loader.getHarness(IxSelectHarness.with({ label: 'Bucket' }));
expect(await bucketSelect.getValue()).toBe('');

spectator.component.isCredentialInvalid$.next(true);
spectator.detectChanges();

const bucketInput = await loader.getHarness(IxInputHarness.with({ label: 'Bucket' }));
await bucketInput.setValue('selected');

expect(spectator.component.getPayload()).toEqual(expect.objectContaining({
attributes: expect.objectContaining({
bucket: 'selected',
}),
}));

await bucketInput.setValue('test-bucket');
expect(spectator.component.getPayload()).toEqual(expect.objectContaining({
attributes: expect.objectContaining({
bucket: 'test-bucket',
}),
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { find, findIndex, isArray } from 'lodash-es';
import {
BehaviorSubject,
EMPTY,
Observable, catchError, combineLatest, filter, map, merge, of, tap,
} from 'rxjs';
Expand Down Expand Up @@ -118,6 +119,7 @@ export class CloudSyncWhatAndWhenComponent implements OnInit, OnChanges {
bwlimit: [[] as string[]],
});

isCredentialInvalid$ = new BehaviorSubject(false);
credentials: CloudSyncCredential[] = [];
providers: CloudSyncProvider[] = [];
bucketPlaceholder: string = helptextCloudSync.bucket_placeholder;
Expand Down Expand Up @@ -273,6 +275,8 @@ export class CloudSyncWhatAndWhenComponent implements OnInit, OnChanges {
if (formValue[name] !== undefined && formValue[name] !== null && formValue[name] !== '') {
if (name === 'task_encryption') {
attributes[name] = formValue[name] === '' ? null : formValue[name];
} else if (name === 'bucket_input') {
attributes['bucket'] = formValue[name];
} else {
attributes[name] = formValue[name];
}
Expand Down Expand Up @@ -438,6 +442,16 @@ export class CloudSyncWhatAndWhenComponent implements OnInit, OnChanges {
}
});

this.isCredentialInvalid$.pipe(untilDestroyed(this)).subscribe((value) => {
if (value) {
this.form.controls.bucket_input.enable();
this.form.controls.bucket.disable();
} else {
this.form.controls.bucket_input.disable();
this.form.controls.bucket.enable();
}
});

this.form.controls.bucket.valueChanges.pipe(
filter((selectedOption) => selectedOption === newOption),
untilDestroyed(this),
Expand Down Expand Up @@ -479,13 +493,11 @@ export class CloudSyncWhatAndWhenComponent implements OnInit, OnChanges {
});
}
this.bucketOptions$ = of(bucketOptions);
this.form.controls.bucket.enable();
this.form.controls.bucket_input.disable();
this.isCredentialInvalid$.next(false);
this.cdr.markForCheck();
},
error: (error: ApiError) => {
this.form.controls.bucket.disable();
this.form.controls.bucket_input.enable();
this.isCredentialInvalid$.next(true);
this.dialog.closeAllDialogs();
this.dialog.confirm({
title: error.extra ? (error.extra as { excerpt: string }).excerpt : `${this.translate.instant('Error: ')}${error.error}`,
Expand Down
24 changes: 12 additions & 12 deletions src/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5134,17 +5134,7 @@
"{temp}°C (Core #{core})": "",
"{temp}°C ({coreCount} cores at {temp}°C)": "",
"{threadCount, plural, one {# thread} other {# threads} }": "",
"{type} VDEVs": "{type} VDEVs",
"{type} at {location}": "{type} w {location}",
"{type} widget does not support {size} size.": "Widżet {type} nie obsługuje rozmiaru {size}",
"{type} widget is not supported.": "Widżet {type} nie jest obsługiwany.",
"{type} | {vdevWidth} wide | ": "",
"{usage}% (All Threads)": "{usage}% Wszystkich wątków)",
"{usage}% (Thread #{thread})": "{usage}% (Wątek #{thread})",
"{usage}% ({threadCount} threads at {usage}%)": "{usage}% ({threadCount} wątków przy {usage}%)",
"{used} of {total} ({used_pct})": "{used} z {total} ({used_pct})",
"{version} is available!": "{version} jest dostępna!",
"{view} on {enclosure}": "{view} na {enclosure}",
" seconds.": " sekund",
"% of all cores": "% użycia wszytskich rdzeni",
"(24 Hours)": "(24 Godziny)",
Expand Down Expand Up @@ -5279,5 +5269,15 @@
"to cloud": "do chmury",
"total available": "łącznie dostępne",
"{name} Devices": "Urządzenia",
"{name} Sessions": "Sesji"
}
"{name} Sessions": "Sesji",
"{type} VDEVs": "{type} VDEVs",
"{type} at {location}": "{type} w {location}",
"{type} widget does not support {size} size.": "Widżet {type} nie obsługuje rozmiaru {size}",
"{type} widget is not supported.": "Widżet {type} nie jest obsługiwany.",
"{usage}% (All Threads)": "{usage}% Wszystkich wątków)",
"{usage}% (Thread #{thread})": "{usage}% (Wątek #{thread})",
"{usage}% ({threadCount} threads at {usage}%)": "{usage}% ({threadCount} wątków przy {usage}%)",
"{used} of {total} ({used_pct})": "{used} z {total} ({used_pct})",
"{version} is available!": "{version} jest dostępna!",
"{view} on {enclosure}": "{view} na {enclosure}"
}

0 comments on commit 373844d

Please sign in to comment.