Skip to content

Commit

Permalink
Merge pull request #4262 from snyk/fix/iac-usage-with-custom-org
Browse files Browse the repository at this point in the history
fix: iac usage tracking missing custom org
  • Loading branch information
rontalx committed Dec 28, 2022
2 parents 108f41e + 8e8fddb commit 3aa723b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac/local-execution/index.ts
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/cli/commands/test/iac/local-execution/usage-tracking.ts
Expand Up @@ -5,6 +5,7 @@ import { CustomError } from '../../../../../lib/errors';

export async function trackUsage(
formattedResults: TrackableResult[],
org: string, // e.g. "my.org"
): Promise<void> {
const trackingData = formattedResults.map((res) => {
return {
Expand All @@ -19,6 +20,7 @@ export async function trackUsage(
},
url: `${config.API}/track-iac-usage/cli`,
body: { results: trackingData },
qs: { org },
gzip: true,
json: true,
});
Expand Down
9 changes: 6 additions & 3 deletions test/jest/unit/iac/usage-tracking.spec.ts
Expand Up @@ -29,6 +29,8 @@ const results = [
},
];

const org = 'test-org';

describe('tracking IaC test usage', () => {
afterEach(() => {
jest.clearAllMocks();
Expand All @@ -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: [
{
Expand All @@ -71,7 +74,7 @@ describe('tracking IaC test usage', () => {
});
});

await expect(trackUsage(results)).rejects.toThrow(
await expect(trackUsage(results, org)).rejects.toThrow(
new TestLimitReachedError(),
);
});
Expand All @@ -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"}',
),
Expand Down

0 comments on commit 3aa723b

Please sign in to comment.