Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: iac usage tracking missing custom org #4262

Merged
merged 1 commit into from Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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