Skip to content

Commit

Permalink
chore: add some tests for server and client config
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsny committed Feb 14, 2025
1 parent 258ce85 commit 8bfc3c5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
67 changes: 67 additions & 0 deletions src/__tests__/extensions/replay/sessionrecording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,73 @@ describe('SessionRecording', () => {
)
})

describe('masking config', () => {
it.each([
[
'enabled when both enabled',
{ maskAllInputs: true, maskTextSelector: '*' },
{ maskAllInputs: true, maskTextSelector: '*' },
{ maskAllInputs: true, maskTextSelector: '*' },
],
[
'disabled when both disabled',
{ maskAllInputs: false },
{ maskAllInputs: false },
{ maskAllInputs: false },
],
[
'is undefined when nothing is set',
undefined,
undefined,
{
maskAllInputs: undefined,
maskTextSelector: undefined,
},
],
[
'uses client config when set if server config is not set',
undefined,
{ maskAllInputs: true, maskTextSelector: '#client' },
{ maskAllInputs: true, maskTextSelector: '#client' },
],
[
'uses server config when set if client config is not set',
{ maskAllInputs: false, maskTextSelector: '#server' },
undefined,
{ maskAllInputs: false, maskTextSelector: '#server' },
],
[
'overrides server config with client config if both are set',
{ maskAllInputs: false, maskTextSelector: '#server' },
{ maskAllInputs: true, maskTextSelector: '#client' },
{ maskAllInputs: true, maskTextSelector: '#client' },
],
[
'partially overrides server config with client config if both are set',
{ maskAllInputs: true, maskTextSelector: '*' },
{ maskAllInputs: false },
{ maskAllInputs: false, maskTextSelector: '*' },
],
])(
'%s',
(
_name: string,
serverConfig: { maskAllInputs?: boolean; maskTextSelector?: string } | undefined,
clientConfig: { maskAllInputs: boolean; maskTextSelector?: string } | undefined,
expected: { maskAllInputs: boolean; maskTextSelector?: string } | undefined
) => {
posthog.persistence?.register({
[SESSION_RECORDING_MASKING]: serverConfig,
})

posthog.config.session_recording.maskAllInputs = clientConfig?.maskAllInputs
posthog.config.session_recording.maskTextSelector = clientConfig?.maskTextSelector

expect(sessionRecording['masking']).toEqual(expected)
}
)
})

describe('startIfEnabledOrStop', () => {
beforeEach(() => {
// need to cast as any to mock private methods
Expand Down
7 changes: 5 additions & 2 deletions src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@ export class SessionRecording {
maskTextSelector: this.instance.config.session_recording?.maskTextSelector,
}

const maskAllInputs = masking_client_side?.maskAllInputs ?? masking_server_side?.maskAllInputs
const maskTextSelector = masking_client_side?.maskTextSelector ?? masking_server_side?.maskTextSelector

return {
...masking_server_side,
...masking_client_side,
maskAllInputs,
maskTextSelector,
}
}

Expand Down

0 comments on commit 8bfc3c5

Please sign in to comment.