Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/lib/Insights/adapters/PlausibleAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class PlausibleAdapter {
return `${this.env.PUBLIC_ANALYTICS_API_HOST}/api/event`;
}

async forwardEvent(envelope, requestContext) {
async forwardEvent(envelope = {}, requestContext) {
// Disabled analytics intentionally ignores malformed events so local development
// and tests without a complete analytics configuration remain quiet.
if (!this.isEnabled()) {
return { status: 'analytics disabled' };
}
Expand Down
6 changes: 6 additions & 0 deletions src/tests/lib/Insights/adapters/PlausibleAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ describe('PlausibleAdapter.forwardEvent', () => {
).rejects.toThrow('forwardEvent requires name and url');
});

it('throws a clear validation error when called without an envelope', async () => {
await expect(new PlausibleAdapter(fullEnv).forwardEvent()).rejects.toThrow(
'forwardEvent requires name and url'
);
});

it('POSTs to {apiHost}/api/event', async () => {
await new PlausibleAdapter(fullEnv).forwardEvent(envelope, ctx);
expect(global.fetch).toHaveBeenCalledWith(
Expand Down
Loading