-
Notifications
You must be signed in to change notification settings - Fork 30
Append abTestParticipations to the xcust query string param for Skimlinks #14792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a2a2cb6
90d4cdc
2ef4ed7
5d38a82
025484e
4d78447
6b72c6d
60d4ecc
4242934
0429420
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import '@testing-library/jest-dom'; | ||
| import { render } from '@testing-library/react'; | ||
| import { useBetaAB } from '../lib/useAB'; | ||
| import { EnhanceAffiliateLinks } from './EnhanceAffiliateLinks.importable'; | ||
|
|
||
| // Mock the useAB module | ||
| jest.mock('../lib/useAB', () => ({ | ||
| useBetaAB: jest.fn(), | ||
| })); | ||
|
|
||
| describe('EnhanceAffiliateLinks', () => { | ||
| beforeEach(() => { | ||
| // Clear the DOM before each test | ||
| document.body.innerHTML = ''; | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('should not modify links if no Skimlinks are present', () => { | ||
| document.body.innerHTML = ` | ||
| <a href="https://example.com">Not a Skimlink</a> | ||
| `; | ||
|
|
||
| render(<EnhanceAffiliateLinks />); | ||
|
|
||
| const link = document.querySelector('a'); | ||
| expect(link?.href).toBe('https://example.com/'); | ||
| }); | ||
|
|
||
| it('should append xcust parameter to Skimlinks with refferer set to none if unavailable', () => { | ||
| Object.defineProperty(document, 'referrer', { | ||
| value: '', | ||
| configurable: true, | ||
| }); | ||
|
|
||
| document.body.innerHTML = ` | ||
| <a href="https://go.skimresources.com/?id=12345">Skimlink</a> | ||
| `; | ||
|
|
||
| render(<EnhanceAffiliateLinks />); | ||
|
|
||
| const link = document.querySelector('a'); | ||
| expect(link?.href).toContain( | ||
| 'xcust=referrer%7Cnone%7CaccountId%7C12345', | ||
| ); | ||
| }); | ||
|
|
||
| it('should append xcust parameter to Skimlinks with refferer set if available', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also minor spelling mistake on referrer |
||
| Object.defineProperty(document, 'referrer', { | ||
| value: 'https://foo.com', | ||
| configurable: true, | ||
| }); | ||
|
|
||
| document.body.innerHTML = ` | ||
| <a href="https://go.skimresources.com/?id=12345">Skimlink</a> | ||
| `; | ||
|
|
||
| render(<EnhanceAffiliateLinks />); | ||
|
|
||
| const link = document.querySelector('a'); | ||
| expect(link?.href).toContain( | ||
| 'xcust=referrer%7Cfoo.com%7CaccountId%7C12345', | ||
| ); | ||
| }); | ||
|
|
||
| it('should include AB test participations in xcust if present', () => { | ||
| document.body.innerHTML = ` | ||
| <a href="https://go.skimresources.com/?id=12345">Skimlink</a> | ||
| `; | ||
|
|
||
| (useBetaAB as jest.Mock).mockReturnValue({ | ||
| getParticipations: () => ({ | ||
| test1: 'variantA', | ||
| test2: 'variantB', | ||
| }), | ||
| }); | ||
|
|
||
| render(<EnhanceAffiliateLinks />); | ||
|
|
||
| const link = document.querySelector('a'); | ||
| expect(link?.href).toContain( | ||
| 'xcust=referrer%7Cfoo.com%7CaccountId%7C12345%7CabTestParticipations%7Ctest1%3AvariantA%2Ctest2%3AvariantB', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, is the test naming case sensitive? |
||
| ); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor:
referrerrather thanrefferer