mirror of
https://github.com/bitwarden/browser
synced 2026-02-26 17:43:22 +00:00
Introduce a new vault-export-api.service to replace the existing getOrganizationExport method in apiService
This commit is contained in:
@@ -7,3 +7,4 @@ export * from "./services/org-vault-export.service";
|
||||
export * from "./services/individual-vault-export.service.abstraction";
|
||||
export * from "./services/individual-vault-export.service";
|
||||
export * from "./services/export-helper";
|
||||
export * from "./services/api";
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./vault-export-api.service.abstraction";
|
||||
export * from "./vault-export-api.service";
|
||||
@@ -0,0 +1,13 @@
|
||||
import { OrganizationExportResponse } from "@bitwarden/common/admin-console/models/response/organization-export.response";
|
||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||
|
||||
export abstract class VaultExportApiServiceAbstraction {
|
||||
/**
|
||||
* Retrieves the export data for a specific organization.
|
||||
* @param organizationId The ID of the organization to export.
|
||||
* @returns A promise that resolves to the organization export response.
|
||||
*/
|
||||
abstract getOrganizationExport(
|
||||
organizationId: OrganizationId,
|
||||
): Promise<OrganizationExportResponse>;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||
|
||||
import { VaultExportApiService } from "./vault-export-api.service";
|
||||
|
||||
describe("VaultExportApiService", () => {
|
||||
let apiServiceMock: MockProxy<ApiService>;
|
||||
let sut: VaultExportApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
apiServiceMock = mock<ApiService>();
|
||||
sut = new VaultExportApiService(apiServiceMock);
|
||||
});
|
||||
|
||||
it("should call apiService.send with correct parameters", async () => {
|
||||
const orgId: OrganizationId = "test-org-id" as OrganizationId;
|
||||
const apiResponse = { foo: "bar" };
|
||||
apiServiceMock.send.mockResolvedValue(apiResponse);
|
||||
|
||||
await sut.getOrganizationExport(orgId);
|
||||
|
||||
expect(apiServiceMock.send).toHaveBeenCalledWith(
|
||||
"GET",
|
||||
`/organizations/${orgId}/export`,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { OrganizationExportResponse } from "@bitwarden/common/admin-console/models/response/organization-export.response";
|
||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||
|
||||
import { VaultExportApiServiceAbstraction } from "./vault-export-api.service.abstraction";
|
||||
|
||||
/**
|
||||
* Service for handling vault export API interactions.
|
||||
* @param apiService - An instance of {@link ApiService} used to make HTTP requests.
|
||||
*/
|
||||
export class VaultExportApiService implements VaultExportApiServiceAbstraction {
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
async getOrganizationExport(organizationId: OrganizationId): Promise<OrganizationExportResponse> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/export",
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new OrganizationExportResponse(r);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user