@@ -46,6 +46,9 @@ import {
4646 NotificationPreferenceStatus ,
4747 NotificationType ,
4848} from '../../src/notifications/common' ;
49+ import { personalizedDigestSnotraClient } from '../../src/common/personalizedDigest' ;
50+ import { PersonaliseState } from '../../src/integrations/snotra/types' ;
51+ import { FeedConfigName } from '../../src/integrations/feed/types' ;
4952
5053jest . mock ( '../../src/common' , ( ) => ( {
5154 ...( jest . requireActual ( '../../src/common' ) as Record < string , unknown > ) ,
@@ -1192,6 +1195,101 @@ describe('personalizedDigestEmail worker', () => {
11921195 } ) ;
11931196 } ) ;
11941197
1198+ describe ( 'digest_cs_v1 experiment' , ( ) => {
1199+ const experimentConfig = {
1200+ templateId : '48' ,
1201+ maxPosts : 5 ,
1202+ feedConfig : FeedConfigName . DigestCsV1 ,
1203+ } ;
1204+
1205+ it ( 'should use digest_v2 when snotra reports any state other than non_personalised' , async ( ) => {
1206+ const spy = jest
1207+ . spyOn ( personalizedDigestSnotraClient , 'getUserProfile' )
1208+ . mockResolvedValue ( {
1209+ personalise : { state : 'some_other_state' as PersonaliseState } ,
1210+ } ) ;
1211+
1212+ const personalizedDigest = await con
1213+ . getRepository ( UserPersonalizedDigest )
1214+ . findOneBy ( { userId : '1' } ) ;
1215+
1216+ await expectSuccessfulBackground ( worker , {
1217+ personalizedDigest,
1218+ ...getDates ( personalizedDigest ! , Date . now ( ) ) ,
1219+ emailBatchId : 'test-email-batch-id' ,
1220+ config : experimentConfig ,
1221+ } ) ;
1222+
1223+ expect ( spy ) . toHaveBeenCalledWith ( {
1224+ user_id : '1' ,
1225+ providers : { personalise : { } } ,
1226+ } ) ;
1227+ expect ( nockBody . feed_config_name ) . toBe ( FeedConfigName . DigestV2 ) ;
1228+ } ) ;
1229+
1230+ it ( 'should use digest_cs_v1 when snotra reports user is non_personalised' , async ( ) => {
1231+ jest
1232+ . spyOn ( personalizedDigestSnotraClient , 'getUserProfile' )
1233+ . mockResolvedValue ( {
1234+ personalise : { state : PersonaliseState . NonPersonalised } ,
1235+ } ) ;
1236+
1237+ const personalizedDigest = await con
1238+ . getRepository ( UserPersonalizedDigest )
1239+ . findOneBy ( { userId : '1' } ) ;
1240+
1241+ await expectSuccessfulBackground ( worker , {
1242+ personalizedDigest,
1243+ ...getDates ( personalizedDigest ! , Date . now ( ) ) ,
1244+ emailBatchId : 'test-email-batch-id' ,
1245+ config : experimentConfig ,
1246+ } ) ;
1247+
1248+ expect ( nockBody . feed_config_name ) . toBe ( FeedConfigName . DigestCsV1 ) ;
1249+ } ) ;
1250+
1251+ it ( 'should fall back to digest_v2 when snotra call fails' , async ( ) => {
1252+ jest
1253+ . spyOn ( personalizedDigestSnotraClient , 'getUserProfile' )
1254+ . mockRejectedValue ( new Error ( 'snotra down' ) ) ;
1255+
1256+ const personalizedDigest = await con
1257+ . getRepository ( UserPersonalizedDigest )
1258+ . findOneBy ( { userId : '1' } ) ;
1259+
1260+ await expectSuccessfulBackground ( worker , {
1261+ personalizedDigest,
1262+ ...getDates ( personalizedDigest ! , Date . now ( ) ) ,
1263+ emailBatchId : 'test-email-batch-id' ,
1264+ config : experimentConfig ,
1265+ } ) ;
1266+
1267+ expect ( nockBody . feed_config_name ) . toBe ( FeedConfigName . DigestV2 ) ;
1268+ } ) ;
1269+
1270+ it ( 'should not call snotra when feedConfig is not the experiment marker' , async ( ) => {
1271+ const spy = jest . spyOn ( personalizedDigestSnotraClient , 'getUserProfile' ) ;
1272+
1273+ const personalizedDigest = await con
1274+ . getRepository ( UserPersonalizedDigest )
1275+ . findOneBy ( { userId : '1' } ) ;
1276+
1277+ await expectSuccessfulBackground ( worker , {
1278+ personalizedDigest,
1279+ ...getDates ( personalizedDigest ! , Date . now ( ) ) ,
1280+ emailBatchId : 'test-email-batch-id' ,
1281+ config : {
1282+ templateId : '48' ,
1283+ maxPosts : 5 ,
1284+ feedConfig : 'some_other_config' ,
1285+ } ,
1286+ } ) ;
1287+
1288+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1289+ expect ( nockBody . feed_config_name ) . toBe ( 'some_other_config' ) ;
1290+ } ) ;
1291+ } ) ;
1292+
11951293 it ( 'should generate personalized digest without an ad for plus members' , async ( ) => {
11961294 const personalizedDigest = await con
11971295 . getRepository ( UserPersonalizedDigest )
0 commit comments