11import { refreshAccessToken } from "@repo/backlog-utils" ;
2- import { resolveSpace , updateSpaceAuth } from "@repo/config" ;
2+ import { findSpace , loadConfig , updateSpaceAuth } from "@repo/config" ;
33import { Backlog } from "backlog-js" ;
44import consola from "consola" ;
55import { describe , expect , it , vi } from "vitest" ;
@@ -19,15 +19,22 @@ vi.mock("@repo/backlog-utils", () => ({
1919vi . mock ( "@repo/config" , ( ) => ( {
2020 findSpace : vi . fn ( ) ,
2121 loadConfig : vi . fn ( ) ,
22- resolveSpace : vi . fn ( ) ,
2322 updateSpaceAuth : vi . fn ( ) ,
2423} ) ) ;
2524
2625vi . mock ( "consola" , ( ) => import ( "@repo/test-utils/mock-consola" ) ) ;
2726
27+ const mockDefaultSpace = ( space : ReturnType < typeof findSpace > ) => {
28+ vi . mocked ( loadConfig ) . mockReturnValue ( {
29+ spaces : space ? [ space ] : [ ] ,
30+ defaultSpace : space ?. host ,
31+ } ) ;
32+ vi . mocked ( findSpace ) . mockReturnValue ( space ) ;
33+ } ;
34+
2835describe ( "auth refresh" , ( ) => {
2936 it ( "throws error when no space is configured" , async ( ) => {
30- vi . mocked ( resolveSpace ) . mockReturnValue ( null ) ;
37+ mockDefaultSpace ( null ) ;
3138
3239 const { default : refresh } = await import ( "./refresh" ) ;
3340 await expect ( refresh . parseAsync ( [ ] , { from : "user" } ) ) . rejects . toThrow (
@@ -36,7 +43,7 @@ describe("auth refresh", () => {
3643 } ) ;
3744
3845 it ( "shows error for API key authentication" , async ( ) => {
39- vi . mocked ( resolveSpace ) . mockReturnValue ( {
46+ mockDefaultSpace ( {
4047 host : "example.backlog.com" ,
4148 auth : { method : "api-key" as const , apiKey : "key" } ,
4249 } ) ;
@@ -48,7 +55,7 @@ describe("auth refresh", () => {
4855 } ) ;
4956
5057 it ( "shows error when clientId/clientSecret are missing" , async ( ) => {
51- vi . mocked ( resolveSpace ) . mockReturnValue ( {
58+ mockDefaultSpace ( {
5259 host : "example.backlog.com" ,
5360 auth : {
5461 method : "oauth" as const ,
@@ -64,7 +71,7 @@ describe("auth refresh", () => {
6471 } ) ;
6572
6673 it ( "successfully refreshes token" , async ( ) => {
67- vi . mocked ( resolveSpace ) . mockReturnValue ( {
74+ mockDefaultSpace ( {
6875 host : "example.backlog.com" ,
6976 auth : {
7077 method : "oauth" as const ,
@@ -108,7 +115,7 @@ describe("auth refresh", () => {
108115 } ) ;
109116
110117 it ( "shows error on refresh failure" , async ( ) => {
111- vi . mocked ( resolveSpace ) . mockReturnValue ( {
118+ mockDefaultSpace ( {
112119 host : "example.backlog.com" ,
113120 auth : {
114121 method : "oauth" as const ,
@@ -127,7 +134,7 @@ describe("auth refresh", () => {
127134 } ) ;
128135
129136 it ( "shows error when token verification fails after refresh" , async ( ) => {
130- vi . mocked ( resolveSpace ) . mockReturnValue ( {
137+ mockDefaultSpace ( {
131138 host : "example.backlog.com" ,
132139 auth : {
133140 method : "oauth" as const ,
0 commit comments