|
| 1 | +/* global jest */ |
| 2 | +import { ApiClient } from "../../src/common/atlas/apiClient.js"; |
| 3 | +import { ensureCurrentIpInAccessList } from "../../src/common/atlas/accessListUtils.js"; |
| 4 | +import { jest } from "@jest/globals"; |
| 5 | + |
| 6 | +describe("ensureCurrentIpInAccessList", () => { |
| 7 | + it("should add the current IP to the access list", async () => { |
| 8 | + const apiClient = { |
| 9 | + getIpInfo: jest.fn().mockResolvedValue({ currentIpv4Address: "127.0.0.1" } as never), |
| 10 | + createProjectIpAccessList: jest.fn().mockResolvedValue(undefined as never), |
| 11 | + } as unknown as ApiClient; |
| 12 | + await ensureCurrentIpInAccessList(apiClient, "projectId"); |
| 13 | + expect(apiClient.createProjectIpAccessList).toHaveBeenCalledWith({ |
| 14 | + params: { path: { groupId: "projectId" } }, |
| 15 | + body: [{ groupId: "projectId", ipAddress: "127.0.0.1", comment: "Added by MCP pre-run access list helper" }], |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should not fail if the current IP is already in the access list", async () => { |
| 20 | + const apiClient = { |
| 21 | + getIpInfo: jest.fn().mockResolvedValue({ currentIpv4Address: "127.0.0.1" } as never), |
| 22 | + createProjectIpAccessList: jest.fn().mockRejectedValue({ response: { status: 409 } } as never), |
| 23 | + } as unknown as ApiClient; |
| 24 | + await ensureCurrentIpInAccessList(apiClient, "projectId"); |
| 25 | + expect(apiClient.createProjectIpAccessList).toHaveBeenCalledWith({ |
| 26 | + params: { path: { groupId: "projectId" } }, |
| 27 | + body: [{ groupId: "projectId", ipAddress: "127.0.0.1", comment: "Added by MCP pre-run access list helper" }], |
| 28 | + }); |
| 29 | + }); |
| 30 | +}); |
0 commit comments