Skip to content

Commit

Permalink
Test bumpStat URL via url.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Aug 4, 2017
1 parent ccf3906 commit 1c179a2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions utils/test/tracking.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable no-console */

/**
* External dependencies
*/
import url from 'url';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -68,16 +73,15 @@ describe( 'bumpStat', () => {

it( 'should bump valid stats', () => {
window.getUserSetting = () => 'on';
const url = bumpStat( 'valid_group', 'valid-name' );
// There are a couple of pieces of the URL where we don't care about
// testing the specific value. Replace them with placeholders.
const urlMatch = url
.replace( /^[a-z]+:/, 'PROTOCOL:' )
.replace( /t=[0-9.]+$/, 't=NUMBER' );
expect( urlMatch ).toBe(
'PROTOCOL://pixel.wp.com/g.gif?v=wpcom-no-pv'
+ '&x_gutenberg_valid_group=valid-name'
+ '&t=NUMBER'
// Testing the URL protocol and the randomized `?t=` cache-buster is
// difficult, so only test the pieces we're actually interested in.
const statUrlPieces = url.parse(
bumpStat( 'valid_group', 'valid-name' ),
true
);
expect( statUrlPieces.hostname ).toBe( 'pixel.wp.com' );
expect( statUrlPieces.pathname ).toBe( '/g.gif' );
expect( statUrlPieces.query.v ).toBe( 'wpcom-no-pv' );
expect( statUrlPieces.query.x_gutenberg_valid_group ).toBe( 'valid-name' );
} );
} );

0 comments on commit 1c179a2

Please sign in to comment.