Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Rokt-Kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface RoktKitSettings {
onboardingExpProvider?: string;
loggingUrl?: string;
errorUrl?: string;
isLoggingEnabled?: string | boolean;
workspaceIdSyncApiKey?: string;
}

Expand Down Expand Up @@ -151,7 +150,7 @@ interface MParticleExtended {
getInstance(): MParticleInstance;
sessionManager?: { getSession(): string };
_getActiveForwarders(): Array<{ name: string }>;
config?: { isLocalLauncherEnabled?: boolean };
config?: { isLocalLauncherEnabled?: boolean; isLoggingEnabled?: boolean };
captureTiming?(metricName: string): void;
forwarder?: RoktKit;
loggedEvents?: Array<Record<string, unknown>>;
Expand Down Expand Up @@ -189,7 +188,7 @@ interface ForwarderRegistration {
interface ReportingConfig {
loggingUrl?: string;
errorUrl?: string;
isLoggingEnabled?: boolean | string;
isLoggingEnabled: boolean;
}

interface ErrorReport {
Expand Down Expand Up @@ -554,7 +553,7 @@ class ReportingTransport {
accountId: string | null | undefined,
rateLimiter?: RateLimiter,
) {
const isLoggingEnabled = config?.isLoggingEnabled === true || config?.isLoggingEnabled === 'true';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫨

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so even this code previously was technically wrong and no one caught it. because MPServer actually sends things back as "True" and not "true", or true. 🙃

const isLoggingEnabled = config.isLoggingEnabled;
this._integrationName = integrationName || '';
this._launcherInstanceGuid = launcherInstanceGuid;
this._accountId = accountId || null;
Expand Down Expand Up @@ -1113,7 +1112,7 @@ class RoktKit implements KitInterface {
const reportingConfig: ReportingConfig = {
loggingUrl: kitSettings.loggingUrl,
errorUrl: kitSettings.errorUrl,
isLoggingEnabled: kitSettings.isLoggingEnabled === 'true' || kitSettings.isLoggingEnabled === true,
isLoggingEnabled: mp().config?.isLoggingEnabled === true,
};
const errorReportingService = new ErrorReportingService(
reportingConfig,
Expand Down
71 changes: 64 additions & 7 deletions test/src/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6595,13 +6595,7 @@ describe('Rokt Forwarder', () => {
filteredUser: { getMPID: () => '123' },
};

await mParticle.forwarder.init(
{ accountId: '123456', isLoggingEnabled: 'true' },
reportService.cb,
true,
null,
{},
);
await mParticle.forwarder.init({ accountId: '123456' }, reportService.cb, true, null, {});

expect(registeredErrorService).not.toBeNull();
expect(registeredLoggingService).not.toBeNull();
Expand All @@ -6612,6 +6606,69 @@ describe('Rokt Forwarder', () => {
delete (window as any).mParticle._registerLoggingService;
});

it('should enable registered logging service from mParticle config', async () => {
let registeredLoggingService: any = null;
const fetchCalls: Array<{ url: string; options: any }> = [];
const originalFetch = window.fetch;
const originalRoktDomain = (window as any).ROKT_DOMAIN;
const originalConfig = (window as any).mParticle.config;

try {
(window as any).fetch = (url: string, options: any) => {
fetchCalls.push({ url, options });
return Promise.resolve({ ok: true });
};
(window as any).ROKT_DOMAIN = 'set';
(window as any).mParticle.config = {
...originalConfig,
isLoggingEnabled: true,
};

(window as any).mParticle._registerErrorReportingService = () => {};
(window as any).mParticle._registerLoggingService = (service: any) => {
registeredLoggingService = service;
};

(window as any).Rokt = new (MockRoktForwarder as any)();
(window as any).mParticle.Rokt = (window as any).Rokt;
(window as any).mParticle.Rokt.attachKit = async (kit: any) => {
(window as any).mParticle.Rokt.kit = kit;
};
(window as any).mParticle.Rokt.filters = {
userAttributesFilters: [],
filterUserAttributes: (attributes: any) => attributes,
filteredUser: { getMPID: () => '123' },
};

await mParticle.forwarder.init(
{ accountId: '123456', loggingUrl: 'test.com/v1/log' },
reportService.cb,
true,
null,
{},
);

expect(registeredLoggingService).not.toBeNull();

registeredLoggingService.log({
message: 'global logging flag is enabled',
code: ErrorCodesConst.UNKNOWN_ERROR,
});

expect(fetchCalls.length).toBe(1);
expect(fetchCalls[0].url).toBe('https://test.com/v1/log');
const body = JSON.parse(fetchCalls[0].options.body);
expect(body.additionalInformation.message).toBe('global logging flag is enabled');
expect(body.code).toBe(ErrorCodesConst.UNKNOWN_ERROR);
} finally {
window.fetch = originalFetch;
(window as any).ROKT_DOMAIN = originalRoktDomain;
(window as any).mParticle.config = originalConfig;
delete (window as any).mParticle._registerErrorReportingService;
delete (window as any).mParticle._registerLoggingService;
}
});

it('should not throw when registration methods do not exist', async () => {
delete (window as any).mParticle._registerErrorReportingService;
delete (window as any).mParticle._registerLoggingService;
Expand Down
3 changes: 3 additions & 0 deletions test/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
(globalThis as any).mParticle.forwarder = new forwarder.constructor();
},
Rokt: {},
config: {
isLoggingEnabled: true,
},
EventType: { Other: 8 },
getEnvironment: () => 'development',
getVersion: () => '1.2.3',
Expand Down
Loading