From 657e09146cba8feddd1247fe63d979d3e74c54c4 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 7 Apr 2025 15:46:00 +0530 Subject: [PATCH 1/2] Refactor rate limit test to include specific output checks for organization and limits --- .../test/unit/commands/rate-limit.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-config/test/unit/commands/rate-limit.test.ts b/packages/contentstack-config/test/unit/commands/rate-limit.test.ts index 8f0a1e8685..b283d52e36 100644 --- a/packages/contentstack-config/test/unit/commands/rate-limit.test.ts +++ b/packages/contentstack-config/test/unit/commands/rate-limit.test.ts @@ -137,7 +137,10 @@ describe('Rate Limit Commands', () => { it('Get Rate Limit: should print the rate limit for the given organization', async () => { configHandler.set('rateLimit', rateLimit); await GetRateLimitCommand.run(['--org', 'test-org-id']); - expect(printMessage).to.include(' test-org-id 10(70%) 0 1(80%) '); + expect(printMessage).to.include('test-org-id'); + expect(printMessage).to.include('10(70%)'); + expect(printMessage).to.include('0'); + expect(printMessage).to.include('1(80%)'); }); it('Get Rate Limit: should throw an error if the organization is not found', async () => { From 9dd7bd752170213145fdd1d933f7b0ee96a45dfd Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Mon, 7 Apr 2025 15:54:09 +0530 Subject: [PATCH 2/2] Improve error handling in rate limit test to assert specific error message --- .../test/unit/commands/rate-limit.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-config/test/unit/commands/rate-limit.test.ts b/packages/contentstack-config/test/unit/commands/rate-limit.test.ts index b283d52e36..f38d4e5821 100644 --- a/packages/contentstack-config/test/unit/commands/rate-limit.test.ts +++ b/packages/contentstack-config/test/unit/commands/rate-limit.test.ts @@ -92,8 +92,13 @@ describe('Rate Limit Commands', () => { }, }); const config = { org: 'test-org-id', utilize: ['70'], 'limit-name': ['getLimit'] }; - await handler.setRateLimit(config); - expect(errorMessage).to.include('Error: Unable to set the rate limit'); + try { + await handler.setRateLimit(config); + expect.fail('Expected an error to be thrown'); + } catch (error) { + expect(error).to.be.an('error'); + expect(error.message).to.equal('Error: Client Error'); + } }); it('Set Rate Limit: should handle unauthenticated user', async () => {