@@ -187,6 +187,57 @@ describe('Amplitude', function() {
187187 } ) ;
188188 } ) ;
189189
190+ describe ( 'optOut' , function ( ) {
191+ beforeEach ( function ( ) {
192+ amplitude . init ( apiKey ) ;
193+ } ) ;
194+
195+ afterEach ( function ( ) {
196+ reset ( ) ;
197+ } ) ;
198+
199+ it ( 'should not send events while enabled' , function ( ) {
200+ amplitude . setOptOut ( true ) ;
201+ amplitude . logEvent ( 'Event Type 1' ) ;
202+ assert . lengthOf ( server . requests , 0 ) ;
203+ } ) ;
204+
205+ it ( 'should not send saved events while enabled' , function ( ) {
206+ amplitude . logEvent ( 'Event Type 1' ) ;
207+ assert . lengthOf ( server . requests , 1 ) ;
208+
209+ amplitude . _sending = false ;
210+ amplitude . setOptOut ( true ) ;
211+ amplitude . init ( apiKey ) ;
212+ assert . lengthOf ( server . requests , 1 ) ;
213+ } ) ;
214+
215+ it ( 'should start sending events again when disabled' , function ( ) {
216+ amplitude . setOptOut ( true ) ;
217+ amplitude . logEvent ( 'Event Type 1' ) ;
218+ assert . lengthOf ( server . requests , 0 ) ;
219+
220+ amplitude . setOptOut ( false ) ;
221+ amplitude . logEvent ( 'Event Type 1' ) ;
222+ assert . lengthOf ( server . requests , 1 ) ;
223+
224+ var events = JSON . parse ( querystring . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
225+ assert . lengthOf ( events , 1 ) ;
226+ } ) ;
227+
228+ it ( 'should have state be persisted in the cookie' , function ( ) {
229+ var amplitude = new Amplitude ( ) ;
230+ amplitude . init ( apiKey ) ;
231+ assert . strictEqual ( amplitude . options . optOut , false ) ;
232+
233+ amplitude . setOptOut ( true ) ;
234+
235+ var amplitude2 = new Amplitude ( ) ;
236+ amplitude2 . init ( apiKey ) ;
237+ assert . strictEqual ( amplitude2 . options . optOut , true ) ;
238+ } ) ;
239+ } ) ;
240+
190241 describe ( 'gatherUtm' , function ( ) {
191242 beforeEach ( function ( ) {
192243 amplitude . init ( apiKey ) ;
0 commit comments