1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 11:43:51 +00:00

Adding the organization integration api service and test cases

This commit is contained in:
Tom
2025-07-21 14:30:23 -04:00
parent 127fed70ac
commit 932ddc0290
6 changed files with 174 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import { OrganizationIntegrationType } from "./organization-integration-type";
export class OrganizationIntegrationRequest {
type: OrganizationIntegrationType;
configuration?: string;
constructor(integrationType: OrganizationIntegrationType, configuration?: string) {
this.type = integrationType;
this.configuration = configuration;
}
}

View File

@@ -0,0 +1,15 @@
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
import { Guid } from "@bitwarden/common/types/guid";
import { OrganizationIntegrationType } from "./organization-integration-type";
export class OrganizationIntegrationResponse extends BaseResponse {
id: Guid;
organizationIntegrationType: OrganizationIntegrationType;
constructor(response: any) {
super(response);
this.id = this.getResponseProperty("Id");
this.organizationIntegrationType = this.getResponseProperty("Type");
}
}

View File

@@ -0,0 +1,7 @@
export const OrganizationIntegrationType = {
CloudBillingSync: 1,
Scim: 2,
Slack: 3,
Webhook: 4,
Hec: 5,
} as const;

View File

@@ -0,0 +1,54 @@
import { Injectable } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationId, OrganizationIntegrationId } from "@bitwarden/common/types/guid";
import { OrganizationIntegrationRequest } from "./models/organization-integration-request";
import { OrganizationIntegrationResponse } from "./models/organization-integration-response";
@Injectable()
export class OrganizationIntegrationApiService {
constructor(private apiService: ApiService) {}
async createOrganizationIntegration(
orgId: OrganizationId,
request: OrganizationIntegrationRequest,
): Promise<OrganizationIntegrationResponse> {
const response = await this.apiService.send(
"POST",
`organizations/${orgId}/integrations`,
request,
true,
true,
);
return response;
}
async updateOrganizationIntegration(
orgId: OrganizationId,
integrationId: OrganizationIntegrationId,
request: OrganizationIntegrationRequest,
): Promise<OrganizationIntegrationResponse> {
const response = await this.apiService.send(
"PUT",
`organizations/${orgId}/integrations/${integrationId}`,
request,
true,
true,
);
return response;
}
async deleteOrganizationIntegration(
orgId: OrganizationId,
integrationId: OrganizationIntegrationId,
): Promise<any> {
await this.apiService.send(
"DELETE",
`organizations/${orgId}/integrations/${integrationId}`,
null,
true,
false,
);
}
}

View File

@@ -0,0 +1,86 @@
import { mock } from "jest-mock-extended";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationId, OrganizationIntegrationId } from "@bitwarden/common/types/guid";
import { OrganizationIntegrationRequest } from "../models/organization-integration-request";
import { OrganizationIntegrationType } from "../models/organization-integration-type";
import { OrganizationIntegrationApiService } from "../organization-integration-api.service";
export const mockIntegrationResponse: any = {
id: "1",
organizationIntegratipnType: 5,
};
describe("OrganizationIntegrationApiService", () => {
let service: OrganizationIntegrationApiService;
const apiService = mock<ApiService>();
beforeEach(() => {
service = new OrganizationIntegrationApiService(apiService);
});
it("should be created", () => {
expect(service).toBeTruthy();
});
it("should call apiService.send with correct parameters for createOrganizationIntegration", async () => {
const request = new OrganizationIntegrationRequest(
OrganizationIntegrationType.Hec,
"{ 'uri:' 'test.com', 'scheme:' 'bearer', 'token:' '123456789' }",
);
const orgId = "org1" as OrganizationId;
apiService.send.mockReturnValue(Promise.resolve(mockIntegrationResponse));
const result = await service.createOrganizationIntegration(orgId, request);
expect(result.organizationIntegrationType).toEqual(
mockIntegrationResponse.organizationIntegrationType,
);
expect(apiService.send).toHaveBeenCalledWith(
"POST",
`organizations/${orgId.toString()}/integrations`,
request,
true,
true,
);
});
it("should call apiService.send with the correct parameters for updateOrganizationIntegration", async () => {
const request = new OrganizationIntegrationRequest(
OrganizationIntegrationType.Hec,
"{ 'uri:' 'test.com', 'scheme:' 'bearer', 'token:' '123456789' }",
);
const orgId = "org1" as OrganizationId;
const integrationId = "integration1" as OrganizationIntegrationId;
apiService.send.mockReturnValue(Promise.resolve(mockIntegrationResponse));
const result = await service.updateOrganizationIntegration(orgId, integrationId, request);
expect(result.organizationIntegrationType).toEqual(
mockIntegrationResponse.organizationIntegrationType,
);
expect(apiService.send).toHaveBeenCalledWith(
"PUT",
`organizations/${orgId}/integrations/${integrationId}`,
request,
true,
true,
);
});
it("should call apiService.send with the correct parameters for deleteOrganizationIntegration", async () => {
const orgId = "org1" as OrganizationId;
const integrationId = "integration1" as OrganizationIntegrationId;
await service.deleteOrganizationIntegration(orgId, integrationId);
expect(apiService.send).toHaveBeenCalledWith(
"DELETE",
`organizations/${orgId}/integrations/${integrationId}`,
null,
true,
false,
);
});
});

View File

@@ -15,3 +15,4 @@ export type IndexedEntityId = Opaque<string, "IndexedEntityId">;
export type SecurityTaskId = Opaque<string, "SecurityTaskId">;
export type NotificationId = Opaque<string, "NotificationId">;
export type EmergencyAccessId = Opaque<string, "EmergencyAccessId">;
export type OrganizationIntegrationId = Opaque<string, "OrganizationIntegrationId">;