11import { expect } from 'chai' ;
22import { stub , restore } from 'sinon' ; // Import restore for cleaning up
3- import { cliux , configHandler , isAuthenticated } from '@contentstack/cli-utilities' ;
3+ import { cliux , configHandler } from '@contentstack/cli-utilities' ;
44import SetRateLimitCommand from '../../../src/commands/config/set/rate-limit' ;
55import GetRateLimitCommand from '../../../src/commands/config/get/rate-limit' ;
66import RemoveRateLimitCommand from '../../../src/commands/config/remove/rate-limit' ;
@@ -9,40 +9,32 @@ import { RateLimitHandler } from '../../../src/utils/rate-limit-handler';
99import { defaultRalteLimitConfig } from '../../../src/utils/common-utilities' ;
1010
1111describe ( 'Rate Limit Commands' , ( ) => {
12- let originalCliuxError : typeof cliux . error ;
13- let originalCliuxPrint : typeof cliux . print ;
14- let originalIsAuthenticated : ( ) => boolean ;
1512 let errorMessage : any ;
1613 let printMessage : any ;
17- let authenticated = isAuthenticated ;
1814 let rateLimitHandler : RateLimitHandler ;
1915 let mockClient : any ;
2016
2117 beforeEach ( ( ) => {
22- originalCliuxError = cliux . error ;
23- originalCliuxPrint = cliux . print ;
24- originalIsAuthenticated = isAuthenticated ;
18+ errorMessage = undefined ;
19+ printMessage = undefined ;
2520
26- cliux . error = ( message : string ) => {
21+ stub ( cliux , 'error' ) . callsFake ( ( message : string ) => {
2722 errorMessage = message ;
28- } ;
29- cliux . print = ( message : string ) => {
23+ } ) ;
24+ stub ( cliux , 'print' ) . callsFake ( ( message : string ) => {
3025 printMessage = message ;
31- } ;
26+ } ) ;
3227 rateLimitHandler = new RateLimitHandler ( ) ;
3328 mockClient = {
3429 organization : stub ( ) . returns ( {
3530 fetch : stub ( ) . resolves ( { plan : { features : [ { uid : 'getLimit' } , { uid : 'bulkLimit' } ] } } ) ,
3631 } ) ,
3732 } ;
3833 rateLimitHandler . setClient ( mockClient ) ;
39- restore ( ) ;
4034 } ) ;
4135
4236 afterEach ( ( ) => {
43- cliux . error = originalCliuxError ;
44- cliux . print = originalCliuxPrint ;
45- authenticated = originalIsAuthenticated ;
37+ restore ( ) ;
4638 } ) ;
4739
4840 describe ( 'Set Rate Limit Command' , ( ) => {
@@ -124,8 +116,6 @@ describe('Rate Limit Commands', () => {
124116 } ) ;
125117
126118 it ( 'Set Rate Limit: should handle unauthenticated user' , async ( ) => {
127- const isAuthenticatedStub = stub ( ) . returns ( false ) ;
128- authenticated = isAuthenticatedStub ;
129119 // Stub the exit method to prevent process exit
130120 const exitStub = stub ( SetRateLimitCommand . prototype , 'exit' ) ;
131121 const args = [ '--org' , 'test-org-id' , '--utilize' , '70,80' , '--limit-name' , 'getLimit,bulkLimit' ] ;
0 commit comments