@@ -2,11 +2,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
22import * as vscode from "vscode"
33
44import {
5- checkSubscriptionStatus ,
65 clearZooCodeToken ,
76 clearZooCodeUserInfo ,
87 disconnectZooCode ,
9- getCachedSubscriptionStatus ,
108 getCachedZooCodeToken ,
119 getCachedZooCodeUserInfo ,
1210 getZooCodeBaseUrl ,
@@ -68,98 +66,6 @@ describe("zoo-code-auth", () => {
6866 vi . restoreAllMocks ( )
6967 } )
7068
71- describe ( "getCachedSubscriptionStatus" , ( ) => {
72- it ( "returns unknown initially" , ( ) => {
73- expect ( getCachedSubscriptionStatus ( ) ) . toBe ( "unknown" )
74- } )
75- } )
76-
77- describe ( "checkSubscriptionStatus" , ( ) => {
78- it ( "returns inactive when no token is present" , async ( ) => {
79- await initZooCodeAuth ( mockContext )
80-
81- const status = await checkSubscriptionStatus ( )
82-
83- expect ( status ) . toBe ( "inactive" )
84- expect ( mockFetch ) . not . toHaveBeenCalled ( )
85- } )
86-
87- it ( "returns active when the API reports an active subscriber" , async ( ) => {
88- await initZooCodeAuth ( mockContext )
89- await setZooCodeToken ( "zoo_ext_test_token" )
90-
91- mockFetch . mockResolvedValueOnce ( {
92- ok : true ,
93- json : async ( ) => ( { isSubscriber : true , planId : "pro" , status : "active" } ) ,
94- } )
95-
96- const status = await checkSubscriptionStatus ( )
97-
98- expect ( status ) . toBe ( "active" )
99- expect ( mockFetch ) . toHaveBeenCalledWith (
100- expect . stringContaining ( "/api/subscription/status" ) ,
101- expect . objectContaining ( {
102- headers : { Authorization : "Bearer zoo_ext_test_token" } ,
103- } ) ,
104- )
105- } )
106-
107- it ( "returns inactive when the API reports a free user" , async ( ) => {
108- await initZooCodeAuth ( mockContext )
109- await setZooCodeToken ( "zoo_ext_test_token" )
110-
111- mockFetch . mockResolvedValueOnce ( {
112- ok : true ,
113- json : async ( ) => ( { isSubscriber : false , planId : "free" , status : "active" } ) ,
114- } )
115-
116- await expect ( checkSubscriptionStatus ( ) ) . resolves . toBe ( "inactive" )
117- } )
118-
119- it ( "returns unknown when the API request fails" , async ( ) => {
120- await initZooCodeAuth ( mockContext )
121- await setZooCodeToken ( "zoo_ext_test_token" )
122-
123- mockFetch . mockResolvedValueOnce ( {
124- ok : false ,
125- status : 500 ,
126- statusText : "Internal Server Error" ,
127- } )
128-
129- await expect ( checkSubscriptionStatus ( ) ) . resolves . toBe ( "unknown" )
130- } )
131-
132- it ( "returns unknown when the API throws" , async ( ) => {
133- await initZooCodeAuth ( mockContext )
134- await setZooCodeToken ( "zoo_ext_test_token" )
135- mockFetch . mockRejectedValueOnce ( new Error ( "Network error" ) )
136-
137- await expect ( checkSubscriptionStatus ( ) ) . resolves . toBe ( "unknown" )
138- } )
139-
140- it ( "reuses the cached status when it was checked recently" , async ( ) => {
141- await initZooCodeAuth ( mockContext )
142- await setZooCodeToken ( "zoo_ext_test_token" )
143-
144- mockFetch . mockResolvedValueOnce ( {
145- ok : true ,
146- json : async ( ) => ( { isSubscriber : true , planId : "pro" , status : "active" } ) ,
147- } )
148-
149- expect ( await checkSubscriptionStatus ( ) ) . toBe ( "active" )
150- expect ( await checkSubscriptionStatus ( ) ) . toBe ( "active" )
151- expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 )
152- } )
153-
154- it ( "handles AbortSignal timeouts" , async ( ) => {
155- await initZooCodeAuth ( mockContext )
156- await setZooCodeToken ( "zoo_ext_test_token" )
157- mockFetch . mockRejectedValueOnce ( new DOMException ( "Aborted" , "AbortError" ) )
158-
159- await expect ( checkSubscriptionStatus ( ) ) . resolves . toBe ( "unknown" )
160- } )
161- } )
162-
16369 describe ( "getCachedZooCodeToken" , ( ) => {
16470 it ( "returns an empty string when no token is set" , async ( ) => {
16571 await clearZooCodeToken ( )
@@ -169,15 +75,10 @@ describe("zoo-code-auth", () => {
16975
17076 it ( "preloads the cached token during initialization" , async ( ) => {
17177 await mockSecrets . store ( "zoo-code-session-token" , "zoo_ext_cached_token" )
172- mockFetch
173- . mockResolvedValueOnce ( {
174- ok : true ,
175- json : async ( ) => ( { valid : true } ) ,
176- } )
177- . mockResolvedValueOnce ( {
178- ok : true ,
179- json : async ( ) => ( { isSubscriber : true } ) ,
180- } )
78+ mockFetch . mockResolvedValueOnce ( {
79+ ok : true ,
80+ json : async ( ) => ( { valid : true } ) ,
81+ } )
18182
18283 await initZooCodeAuth ( mockContext )
18384 await Promise . resolve ( )
@@ -237,10 +138,8 @@ describe("zoo-code-auth", () => {
237138
238139 await initZooCodeAuth ( mockContext )
239140
240- // Token and user info should be kept; subscription status should be unknown
241141 expect ( getCachedZooCodeToken ( ) ) . toBe ( "zoo_ext_valid_token" )
242142 expect ( getCachedZooCodeUserInfo ( ) . name ) . toBe ( "Jane Doe" )
243- expect ( getCachedSubscriptionStatus ( ) ) . toBe ( "unknown" )
244143 } )
245144
246145 it ( "preserves token and user info when verify returns 5xx (transient backend error)" , async ( ) => {
@@ -257,39 +156,16 @@ describe("zoo-code-auth", () => {
257156
258157 expect ( getCachedZooCodeToken ( ) ) . toBe ( "zoo_ext_valid_token" )
259158 expect ( getCachedZooCodeUserInfo ( ) . name ) . toBe ( "Jane Doe" )
260- expect ( getCachedSubscriptionStatus ( ) ) . toBe ( "unknown" )
261- } )
262- } )
263-
264- describe ( "setZooCodeToken" , ( ) => {
265- it ( "resets the cached subscription status when the token changes" , async ( ) => {
266- await initZooCodeAuth ( mockContext )
267- await setZooCodeToken ( "zoo_ext_token1" )
268- mockFetch . mockResolvedValueOnce ( {
269- ok : true ,
270- json : async ( ) => ( { isSubscriber : true , planId : "pro" , status : "active" } ) ,
271- } )
272- await checkSubscriptionStatus ( )
273-
274- await setZooCodeToken ( "zoo_ext_token2" )
275-
276- expect ( getCachedSubscriptionStatus ( ) ) . toBe ( "unknown" )
277159 } )
278160 } )
279161
280162 describe ( "clearZooCodeToken" , ( ) => {
281- it ( "resets the cached subscription status when the token is cleared " , async ( ) => {
163+ it ( "clears the cached token" , async ( ) => {
282164 await initZooCodeAuth ( mockContext )
283165 await setZooCodeToken ( "zoo_ext_test_token" )
284- mockFetch . mockResolvedValueOnce ( {
285- ok : true ,
286- json : async ( ) => ( { isSubscriber : true , planId : "pro" , status : "active" } ) ,
287- } )
288- await checkSubscriptionStatus ( )
289166
290167 await clearZooCodeToken ( )
291168
292- expect ( getCachedSubscriptionStatus ( ) ) . toBe ( "unknown" )
293169 expect ( getCachedZooCodeToken ( ) ) . toBe ( "" )
294170 } )
295171 } )
@@ -337,15 +213,10 @@ describe("zoo-code-auth", () => {
337213
338214 it ( "persists a token only after backend verification succeeds" , async ( ) => {
339215 await initZooCodeAuth ( mockContext )
340- mockFetch
341- . mockResolvedValueOnce ( {
342- ok : true ,
343- json : async ( ) => ( { valid : true } ) ,
344- } )
345- . mockResolvedValueOnce ( {
346- ok : true ,
347- json : async ( ) => ( { isSubscriber : true } ) ,
348- } )
216+ mockFetch . mockResolvedValueOnce ( {
217+ ok : true ,
218+ json : async ( ) => ( { valid : true } ) ,
219+ } )
349220
350221 const success = await handleAuthCallback ( "zoo_ext_real_token" )
351222
0 commit comments