@@ -107,4 +107,63 @@ describe("PingType", function() {
107107 const storedPings = await Context . pingsDatabase [ "store" ] . _getWholeStore ( ) ;
108108 assert . strictEqual ( Object . keys ( storedPings ) . length , 0 ) ;
109109 } ) ;
110+
111+ it ( "runs a validator with no metrics tests" , async function ( ) {
112+ const ping = new PingType ( {
113+ name : "custom" ,
114+ includeClientId : true ,
115+ sendIfEmpty : false ,
116+ reasonCodes : [ "test" ]
117+ } ) ;
118+
119+ // We did not call the testing API yet, internals should be undefined.
120+ assert . strictEqual ( ping [ "testResolutionFunction" ] , undefined ) ;
121+ assert . strictEqual ( ping [ "testValidator" ] , undefined ) ;
122+
123+ let validatorRun = false ;
124+ let p = ping . testBeforeNextSubmit ( async r => {
125+ assert . strictEqual ( r , "test" ) ;
126+ validatorRun = true ;
127+ } ) ;
128+
129+ // Internals should be defined after the API was called.
130+ assert . notStrictEqual ( ping [ "testResolutionFunction" ] , undefined ) ;
131+ assert . notStrictEqual ( ping [ "testValidator" ] , undefined ) ;
132+
133+ ping . submit ( "test" ) ;
134+ await p ;
135+
136+ assert . ok ( validatorRun ) ;
137+ } ) ;
138+
139+ it ( "runs a validator with metrics tests" , async function ( ) {
140+ const TEST_VALUE = 2908 ;
141+
142+ const ping = new PingType ( {
143+ name : "custom" ,
144+ includeClientId : true ,
145+ sendIfEmpty : false ,
146+ reasonCodes : [ "test" ]
147+ } ) ;
148+ const counter = new CounterMetricType ( {
149+ category : "aCategory" ,
150+ name : "aCounterMetric" ,
151+ sendInPings : [ "custom" ] ,
152+ lifetime : Lifetime . Ping ,
153+ disabled : false
154+ } ) ;
155+ counter . add ( TEST_VALUE ) ;
156+
157+ let validatorRun = false ;
158+ let p = ping . testBeforeNextSubmit ( async r => {
159+ assert . strictEqual ( r , "test" ) ;
160+ assert . strictEqual ( await counter . testGetValue ( ) , TEST_VALUE ) ;
161+ validatorRun = true ;
162+ } ) ;
163+
164+ ping . submit ( "test" ) ;
165+ await p ;
166+
167+ assert . ok ( validatorRun ) ;
168+ } ) ;
110169} ) ;
0 commit comments