@@ -22,12 +22,15 @@ import { getAccessToken } from '@/auth/store';
2222import { needsInteractiveMode , runInteractiveFlow } from '@/prompts/project-create' ;
2323
2424function mockFetchResponse ( status : number , body : unknown ) : void {
25- vi . stubGlobal ( 'fetch' , vi . fn ( ) . mockResolvedValue ( {
26- ok : status >= 200 && status < 300 ,
27- status,
28- json : ( ) => Promise . resolve ( body ) ,
29- headers : new Headers ( ) ,
30- } ) ) ;
25+ vi . stubGlobal (
26+ 'fetch' ,
27+ vi . fn ( ) . mockResolvedValue ( {
28+ ok : status >= 200 && status < 300 ,
29+ status,
30+ json : ( ) => Promise . resolve ( body ) ,
31+ headers : new Headers ( ) ,
32+ } ) ,
33+ ) ;
3134}
3235
3336describe ( 'executeCreateProject' , ( ) => {
@@ -45,57 +48,60 @@ describe('executeCreateProject', () => {
4548 it ( 'throws when no token is available' , async ( ) => {
4649 vi . mocked ( getAccessToken ) . mockResolvedValue ( null ) ;
4750
48- await expect ( executeCreateProject ( { url : 'https://docs.example.com' } ) )
49- . rejects . toThrow ( 'Not authenticated' ) ;
51+ await expect ( executeCreateProject ( { url : 'https://docs.example.com' } ) ) . rejects . toThrow ( 'Not authenticated' ) ;
5052 } ) ;
5153
5254 it ( 'throws when both --url and --github are provided' , async ( ) => {
5355 vi . mocked ( getAccessToken ) . mockResolvedValue ( 'test-token' ) ;
5456 mockFetchResponse ( 200 , { data : [ ] } ) ;
5557
56- await expect ( executeCreateProject ( {
57- url : 'https://docs.example.com' ,
58- github : 'owner/repo' ,
59- } ) ) . rejects . toThrow ( 'not both' ) ;
58+ await expect (
59+ executeCreateProject ( {
60+ url : 'https://docs.example.com' ,
61+ github : 'owner/repo' ,
62+ } ) ,
63+ ) . rejects . toThrow ( 'not both' ) ;
6064 } ) ;
6165
6266 it ( 'throws when no source is provided and interactive mode is skipped' , async ( ) => {
6367 vi . mocked ( getAccessToken ) . mockResolvedValue ( 'test-token' ) ;
6468 vi . mocked ( needsInteractiveMode ) . mockReturnValue ( false ) ;
6569 mockFetchResponse ( 200 , { data : [ ] } ) ;
6670
67- await expect ( executeCreateProject ( { } ) )
68- . rejects . toThrow ( '--url or --github is required' ) ;
71+ await expect ( executeCreateProject ( { } ) ) . rejects . toThrow ( '--url or --github is required' ) ;
6972 } ) ;
7073
7174 it ( 'creates a project successfully with --url and --org' , async ( ) => {
7275 vi . mocked ( getAccessToken ) . mockResolvedValue ( 'test-token' ) ;
7376
74- const fetchMock = vi . fn ( )
77+ const fetchMock = vi
78+ . fn ( )
7579 . mockResolvedValueOnce ( {
7680 ok : true ,
7781 status : 200 ,
78- json : ( ) => Promise . resolve ( {
79- data : [ { organization : { name : 'My Org' , slug : 'my-org' } } ] ,
80- } ) ,
82+ json : ( ) =>
83+ Promise . resolve ( {
84+ data : [ { organization : { name : 'My Org' , slug : 'my-org' } } ] ,
85+ } ) ,
8186 headers : new Headers ( ) ,
8287 } )
8388 . mockResolvedValueOnce ( {
8489 ok : true ,
8590 status : 201 ,
86- json : ( ) => Promise . resolve ( {
87- data : {
88- id : 1 ,
89- name : 'Example Docs' ,
90- slug : 'example-docs' ,
91- description : null ,
92- organization : { name : 'My Org' , slug : 'my-org' } ,
93- pages_count : 0 ,
94- last_indexed_at : null ,
95- has_indexed_content : false ,
96- mcp_url : 'https://yavy.dev/mcp/my-org/example-docs' ,
97- } ,
98- } ) ,
91+ json : ( ) =>
92+ Promise . resolve ( {
93+ data : {
94+ id : 1 ,
95+ name : 'Example Docs' ,
96+ slug : 'example-docs' ,
97+ description : null ,
98+ organization : { name : 'My Org' , slug : 'my-org' } ,
99+ pages_count : 0 ,
100+ last_indexed_at : null ,
101+ has_indexed_content : false ,
102+ mcp_url : 'https://yavy.dev/mcp/my-org/example-docs' ,
103+ } ,
104+ } ) ,
99105 headers : new Headers ( ) ,
100106 } ) ;
101107 vi . stubGlobal ( 'fetch' , fetchMock ) ;
@@ -105,39 +111,40 @@ describe('executeCreateProject', () => {
105111 org : 'my-org' ,
106112 } ) ;
107113
108- expect ( consoleSpy ) . toHaveBeenCalledWith (
109- expect . stringContaining ( 'Project created successfully!' ) ,
110- ) ;
114+ expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Project created successfully!' ) ) ;
111115 } ) ;
112116
113117 it ( 'auto-selects org when user has exactly one' , async ( ) => {
114118 vi . mocked ( getAccessToken ) . mockResolvedValue ( 'test-token' ) ;
115119
116- const fetchMock = vi . fn ( )
120+ const fetchMock = vi
121+ . fn ( )
117122 . mockResolvedValueOnce ( {
118123 ok : true ,
119124 status : 200 ,
120- json : ( ) => Promise . resolve ( {
121- data : [ { organization : { name : 'Solo Org' , slug : 'solo-org' } } ] ,
122- } ) ,
125+ json : ( ) =>
126+ Promise . resolve ( {
127+ data : [ { organization : { name : 'Solo Org' , slug : 'solo-org' } } ] ,
128+ } ) ,
123129 headers : new Headers ( ) ,
124130 } )
125131 . mockResolvedValueOnce ( {
126132 ok : true ,
127133 status : 201 ,
128- json : ( ) => Promise . resolve ( {
129- data : {
130- id : 2 ,
131- name : 'Docs' ,
132- slug : 'docs' ,
133- description : null ,
134- organization : { name : 'Solo Org' , slug : 'solo-org' } ,
135- pages_count : 0 ,
136- last_indexed_at : null ,
137- has_indexed_content : false ,
138- mcp_url : 'https://yavy.dev/mcp/solo-org/docs' ,
139- } ,
140- } ) ,
134+ json : ( ) =>
135+ Promise . resolve ( {
136+ data : {
137+ id : 2 ,
138+ name : 'Docs' ,
139+ slug : 'docs' ,
140+ description : null ,
141+ organization : { name : 'Solo Org' , slug : 'solo-org' } ,
142+ pages_count : 0 ,
143+ last_indexed_at : null ,
144+ has_indexed_content : false ,
145+ mcp_url : 'https://yavy.dev/mcp/solo-org/docs' ,
146+ } ,
147+ } ) ,
141148 headers : new Headers ( ) ,
142149 } ) ;
143150 vi . stubGlobal ( 'fetch' , fetchMock ) ;
@@ -159,40 +166,41 @@ describe('executeCreateProject', () => {
159166 name : 'Interactive Project' ,
160167 } ) ;
161168
162- const fetchMock = vi . fn ( )
169+ const fetchMock = vi
170+ . fn ( )
163171 . mockResolvedValueOnce ( {
164172 ok : true ,
165173 status : 200 ,
166- json : ( ) => Promise . resolve ( {
167- data : [ { organization : { name : 'My Org' , slug : 'my-org' } } ] ,
168- } ) ,
174+ json : ( ) =>
175+ Promise . resolve ( {
176+ data : [ { organization : { name : 'My Org' , slug : 'my-org' } } ] ,
177+ } ) ,
169178 headers : new Headers ( ) ,
170179 } )
171180 . mockResolvedValueOnce ( {
172181 ok : true ,
173182 status : 201 ,
174- json : ( ) => Promise . resolve ( {
175- data : {
176- id : 3 ,
177- name : 'Interactive Project' ,
178- slug : 'interactive-project' ,
179- description : null ,
180- organization : { name : 'My Org' , slug : 'my-org' } ,
181- pages_count : 0 ,
182- last_indexed_at : null ,
183- has_indexed_content : false ,
184- mcp_url : 'https://yavy.dev/mcp/my-org/interactive-project' ,
185- } ,
186- } ) ,
183+ json : ( ) =>
184+ Promise . resolve ( {
185+ data : {
186+ id : 3 ,
187+ name : 'Interactive Project' ,
188+ slug : 'interactive-project' ,
189+ description : null ,
190+ organization : { name : 'My Org' , slug : 'my-org' } ,
191+ pages_count : 0 ,
192+ last_indexed_at : null ,
193+ has_indexed_content : false ,
194+ mcp_url : 'https://yavy.dev/mcp/my-org/interactive-project' ,
195+ } ,
196+ } ) ,
187197 headers : new Headers ( ) ,
188198 } ) ;
189199 vi . stubGlobal ( 'fetch' , fetchMock ) ;
190200
191201 await executeCreateProject ( { } ) ;
192202
193203 expect ( runInteractiveFlow ) . toHaveBeenCalled ( ) ;
194- expect ( consoleSpy ) . toHaveBeenCalledWith (
195- expect . stringContaining ( 'Project created successfully!' ) ,
196- ) ;
204+ expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Project created successfully!' ) ) ;
197205 } ) ;
198206} ) ;
0 commit comments