@@ -17,7 +17,11 @@ import jwt from 'jsonwebtoken';
17
17
import rison from 'rison' ;
18
18
import { DeepPartial } from 'ts-essentials' ;
19
19
20
- import { getVisitorAuthCookieName , getVisitorAuthCookieValue } from '@/lib/visitor-auth' ;
20
+ import {
21
+ getVisitorAuthCookieName ,
22
+ getVisitorAuthCookieValue ,
23
+ VISITOR_TOKEN_COOKIE ,
24
+ } from '@/lib/visitor-token' ;
21
25
22
26
import { getContentTestURL } from '../tests/utils' ;
23
27
@@ -1081,6 +1085,149 @@ const testCases: TestsCase[] = [
1081
1085
} ,
1082
1086
] ,
1083
1087
} ,
1088
+ {
1089
+ name : 'Adaptive Content - Public' ,
1090
+ baseUrl : `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-public/` ,
1091
+ tests : [
1092
+ {
1093
+ name : 'No custom cookie' ,
1094
+ url : '' ,
1095
+ run : async ( page ) => {
1096
+ const welcomePage = page
1097
+ . locator ( 'a[class*="group\\/toclink"]' )
1098
+ . filter ( { hasText : 'Welcome Page' } ) ;
1099
+ const alphaUserPage = page
1100
+ . locator ( 'a[class*="group\\/toclink"]' )
1101
+ . filter ( { hasText : 'Alpha User' } ) ;
1102
+ const betaUserPage = page
1103
+ . locator ( 'a[class*="group\\/toclink"]' )
1104
+ . filter ( { hasText : 'Beta User' } ) ;
1105
+
1106
+ await expect ( welcomePage ) . toBeVisible ( ) ;
1107
+ await expect ( alphaUserPage ) . toHaveCount ( 0 ) ;
1108
+ await expect ( betaUserPage ) . toHaveCount ( 0 ) ;
1109
+ } ,
1110
+ } ,
1111
+ {
1112
+ name : 'Custom cookie with isAlphaUser claim' ,
1113
+ cookies : ( ( ) => {
1114
+ const privateKey = '4ddd3c2f-e4b7-4e73-840b-526c3be19746' ;
1115
+ const token = jwt . sign (
1116
+ {
1117
+ name : 'gitbook-open-tests' ,
1118
+ isAlphaUser : true ,
1119
+ } ,
1120
+ privateKey ,
1121
+ {
1122
+ expiresIn : '24h' ,
1123
+ } ,
1124
+ ) ;
1125
+ return [
1126
+ {
1127
+ name : VISITOR_TOKEN_COOKIE ,
1128
+ value : token ,
1129
+ httpOnly : true ,
1130
+ } ,
1131
+ ] ;
1132
+ } ) ( ) ,
1133
+ url : '' ,
1134
+ run : async ( page ) => {
1135
+ const welcomePage = page
1136
+ . locator ( 'a[class*="group\\/toclink"]' )
1137
+ . filter ( { hasText : 'Welcome Page' } ) ;
1138
+ const alphaUserPage = page
1139
+ . locator ( 'a[class*="group\\/toclink"]' )
1140
+ . filter ( { hasText : 'Alpha User' } ) ;
1141
+ const betaUserPage = page
1142
+ . locator ( 'a[class*="group\\/toclink"]' )
1143
+ . filter ( { hasText : 'Beta User' } ) ;
1144
+
1145
+ await expect ( welcomePage ) . toBeVisible ( ) ;
1146
+ await expect ( alphaUserPage ) . toBeVisible ( ) ;
1147
+ await expect ( betaUserPage ) . toHaveCount ( 0 ) ;
1148
+ } ,
1149
+ } ,
1150
+ {
1151
+ name : 'Custom cookie with isBetaUser claim' ,
1152
+ cookies : ( ( ) => {
1153
+ const privateKey = '4ddd3c2f-e4b7-4e73-840b-526c3be19746' ;
1154
+ const token = jwt . sign (
1155
+ {
1156
+ name : 'gitbook-open-tests' ,
1157
+ isBetaUser : true ,
1158
+ } ,
1159
+ privateKey ,
1160
+ {
1161
+ expiresIn : '24h' ,
1162
+ } ,
1163
+ ) ;
1164
+ return [
1165
+ {
1166
+ name : VISITOR_TOKEN_COOKIE ,
1167
+ value : token ,
1168
+ httpOnly : true ,
1169
+ } ,
1170
+ ] ;
1171
+ } ) ( ) ,
1172
+ url : '' ,
1173
+ run : async ( page ) => {
1174
+ const welcomePage = page
1175
+ . locator ( 'a[class*="group\\/toclink"]' )
1176
+ . filter ( { hasText : 'Welcome Page' } ) ;
1177
+ const alphaUserPage = page
1178
+ . locator ( 'a[class*="group\\/toclink"]' )
1179
+ . filter ( { hasText : 'Alpha User' } ) ;
1180
+ const betaUserPage = page
1181
+ . locator ( 'a[class*="group\\/toclink"]' )
1182
+ . filter ( { hasText : 'Beta User' } ) ;
1183
+
1184
+ await expect ( welcomePage ) . toBeVisible ( ) ;
1185
+ await expect ( betaUserPage ) . toBeVisible ( ) ;
1186
+ await expect ( alphaUserPage ) . toHaveCount ( 0 ) ;
1187
+ } ,
1188
+ } ,
1189
+ {
1190
+ name : 'Custom cookie with isAlphaUser & isBetaUser claims' ,
1191
+ cookies : ( ( ) => {
1192
+ const privateKey = '4ddd3c2f-e4b7-4e73-840b-526c3be19746' ;
1193
+ const token = jwt . sign (
1194
+ {
1195
+ name : 'gitbook-open-tests' ,
1196
+ isAlphaUser : true ,
1197
+ isBetaUser : true ,
1198
+ } ,
1199
+ privateKey ,
1200
+ {
1201
+ expiresIn : '24h' ,
1202
+ } ,
1203
+ ) ;
1204
+ return [
1205
+ {
1206
+ name : VISITOR_TOKEN_COOKIE ,
1207
+ value : token ,
1208
+ httpOnly : true ,
1209
+ } ,
1210
+ ] ;
1211
+ } ) ( ) ,
1212
+ url : '' ,
1213
+ run : async ( page ) => {
1214
+ const welcomePage = page
1215
+ . locator ( 'a[class*="group\\/toclink"]' )
1216
+ . filter ( { hasText : 'Welcome Page' } ) ;
1217
+ const alphaUserPage = page
1218
+ . locator ( 'a[class*="group\\/toclink"]' )
1219
+ . filter ( { hasText : 'Alpha User' } ) ;
1220
+ const betaUserPage = page
1221
+ . locator ( 'a[class*="group\\/toclink"]' )
1222
+ . filter ( { hasText : 'Beta User' } ) ;
1223
+
1224
+ await expect ( welcomePage ) . toBeVisible ( ) ;
1225
+ await expect ( betaUserPage ) . toBeVisible ( ) ;
1226
+ await expect ( alphaUserPage ) . toBeVisible ( ) ;
1227
+ } ,
1228
+ } ,
1229
+ ] ,
1230
+ } ,
1084
1231
{
1085
1232
name : 'Tables' ,
1086
1233
baseUrl : 'https://gitbook.gitbook.io/test-gitbook-open/' ,
0 commit comments