@@ -10,60 +10,61 @@ vi.mock("../../../../utils/fetch.js");
1010vi . mock ( "./getLoginPath.js" ) ;
1111
1212describe ( "backendAuthenticate" , ( ) => {
13- it ( "should successfully authenticate and return token" , async ( ) => {
14- // Mock response data
15- const mockResponse = {
16- cookieString : "mock-cookie" ,
17- token : "mock-token" ,
18- } ;
13+ it ( "should successfully authenticate and return token" , async ( ) => {
14+ // Mock response data
15+ const mockResponse = {
16+ cookieString : "mock-cookie" ,
17+ token : "mock-token" ,
18+ } ;
1919
20- // Mock fetch implementation
21- const mockFetch = vi . fn ( ) . mockResolvedValue ( {
22- json : ( ) => Promise . resolve ( mockResponse ) ,
23- ok : true ,
24- } ) ;
20+ // Mock fetch implementation
21+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
22+ json : ( ) => Promise . resolve ( mockResponse ) ,
23+ ok : true ,
24+ } ) ;
2525
26- // Mock dependencies
27- vi . mocked ( getClientFetch ) . mockReturnValue ( mockFetch ) ;
28- vi . mocked ( getLoginUrl ) . mockReturnValue ( "/auth/login" ) ;
26+ // Mock dependencies
27+ vi . mocked ( getClientFetch ) . mockReturnValue ( mockFetch ) ;
28+ vi . mocked ( getLoginUrl ) . mockReturnValue ( "/auth/login" ) ;
2929
30- const result = await backendAuthenticate ( {
31- client : TEST_CLIENT ,
32- walletSecret : "test-secret" ,
33- } ) ;
30+ const result = await backendAuthenticate ( {
31+ client : TEST_CLIENT ,
32+ walletSecret : "test-secret" ,
33+ } ) ;
3434
35- // Verify the fetch call
36- expect ( mockFetch ) . toHaveBeenCalledWith ( "/auth/login" , {
37- body : stringify ( { walletSecret : "test-secret" } ) ,
38- headers : {
39- "Content-Type" : "application/json" ,
40- } ,
41- method : "POST" ,
42- } ) ;
35+ // Verify the fetch call
36+ expect ( mockFetch ) . toHaveBeenCalledWith ( "/auth/login" , {
37+ body : stringify ( { walletSecret : "test-secret" } ) ,
38+ headers : {
39+ "Content-Type" : "application/json" ,
40+ } ,
41+ method : "POST" ,
42+ } ) ;
4343
44- // Verify response
45- expect ( result ) . toEqual ( mockResponse ) ;
46- } ) ;
44+ // Verify response
45+ expect ( result ) . toEqual ( mockResponse ) ;
46+ } ) ;
4747
48- it ( "should throw error when authentication fails" , async ( ) => {
49- // Mock failed fetch response
50- const mockFetch = vi . fn ( ) . mockResolvedValue ( {
51- ok : false ,
52- } ) ;
48+ it ( "should throw error when authentication fails" , async ( ) => {
49+ // Mock failed fetch response
50+ const mockFetch = vi . fn ( ) . mockResolvedValue ( {
51+ ok : false ,
52+ text : ( ) => Promise . resolve ( "Failed to generate backend account" ) ,
53+ } ) ;
5354
54- // Mock dependencies
55- vi . mocked ( getClientFetch ) . mockReturnValue ( mockFetch ) ;
56- vi . mocked ( getLoginUrl ) . mockReturnValue ( "/auth/login" ) ;
55+ // Mock dependencies
56+ vi . mocked ( getClientFetch ) . mockReturnValue ( mockFetch ) ;
57+ vi . mocked ( getLoginUrl ) . mockReturnValue ( "/auth/login" ) ;
5758
58- // Test inputs
59- const args = {
60- client : TEST_CLIENT ,
61- walletSecret : "test-secret" ,
62- } ;
59+ // Test inputs
60+ const args = {
61+ client : TEST_CLIENT ,
62+ walletSecret : "test-secret" ,
63+ } ;
6364
64- // Verify error is thrown
65- await expect ( backendAuthenticate ( args ) ) . rejects . toThrow (
66- "Failed to generate backend account" ,
67- ) ;
68- } ) ;
65+ // Verify error is thrown
66+ await expect ( backendAuthenticate ( args ) ) . rejects . toThrow (
67+ "Failed to generate backend account" ,
68+ ) ;
69+ } ) ;
6970} ) ;
0 commit comments