test(#291): add test for connection limit per workspace
Add test to verify workspace connection limit enforcement. Default limit is 100 connections per workspace. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,7 @@ describe("ConnectionService", () => {
|
||||
findMany: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
count: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -136,6 +137,19 @@ describe("ConnectionService", () => {
|
||||
});
|
||||
|
||||
describe("initiateConnection", () => {
|
||||
it("should throw error if workspace has reached connection limit", async () => {
|
||||
const existingConnections = Array.from({ length: 100 }, (_, i) => ({
|
||||
...mockConnection,
|
||||
id: `conn-${i}`,
|
||||
}));
|
||||
|
||||
vi.spyOn(prismaService.federationConnection, "count").mockResolvedValue(100);
|
||||
|
||||
await expect(service.initiateConnection(mockWorkspaceId, mockRemoteUrl)).rejects.toThrow(
|
||||
"Connection limit reached for workspace. Maximum 100 connections allowed per workspace."
|
||||
);
|
||||
});
|
||||
|
||||
it("should create a pending connection", async () => {
|
||||
const mockAxiosResponse: AxiosResponse = {
|
||||
data: mockRemoteIdentity,
|
||||
@@ -145,6 +159,7 @@ describe("ConnectionService", () => {
|
||||
config: {} as never,
|
||||
};
|
||||
|
||||
vi.spyOn(prismaService.federationConnection, "count").mockResolvedValue(5);
|
||||
vi.spyOn(httpService, "get").mockReturnValue(of(mockAxiosResponse));
|
||||
vi.spyOn(httpService, "post").mockReturnValue(
|
||||
of({ data: { accepted: true } } as AxiosResponse)
|
||||
@@ -176,6 +191,7 @@ describe("ConnectionService", () => {
|
||||
config: {} as never,
|
||||
};
|
||||
|
||||
vi.spyOn(prismaService.federationConnection, "count").mockResolvedValue(5);
|
||||
vi.spyOn(httpService, "get").mockReturnValue(of(mockAxiosResponse));
|
||||
vi.spyOn(httpService, "post").mockReturnValue(
|
||||
of({ data: { accepted: true } } as AxiosResponse)
|
||||
@@ -202,6 +218,7 @@ describe("ConnectionService", () => {
|
||||
config: {} as never,
|
||||
};
|
||||
|
||||
vi.spyOn(prismaService.federationConnection, "count").mockResolvedValue(5);
|
||||
const postSpy = vi
|
||||
.spyOn(httpService, "post")
|
||||
.mockReturnValue(of({ data: { accepted: true } } as AxiosResponse));
|
||||
@@ -230,6 +247,7 @@ describe("ConnectionService", () => {
|
||||
config: {} as never,
|
||||
};
|
||||
|
||||
vi.spyOn(prismaService.federationConnection, "count").mockResolvedValue(5);
|
||||
vi.spyOn(httpService, "get").mockReturnValue(of(mockAxiosResponse));
|
||||
vi.spyOn(httpService, "post").mockReturnValue(
|
||||
throwError(() => new Error("Connection refused"))
|
||||
|
||||
Reference in New Issue
Block a user