diff --git a/src/cli/commands/test/iac/local-execution/index.ts b/src/cli/commands/test/iac/local-execution/index.ts index c4082aa340d..b9a4cdbd9b9 100644 --- a/src/cli/commands/test/iac/local-execution/index.ts +++ b/src/cli/commands/test/iac/local-execution/index.ts @@ -118,7 +118,7 @@ export async function test( ); try { - await trackUsage(filteredIssues); + await trackUsage(filteredIssues, iacOrgSettings.meta.org); } catch (e) { if (e instanceof TestLimitReachedError) { throw e; diff --git a/src/cli/commands/test/iac/local-execution/usage-tracking.ts b/src/cli/commands/test/iac/local-execution/usage-tracking.ts index 4cc629398b8..044bf6cef3d 100644 --- a/src/cli/commands/test/iac/local-execution/usage-tracking.ts +++ b/src/cli/commands/test/iac/local-execution/usage-tracking.ts @@ -5,6 +5,7 @@ import { CustomError } from '../../../../../lib/errors'; export async function trackUsage( formattedResults: TrackableResult[], + org: string, // e.g. "my.org" ): Promise { const trackingData = formattedResults.map((res) => { return { @@ -19,6 +20,7 @@ export async function trackUsage( }, url: `${config.API}/track-iac-usage/cli`, body: { results: trackingData }, + qs: { org }, gzip: true, json: true, }); diff --git a/test/jest/unit/iac/usage-tracking.spec.ts b/test/jest/unit/iac/usage-tracking.spec.ts index 8e657aa2647..c80fb7d2c53 100644 --- a/test/jest/unit/iac/usage-tracking.spec.ts +++ b/test/jest/unit/iac/usage-tracking.spec.ts @@ -29,6 +29,8 @@ const results = [ }, ]; +const org = 'test-org'; + describe('tracking IaC test usage', () => { afterEach(() => { jest.clearAllMocks(); @@ -44,9 +46,10 @@ describe('tracking IaC test usage', () => { }); }); - await trackUsage(results); + await trackUsage(results, org); expect(mockedMakeRequest.mock.calls.length).toEqual(1); + expect(mockedMakeRequest.mock.calls[0][0].qs).toEqual({ org }); expect(mockedMakeRequest.mock.calls[0][0].body).toEqual({ results: [ { @@ -71,7 +74,7 @@ describe('tracking IaC test usage', () => { }); }); - await expect(trackUsage(results)).rejects.toThrow( + await expect(trackUsage(results, org)).rejects.toThrow( new TestLimitReachedError(), ); }); @@ -86,7 +89,7 @@ describe('tracking IaC test usage', () => { }); }); - await expect(trackUsage(results)).rejects.toThrow( + await expect(trackUsage(results, org)).rejects.toThrow( new CustomError( 'An error occurred while attempting to track test usage: {"foo":"bar"}', ),