Skip to content

Commit

Permalink
Confirm that events without current_url are unmodified.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBennett authored Jun 17, 2022
1 parent 235d177 commit 411d490
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ function buildPageViewEvent(current_url: string): PluginEvent {
return event;
}

function buildEventWithoutCurrentUrl(): PluginEvent {
const event: PluginEvent = {
properties: {},
distinct_id: "distinct_id",
ip: "1.2.3.4",
site_url: "test.com",
team_id: 0,
now: "2022-06-17T20:21:31.778000+00:00",
event: "$identify",
uuid: "01817354-06bb-0000-d31c-2c4eed374100",
};

return event;
}

function getMeta(): PluginMeta<PluginInput> {
return {} as unknown as PluginMeta<PluginInput>;
}
Expand Down Expand Up @@ -75,7 +90,15 @@ describe("processEvent", () => {

it.todo("should preserve trailing anchors but drop trailing slashes");

it.todo("shouldn't modify events that don't have a current_url set");
it("shouldn't modify events that don't have a current_url set", () => {
const sourceEvent = buildEventWithoutCurrentUrl();

const processedEvent = processEvent(sourceEvent, getMeta());

expect(processedEvent).toEqual(sourceEvent);
expect(processedEvent?.properties).toEqual(sourceEvent.properties);
expect(processedEvent?.properties?.current_url).toBeUndefined();
});

// TODO: Determine the PostHog convention for handling errors in a plugin
it.todo("should raise an error if the current_url is an invalid url");
Expand Down

0 comments on commit 411d490

Please sign in to comment.