|
9 | 9 | handleErrorResponse, |
10 | 10 | handleSuccessResponse, |
11 | 11 | isEntitlementError, |
| 12 | + isWorkspaceDisabledError, |
12 | 13 | createEntitlementErrorResponse, |
13 | 14 | getUnsupportedCodexModelInfo, |
14 | 15 | resolveUnsupportedCodexFallbackModel, |
@@ -307,12 +308,57 @@ describe('Fetch Helpers Module', () => { |
307 | 308 | expect(isEntitlementError('rate_limit_exceeded', '')).toBe(false); |
308 | 309 | }); |
309 | 310 |
|
310 | | - it('returns false for generic errors', () => { |
311 | | - expect(isEntitlementError('not_found', 'Resource not found')).toBe(false); |
312 | | - }); |
| 311 | + it('returns false for generic errors', () => { |
| 312 | + expect(isEntitlementError('not_found', 'Resource not found')).toBe(false); |
| 313 | + }); |
| 314 | +}); |
| 315 | + |
| 316 | +describe('isWorkspaceDisabledError', () => { |
| 317 | + it('returns true for 403 with workspace disabled message', () => { |
| 318 | + expect(isWorkspaceDisabledError(403, '', 'Your workspace has been disabled')).toBe(true); |
| 319 | + }); |
| 320 | + |
| 321 | + it('returns true for 403 with workspace expired message', () => { |
| 322 | + expect(isWorkspaceDisabledError(403, '', 'Workspace expired')).toBe(true); |
| 323 | + }); |
| 324 | + |
| 325 | + it('returns true for 403 with account disabled message', () => { |
| 326 | + expect(isWorkspaceDisabledError(403, '', 'Account has been deactivated')).toBe(true); |
| 327 | + }); |
| 328 | + |
| 329 | + it('returns true for workspace_disabled error code', () => { |
| 330 | + expect(isWorkspaceDisabledError(403, 'workspace_disabled', '')).toBe(true); |
| 331 | + }); |
| 332 | + |
| 333 | + it('returns true for workspace_expired error code', () => { |
| 334 | + expect(isWorkspaceDisabledError(403, 'workspace_expired', 'Some message')).toBe(true); |
313 | 335 | }); |
314 | 336 |
|
315 | | - describe('createEntitlementErrorResponse', () => { |
| 337 | + it('returns true for account_disabled error code', () => { |
| 338 | + expect(isWorkspaceDisabledError(403, 'account_disabled', '')).toBe(true); |
| 339 | + }); |
| 340 | + |
| 341 | + it('returns true for billing_failed error code', () => { |
| 342 | + expect(isWorkspaceDisabledError(403, 'billing_failed', '')).toBe(true); |
| 343 | + }); |
| 344 | + |
| 345 | + it('returns false for non-403 status even with disabled message', () => { |
| 346 | + expect(isWorkspaceDisabledError(400, '', 'Your workspace has been disabled')).toBe(false); |
| 347 | + expect(isWorkspaceDisabledError(401, '', 'Your workspace has been disabled')).toBe(false); |
| 348 | + expect(isWorkspaceDisabledError(500, '', 'Your workspace has been disabled')).toBe(false); |
| 349 | + }); |
| 350 | + |
| 351 | + it('returns false for 403 with unrelated messages', () => { |
| 352 | + expect(isWorkspaceDisabledError(403, '', 'Permission denied')).toBe(false); |
| 353 | + expect(isWorkspaceDisabledError(403, '', 'Not authorized')).toBe(false); |
| 354 | + }); |
| 355 | + |
| 356 | + it('returns false for entitlement errors', () => { |
| 357 | + expect(isWorkspaceDisabledError(403, 'usage_not_included', 'Not in your plan')).toBe(false); |
| 358 | + }); |
| 359 | +}); |
| 360 | + |
| 361 | +describe('createEntitlementErrorResponse', () => { |
316 | 362 | it('returns 403 status with user-friendly message', async () => { |
317 | 363 | const resp = createEntitlementErrorResponse('original body'); |
318 | 364 | expect(resp.status).toBe(403); |
|
0 commit comments