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