mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
[PM-18322] Fix: Allow organization admins to upload attachments for items without direct access (#14361)
* Wire organization ID into AttachmentsV2Component for org-based ciphers * Enhance AttachmentsV2Component to accept organization ID for improved handling of org-based ciphers * Integrate organization ID into VaultComponent for AttachmentsV2Component to enhance org-based cipher handling * Add unit tests for CipherAttachmentsComponent to validate attachment saving behavior for admins - Introduced mocks for ApiService and OrganizationService in the test setup. - Updated tests to check `saveAttachmentWithServer` calls with the correct parameters, including an `isAdmin` flag for admin API usage. * Fix unit tests for AttachmentsV2Component by adding mocks for ApiService and OrganizationService * Fix AttachmentsV2Component tests
This commit is contained in:
@@ -3,6 +3,8 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
import { By } from "@angular/platform-browser";
|
||||
import { mock } from "jest-mock-extended";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
@@ -86,6 +88,14 @@ describe("CipherAttachmentsComponent", () => {
|
||||
provide: AccountService,
|
||||
useValue: accountService,
|
||||
},
|
||||
{
|
||||
provide: ApiService,
|
||||
useValue: mock<ApiService>(),
|
||||
},
|
||||
{
|
||||
provide: OrganizationService,
|
||||
useValue: mock<OrganizationService>(),
|
||||
},
|
||||
],
|
||||
})
|
||||
.overrideComponent(CipherAttachmentsComponent, {
|
||||
@@ -234,7 +244,21 @@ describe("CipherAttachmentsComponent", () => {
|
||||
it("calls `saveAttachmentWithServer`", async () => {
|
||||
await component.submit();
|
||||
|
||||
expect(saveAttachmentWithServer).toHaveBeenCalledWith(cipherDomain, file, mockUserId);
|
||||
expect(saveAttachmentWithServer).toHaveBeenCalledWith(
|
||||
cipherDomain,
|
||||
file,
|
||||
mockUserId,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("calls `saveAttachmentWithServer` with isAdmin=true when using admin API", async () => {
|
||||
// Set isAdmin to true to use admin API
|
||||
Object.defineProperty(component, "isAdmin", { value: true });
|
||||
|
||||
await component.submit();
|
||||
|
||||
expect(saveAttachmentWithServer).toHaveBeenCalledWith(cipherDomain, file, mockUserId, true);
|
||||
});
|
||||
|
||||
it("resets form and input values", async () => {
|
||||
|
||||
Reference in New Issue
Block a user