<commit_before>/*
 * This file defines the unit tests for the main function
 */

/**
 * Defines global test variables
 */
var maxWaitTime;
var asyncPollingInterval;
var params;
var branch;
var stubs;
var asyncTestCase = new goog.testing.ContinuationTestCase("Branch test case");
var reachedSMSMissingPhoneFinal;

/**
 * Setup the Branch Function
 */
var setUpPage = function() {

	asyncTestCase.autoDiscoverTests();
	G_testRunner.initialize(asyncTestCase);
	stubs = new goog.testing.PropertyReplacer();

	// Main Branch object
	branch = new Branch();
	branch.init('5680621892404085', function(err, data) {
	  //document.getElementsByClassName('info')[0].innerHTML = JSON.stringify(data);
	});

	// Test for callbacks
	reachedSMSMissingPhoneFinal = false;

	// Maximum wait time for async tests (ms)
	maxWaitTime = 10000;

	// How often we should check for the finished state of an async test
	asyncPollingInterval = 500;

	//Standard set of dummy params
	params = {
		phone: "5177401526",
		tags: ['tag1', 'tag2'],
		channel: 'sample app',
		feature: 'create link',
		stage: 'created link',
		type: 1,
		data: {  
			mydata: {
				foo: 'bar'
			},
			'$desktop_url': 'http://s3-us-west-1.amazonaws.com/branch-sdk/example.html',
			'$og_title': 'Branch Metrics',
			'$og_description': 'Branch Metrics',
			'$og_image_url': 'http://branch.io/img/logo_icon_white.png'
		}
	};
}

// ===========================================================================================
/**
 * SMS Tests
 */

 // SMS sens with phone param
var testSMSLink = function() {

	var recievedData = {};
	var expectedData = {};
	var recievedFired;
	
	waitForCondition(
		function() {
			return recievedFired;
			 },
		function() {
			assertObjectEquals("should send SMS with phone number", recievedData, expectedData);
			reachedSMSMissingPhoneFinal = true;
		},
		asyncPollingInterval,
		maxWaitTime
	);
	
	branch.SMSLink(params, function(data) {
		recievedFired = true;
		recievedData = data;
	});
};

// Fails on missing phone number
var testMissingPhoneSMSLink = function() {

	var recievedData = {};
	var expectedData = new Error(utils.message(utils.messages.missingParam, 'phone'));
	var recievedFired;

	stubs.replace(params, 'phone', '');
	
	waitForCondition(
		function() {
			return recievedFired;
			 },
		function() {
			assertObjectEquals("should require a phone number", recievedData, expectedData);
			reachedSMSMissingPhoneFinal = true;
		},
		asyncPollingInterval,
		maxWaitTime
	);
	
	branch.SMSLink(params, function(data) {
		recievedFired = true;
		recievedData = data;
	});
};

// ===========================================================================================

/**
 * Clean up post tests
 */
var tearDown = function() {
  stubs.reset();
};<commit_msg>Tests for create link<commit_after>/*
 * This file defines the unit tests for the main function
 */

/**
 * Defines global test variables
 */
var maxWaitTime;
var asyncPollingInterval;
var params;
var branch;
var stubs;
var asyncTestCase = new goog.testing.ContinuationTestCase("Branch test case");
var asyncReachedFinal;

/**
 * Setup the Branch Function
 */
var setUpPage = function() {

	asyncTestCase.autoDiscoverTests();
	G_testRunner.initialize(asyncTestCase);
	stubs = new goog.testing.PropertyReplacer();

	// Main Branch object
	branch = new Branch();
	branch.init('5680621892404085', function(err, data) {
	  //document.getElementsByClassName('info')[0].innerHTML = JSON.stringify(data);
	});

	// Test for callbacks
	asyncReachedFinal = false;

	// Maximum wait time for async tests (ms)
	maxWaitTime = 10000;

	// How often we should check for the finished state of an async test
	asyncPollingInterval = 500;

	//Standard set of dummy params
	params = {
		phone: "5177401526",
		tags: ['tag1', 'tag2'],
		channel: 'sample app',
		feature: 'create link',
		stage: 'created link',
		type: 1,
		data: {  
			mydata: {
				foo: 'bar'
			},
			'$desktop_url': 'http://s3-us-west-1.amazonaws.com/branch-sdk/example.html',
			'$og_title': 'Branch Metrics',
			'$og_description': 'Branch Metrics',
			'$og_image_url': 'http://branch.io/img/logo_icon_white.png'
		}
	};
}

// ===========================================================================================
/**
 * SMS Tests
 */

 // SMS sends with phone param
var testSMSLink = function() {

	var recievedData = {};
	var expectedData = {};
	var recievedFired;
	
	waitForCondition(
		function() {
			return recievedFired;
			 },
		function() {
			assertObjectEquals("should send SMS with phone number", recievedData, expectedData);
			asyncReachedFinal = true;
		},
		asyncPollingInterval,
		maxWaitTime
	);
	
	branch.SMSLink(params, function(data) {
		recievedFired = true;
		recievedData = data;
	});
};

// Fails on missing phone number
var testMissingPhoneSMSLink = function() {

	var recievedData = {};
	var expectedData = new Error(utils.message(utils.messages.missingParam, 'phone'));
	var recievedFired;

	stubs.replace(params, 'phone', '');
	
	waitForCondition(
		function() {
			return recievedFired;
			 },
		function() {
			assertObjectEquals("should require a phone number", recievedData, expectedData);
			asyncReachedFinal = true;
		},
		asyncPollingInterval,
		maxWaitTime
	);
	
	branch.SMSLink(params, function(data) {
		recievedFired = true;
		recievedData = data;
	});
};

// ===========================================================================================
/**
 * Create link tests
 */

// Returns link with required params
var testCreateLink = function() {

	var recievedData = {};
	var expectedData = {};
	var recievedFired;

	waitForCondition(
		function() {
			return recievedFired;
			 },
		function() {
			assertNonEmptyString("should create link with required params", recievedData);
			var branchURL = "https://bnc.lt/l/";
			var recievedURLRoot = recievedData.substring(0, 17);
			assertEquals("should return branch URL", branchURL, recievedURLRoot);
			asyncReachedFinal = true;
		},
		asyncPollingInterval,
		maxWaitTime
	);

	branch.createLink(params, function(err, data) {
		recievedFired = true;
		recievedData = data;
	});
};

 // ===========================================================================================
/**
 * Clean up post tests
 */
var tearDown = function() {
  stubs.reset();
};
{'fraction_non_alphanumeric': 0.1949274206412506, 'fraction_numerical': 0.013239751156484288, 'mean_word_length': 4.318066157760814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1963464', 'n_tokens_mistral': 2172, 'n_tokens_neox': 1908, 'n_words': 474}