@@ -6896,230 +6896,6 @@ describes.realWin('AutoPromptManager', (env) => {
68966896 } ) ;
68976897 } ) ;
68986898
6899- it ( 'getTimestampsForPromptFrequency_ should return dismissals and completions timestamps for DISMISSIBLE closability' , async ( ) => {
6900- const actionsTimestamps = {
6901- 'TYPE_CONTRIBUTION' : {
6902- 'impressions' : [ 'c_i1' , 'c_i2' , 'c_i3' ] ,
6903- 'dismissals' : [ 'c_d1' , 'c_d2' , 'c_d3' ] ,
6904- 'completions' : [ 'c_c1' , 'c_c2' , 'c_c3' ] ,
6905- } ,
6906- 'TYPE_REWARDED_SURVEY' : {
6907- 'impressions' : [ 's_i1' , 's_i2' , 's_i3' ] ,
6908- 'dismissals' : [ 's_d1' , 's_d2' , 's_d3' ] ,
6909- 'completions' : [ 's_c1' , 's_c2' , 's_c3' ] ,
6910- } ,
6911- } ;
6912-
6913- const timestamps = autoPromptManager . getTimestampsForPromptFrequency_ (
6914- actionsTimestamps ,
6915- { 'type' : 'TYPE_REWARDED_SURVEY' , closability : 'DISMISSIBLE' }
6916- ) ;
6917-
6918- expect ( timestamps . length ) . to . equal ( 6 ) ;
6919- expect ( timestamps [ 0 ] ) . to . equal ( 's_d1' ) ;
6920- expect ( timestamps [ 1 ] ) . to . equal ( 's_d2' ) ;
6921- expect ( timestamps [ 2 ] ) . to . equal ( 's_d3' ) ;
6922- expect ( timestamps [ 3 ] ) . to . equal ( 's_c1' ) ;
6923- expect ( timestamps [ 4 ] ) . to . equal ( 's_c2' ) ;
6924- expect ( timestamps [ 5 ] ) . to . equal ( 's_c3' ) ;
6925- } ) ;
6926-
6927- it ( 'getTimestampsForPromptFrequency_ should return completions timestamps for BLOCKING closability' , async ( ) => {
6928- const actionsTimestamps = {
6929- 'TYPE_CONTRIBUTION' : {
6930- 'impressions' : [ 'c_i1' , 'c_i2' , 'c_i3' ] ,
6931- 'dismissals' : [ 'c_d1' , 'c_d2' , 'c_d3' ] ,
6932- 'completions' : [ 'c_c1' , 'c_c2' , 'c_c3' ] ,
6933- } ,
6934- 'TYPE_REWARDED_SURVEY' : {
6935- 'impressions' : [ 's_i1' , 's_i2' , 's_i3' ] ,
6936- 'dismissals' : [ 's_d1' , 's_d2' , 's_d3' ] ,
6937- 'completions' : [ 's_c1' , 's_c2' , 's_c3' ] ,
6938- } ,
6939- } ;
6940-
6941- const timestamps = autoPromptManager . getTimestampsForPromptFrequency_ (
6942- actionsTimestamps ,
6943- { 'type' : 'TYPE_REWARDED_SURVEY' , closability : 'BLOCKING' }
6944- ) ;
6945-
6946- expect ( timestamps . length ) . to . equal ( 3 ) ;
6947- expect ( timestamps [ 0 ] ) . to . equal ( 's_c1' ) ;
6948- expect ( timestamps [ 1 ] ) . to . equal ( 's_c2' ) ;
6949- expect ( timestamps [ 2 ] ) . to . equal ( 's_c3' ) ;
6950- } ) ;
6951-
6952- it ( 'getTimestampsForPromptFrequency_ should return dismissals and completions timestamps by configId for DISMISSIBLE closability' , async ( ) => {
6953- const actionsTimestamps = {
6954- 'contribution_config_id' : {
6955- 'impressions' : [ 'c_i1' , 'c_i2' , 'c_i3' ] ,
6956- 'dismissals' : [ 'c_d1' , 'c_d2' , 'c_d3' ] ,
6957- 'completions' : [ 'c_c1' , 'c_c2' , 'c_c3' ] ,
6958- } ,
6959- 'survey_config_id' : {
6960- 'impressions' : [ 's_i1' , 's_i2' , 's_i3' ] ,
6961- 'dismissals' : [ 's_d1' , 's_d2' , 's_d3' ] ,
6962- 'completions' : [ 's_c1' , 's_c2' , 's_c3' ] ,
6963- } ,
6964- } ;
6965-
6966- const timestamps = autoPromptManager . getTimestampsForPromptFrequency_ (
6967- actionsTimestamps ,
6968- { 'type' : 'survey_config_id' , closability : 'DISMISSIBLE' }
6969- ) ;
6970-
6971- expect ( timestamps . length ) . to . equal ( 6 ) ;
6972- expect ( timestamps [ 0 ] ) . to . equal ( 's_d1' ) ;
6973- expect ( timestamps [ 1 ] ) . to . equal ( 's_d2' ) ;
6974- expect ( timestamps [ 2 ] ) . to . equal ( 's_d3' ) ;
6975- expect ( timestamps [ 3 ] ) . to . equal ( 's_c1' ) ;
6976- expect ( timestamps [ 4 ] ) . to . equal ( 's_c2' ) ;
6977- expect ( timestamps [ 5 ] ) . to . equal ( 's_c3' ) ;
6978- } ) ;
6979-
6980- it ( 'getTimestampsForPromptFrequency_ should return completions timestamps by configId for BLOCKING closability' , async ( ) => {
6981- const actionsTimestamps = {
6982- 'contribution_config_id' : {
6983- 'impressions' : [ 'c_i1' , 'c_i2' , 'c_i3' ] ,
6984- 'dismissals' : [ 'c_d1' , 'c_d2' , 'c_d3' ] ,
6985- 'completions' : [ 'c_c1' , 'c_c2' , 'c_c3' ] ,
6986- } ,
6987- 'survey_config_id' : {
6988- 'impressions' : [ 's_i1' , 's_i2' , 's_i3' ] ,
6989- 'dismissals' : [ 's_d1' , 's_d2' , 's_d3' ] ,
6990- 'completions' : [ 's_c1' , 's_c2' , 's_c3' ] ,
6991- } ,
6992- } ;
6993-
6994- const timestamps = autoPromptManager . getTimestampsForPromptFrequency_ (
6995- actionsTimestamps ,
6996- { 'type' : 'survey_config_id' , closability : 'BLOCKING' }
6997- ) ;
6998-
6999- expect ( timestamps . length ) . to . equal ( 3 ) ;
7000- expect ( timestamps [ 0 ] ) . to . equal ( 's_c1' ) ;
7001- expect ( timestamps [ 1 ] ) . to . equal ( 's_c2' ) ;
7002- expect ( timestamps [ 2 ] ) . to . equal ( 's_c3' ) ;
7003- } ) ;
7004-
7005- it ( 'getPromptFrequencyCapDuration_ should return valid intervention config' , async ( ) => {
7006- const expectedDuration = { seconds : 600 } ;
7007-
7008- const result = autoPromptManager . getPromptFrequencyCapDuration_ (
7009- { } ,
7010- { promptFrequencyCap : { duration : expectedDuration } }
7011- ) ;
7012-
7013- expect ( result ) . to . equal ( expectedDuration ) ;
7014- } ) ;
7015-
7016- it ( 'getPromptFrequencyCapDuration_ should return default anyPromptFrequencyCap for invalid intervention config' , async ( ) => {
7017- const expectedDuration = { seconds : 600 } ;
7018-
7019- const result = autoPromptManager . getPromptFrequencyCapDuration_ (
7020- { anyPromptFrequencyCap : { frequencyCapDuration : expectedDuration } } ,
7021- { }
7022- ) ;
7023-
7024- expect ( result ) . to . equal ( expectedDuration ) ;
7025- } ) ;
7026-
7027- it ( 'getGlobalFrequencyCapDuration_ should return valid intervention config' , async ( ) => {
7028- const expectedDuration = { seconds : 60 } ;
7029-
7030- const result = autoPromptManager . getGlobalFrequencyCapDuration_ (
7031- { } ,
7032- { globalFrequencyCap : { duration : expectedDuration } }
7033- ) ;
7034-
7035- expect ( result ) . to . equal ( expectedDuration ) ;
7036- } ) ;
7037-
7038- it ( 'getGlobalFrequencyCapDuration_ should return defualt globalFrequencyCap for invalid intervention config' , ( ) => {
7039- const expectedDuration = { seconds : 600 } ;
7040-
7041- const result = autoPromptManager . getGlobalFrequencyCapDuration_ (
7042- { globalFrequencyCap : { frequencyCapDuration : expectedDuration } } ,
7043- { }
7044- ) ;
7045-
7046- expect ( result ) . to . equal ( expectedDuration ) ;
7047- } ) ;
7048-
7049- it ( 'isFrequencyCapped_ should return false for empty impressions' , async ( ) => {
7050- const duration = { seconds : 60 , nanos : 0 } ;
7051-
7052- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7053- duration ,
7054- [ ]
7055- ) ;
7056-
7057- expect ( isFrequencyCapped ) . to . equal ( false ) ;
7058- } ) ;
7059-
7060- it ( 'isFrequencyCapped_ should return false for impressions that occurred outside of the cap duration' , async ( ) => {
7061- const duration = { seconds : 60 , nanos : 0 } ;
7062- const impressions = [ CURRENT_TIME - 120 * SECOND_IN_MS ] ;
7063-
7064- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7065- duration ,
7066- impressions
7067- ) ;
7068-
7069- expect ( isFrequencyCapped ) . to . equal ( false ) ;
7070- } ) ;
7071-
7072- it ( 'isFrequencyCapped_ should return true if the max impression occurred within of the cap duration' , async ( ) => {
7073- const duration = { seconds : 60 , nanos : 0 } ;
7074- const impressions = [
7075- CURRENT_TIME - 10 * SECOND_IN_MS ,
7076- CURRENT_TIME - 120 * SECOND_IN_MS ,
7077- ] ;
7078-
7079- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7080- duration ,
7081- impressions
7082- ) ;
7083-
7084- expect ( isFrequencyCapped ) . to . equal ( true ) ;
7085- } ) ;
7086-
7087- it ( 'isFrequencyCapped_ should return true for impressions that occurred within the cap duration' , async ( ) => {
7088- const duration = { seconds : 60 , nanos : 0 } ;
7089- const impressions = [ CURRENT_TIME - 10 * SECOND_IN_MS ] ;
7090-
7091- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7092- duration ,
7093- impressions
7094- ) ;
7095-
7096- expect ( isFrequencyCapped ) . to . equal ( true ) ;
7097- } ) ;
7098-
7099- it ( 'isFrequencyCapped_ should return true if the max impression occurred within the cap duration, including nanos' , async ( ) => {
7100- const duration = { seconds : 60 , nanos : 60 * SECOND_IN_NANO } ;
7101- const impressions = [ CURRENT_TIME - 90 * SECOND_IN_MS ] ;
7102-
7103- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7104- duration ,
7105- impressions
7106- ) ;
7107-
7108- expect ( isFrequencyCapped ) . to . equal ( true ) ;
7109- } ) ;
7110-
7111- it ( 'isFrequencyCapped_ should return false if the max impression occurred within the cap duration, including negative nanos' , async ( ) => {
7112- const duration = { seconds : 120 , nanos : - 60 * SECOND_IN_NANO } ;
7113- const impressions = [ CURRENT_TIME - 90 * SECOND_IN_MS ] ;
7114-
7115- const isFrequencyCapped = autoPromptManager . isFrequencyCapped_ (
7116- duration ,
7117- impressions
7118- ) ;
7119-
7120- expect ( isFrequencyCapped ) . to . equal ( false ) ;
7121- } ) ;
7122-
71236899 it ( 'checkOrchestrationEligibility_ should log an error if completion count is missing for a repeatable action' , async ( ) => {
71246900 const isEligible = autoPromptManager . checkOrchestrationEligibility_ (
71256901 {
0 commit comments