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
3 changes: 3 additions & 0 deletions src/schemas/v1/page-hit-processed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const PageHitProcessedSchema = Type.Object({
member_status: Type.Union([Type.String({minLength: 1}), Type.Literal('undefined')]),
post_uuid: Type.Union([Type.String({format: 'uuid'}), Type.Literal('undefined')]),
post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]),
// Gift-link token, present only on gift reads; absent/null otherwise.
gift: Type.Optional(Type.Union([Type.String(), Type.Null()])),
locale: Type.String({minLength: 1}),
location: Type.Union([Type.String({minLength: 1}), Type.Null()]),
pathname: Type.String({minLength: 1}),
Expand Down Expand Up @@ -161,6 +163,7 @@ export async function transformPageHitRawToProcessed(
member_status: pageHitRaw.payload.member_status,
post_uuid: pageHitRaw.payload.post_uuid,
post_type: pageHitRaw.payload.post_type,
gift: pageHitRaw.payload.gift,
Comment thread
jonatansberg marked this conversation as resolved.
locale: pageHitRaw.payload.locale,
location: pageHitRaw.payload.location,
pathname: pageHitRaw.payload.pathname,
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/v1/page-hit-raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const PayloadSchema = Type.Object({
member_status: Type.Union([NonEmptyStringSchema, Type.Literal('undefined')]),
post_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]),
post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]),
// Gift-link token, present only on gift reads; absent/null otherwise.
gift: Type.Optional(Type.Union([StringSchema, Type.Null()])),
locale: NonEmptyStringSchema,
location: Type.Union([NonEmptyStringSchema, Type.Null()]),
referrer: Type.Optional(Type.Union([StringSchema, Type.Null()])),
Expand Down
3 changes: 3 additions & 0 deletions src/schemas/v1/page-hit-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const PageHitRequestPayloadSchema = Type.Object({
site_uuid: UUIDSchema,
post_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]),
post_type: Type.Union([Type.Literal('null'), Type.Literal('post'), Type.Literal('page')]),
// Gift-link token, present only on gift reads; absent/null otherwise.
gift: Type.Optional(Type.Union([StringSchema, Type.Null()])),
member_uuid: Type.Union([UUIDSchema, Type.Literal('undefined')]),
member_status: Type.Union([NonEmptyStringSchema, Type.Literal('undefined')]),
utm_source: Type.Optional(Type.Union([StringSchema, Type.Null()])),
Expand Down Expand Up @@ -140,6 +142,7 @@ export const PageHitRequestPayloadDefaults = {
site_uuid: '',
post_uuid: 'undefined',
post_type: 'null',
gift: null,
member_uuid: 'undefined',
member_status: 'undefined',
utm_source: null,
Expand Down
1 change: 1 addition & 0 deletions src/transformations/page-hit-transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const pageHitRawPayloadFromRequest = (request: PageHitRequestType): PageH
member_status: request.body.payload.member_status,
post_uuid: request.body.payload.post_uuid,
post_type: request.body.payload.post_type,
gift: request.body.payload.gift ?? null,
Comment thread
jonatansberg marked this conversation as resolved.
locale: request.body.payload.locale,
location: request.body.payload.location,
referrer: request.body.payload.referrer ?? null,
Expand Down
11 changes: 11 additions & 0 deletions test/unit/transformations/page-hit-transformations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('pageHitRawPayloadFromRequest', () => {
member_status: 'free',
post_uuid: 'post-uuid-456',
post_type: 'post',
gift: 'gift-token-789',
locale: 'en-US',
location: 'homepage',
referrer: 'https://google.com',
Expand Down Expand Up @@ -52,6 +53,7 @@ describe('pageHitRawPayloadFromRequest', () => {
member_status: 'free',
post_uuid: 'post-uuid-456',
post_type: 'post',
gift: 'gift-token-789',
locale: 'en-US',
location: 'homepage',
referrer: 'https://google.com',
Expand All @@ -77,6 +79,15 @@ describe('pageHitRawPayloadFromRequest', () => {
});
});

it('defaults gift to null when absent (non-gift hit)', () => {
const request = createPageHitRequest();
delete request.body.payload.gift;

const result = pageHitRawPayloadFromRequest(request);

expect(result.payload.gift).toBeNull();
});

describe('Event ID', () => {
const uuidMatcher = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

Expand Down