Skip to content

Commit 58d13c2

Browse files
committed
fix issues with audience offset
1 parent 97484cb commit 58d13c2

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

.husky/pre-push

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ then
66
exit 1
77
fi
88

9+
cd ./$(dirname "$0")/../dotcom-rendering
10+
make tsc
11+
12+
913
if git diff-tree --no-commit-id --name-only -r HEAD..origin/$currentBranch | grep -q 'ab-testing/'; then
10-
cd ./$(dirname "$0")/../ab-testing
14+
cd ../ab-testing
1115
deno test && deno run validate
1216
fi
13-
14-
cd ./$(dirname "$0")/../dotcom-rendering
15-
make tsc

ab-testing/abTest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const ABTests: ABTest[] = [
4040
status: 'ON',
4141
expirationDate: new Date('2025-09-02'),
4242
type: 'client',
43-
audienceSize: 20 / 100,
44-
audienceOffset: 10,
43+
audienceSize: 10 / 100,
44+
audienceOffset: 15 / 100,
4545
groups: ['control', 'variant'],
4646
},
4747
// Example server side AB test definition
@@ -72,7 +72,7 @@ export const ABTests: ABTest[] = [
7272
expirationDate: new Date('2025-08-04'),
7373
type: 'server',
7474
audienceSize: 10 / 100,
75-
audienceOffset: 30,
75+
audienceOffset: 30 / 100,
7676
groups: ['control', 'variant'],
7777
},
7878
{
@@ -87,7 +87,7 @@ export const ABTests: ABTest[] = [
8787
expirationDate: new Date('2025-08-04'),
8888
type: 'server',
8989
audienceSize: 10 / 100,
90-
audienceOffset: 40,
90+
audienceOffset: 45 / 100,
9191
groups: ['control', 'variant'],
9292
},
9393
];

ab-testing/scripts/validation/validSizeOffset.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,33 @@ Deno.test(
5252
);
5353
},
5454
);
55+
56+
Deno.test(
57+
'validSizeOffset - passes when audienceOffset is between 0 and 1',
58+
() => {
59+
const test: ABTest = {
60+
...baseTest,
61+
audienceSize: 0.5,
62+
audienceOffset: 0.1,
63+
};
64+
65+
assertEquals(validSizeOffset([test]), true);
66+
},
67+
);
68+
69+
Deno.test(
70+
'validSizeOffset - throws when audienceOffset is greater than 1',
71+
() => {
72+
const test: ABTest = {
73+
...baseTest,
74+
audienceSize: 0.5,
75+
audienceOffset: 11,
76+
};
77+
78+
assertThrows(
79+
() => validSizeOffset([test]),
80+
Error,
81+
`Invalid audienceOffset for test ${test.name}`,
82+
);
83+
},
84+
);

0 commit comments

Comments
 (0)