-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from BranchMetrics/feat/added-unit-testing
[FEAT] Added unit-testing
- Loading branch information
Showing
5 changed files
with
234 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
#!/bin/bash | ||
cordova platform add ios android | ||
cordova plugin add ../ --link --variable BRANCH_LIVE_KEY=key_live_fnmRM1FXtu11t6e4LU8WsldpvDcA0bzv --variable BRANCH_TEST_KEY=key_test_oicIH5u2yxW9w3i6UZdfCiokyrixWpBJ --variable URI_SCHEME=testbed | ||
<<<<<<< HEAD | ||
|
||
cordova plugin add ../ --link --variable BRANCH_LIVE_KEY=key_live_fnmRM1FXtu11t6e4LU8WsldpvDcA0bzv --variable URI_SCHEME=testbed --variable ENCODED_ID=X9Ug | ||
cordova plugin add https://github.com/nordnet/cordova-universal-links-plugin.git | ||
|
||
# Include this plugin if you want to run a unit-test for the plugin | ||
cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git | ||
cordova plugin add ../ --link --variable BRANCH_LIVE_KEY=key_live_fnmRM1FXtu11t6e4LU8WsldpvDcA0bzv --variable BRANCH_TEST_KEY=key_test_oicIH5u2yxW9w3i6UZdfCiokyrixWpBJ --variable URI_SCHEME=testbed --variable ENCODED_ID=X9Ug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Running Plugin Tests | ||
|
||
1. Use your existing cordova app, or create a new one. | ||
2. Add these plugins: | ||
``` | ||
cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git | ||
cordova plugin add https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK.git#:/tests | ||
``` | ||
3. Change the start page in `config.xml` with `<content src="cdvtests/index.html" />` or navigate to `cdvtests/index.html` from within your app. | ||
4. That's it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License (MIT) | ||
Copyright (c) 2015 Branch Metrics, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
--> | ||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:rim="http://www.blackberry.com/ns/widgets" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
id="io.branch.sdk-tests" | ||
version="2.0.2"> | ||
|
||
<name>branch-cordova-sdk-tests</name> | ||
<license>Apache 2.0</license> | ||
|
||
<js-module src="tests.js" name="tests"></js-module> | ||
|
||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/** | ||
* Branch.IO Cordova Plugin Unit-Test | ||
* ---------------------------------- | ||
*/ | ||
/* jshint jasmine: true */ | ||
|
||
exports.defineAutoTests = function () { | ||
|
||
describe('Branch.IO SDK (Branch)', function () { | ||
it('should exist', function () { | ||
expect(window.Branch).toBeDefined(); | ||
}); | ||
it('should contain a method called getLatestReferringParams()', function () { | ||
expect(window.Branch.getLatestReferringParams).toBeDefined(); | ||
expect(typeof(window.Branch.getLatestReferringParams)).toBe('function'); | ||
}); | ||
it('should contain a method called getFirstReferringParams()', function () { | ||
expect(window.Branch.getFirstReferringParams).toBeDefined(); | ||
expect(typeof(window.Branch.getFirstReferringParams)).toBe('function'); | ||
}); | ||
it('should contain a method called setIdentity()', function () { | ||
expect(window.Branch.setIdentity).toBeDefined(); | ||
expect(typeof(window.Branch.setIdentity)).toBe('function'); | ||
}); | ||
it('should contain a method called logout()', function () { | ||
expect(window.Branch.logout).toBeDefined(); | ||
expect(typeof(window.Branch.logout)).toBe('function'); | ||
}); | ||
it('should contain a method called createBranchUniversalObject()', function () { | ||
expect(window.Branch.createBranchUniversalObject).toBeDefined(); | ||
expect(typeof(window.Branch.createBranchUniversalObject)).toBe('function'); | ||
}); | ||
it('should contain a method called userCompletedAction()', function () { | ||
expect(window.Branch.userCompletedAction).toBeDefined(); | ||
expect(typeof(window.Branch.userCompletedAction)).toBe('function'); | ||
}); | ||
it('should contain a method called loadRewards()', function () { | ||
expect(window.Branch.loadRewards).toBeDefined(); | ||
expect(typeof(window.Branch.loadRewards)).toBe('function'); | ||
}); | ||
it('should contain a method called redeemRewards()', function () { | ||
expect(window.Branch.redeemRewards).toBeDefined(); | ||
expect(typeof(window.Branch.redeemRewards)).toBe('function'); | ||
}); | ||
it('should contain a method called creditHistory()', function () { | ||
expect(window.Branch.creditHistory).toBeDefined(); | ||
expect(typeof(window.Branch.creditHistory)).toBe('function'); | ||
}); | ||
}); | ||
|
||
describe('Branch.getLatestReferringParams()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return an object response', function (done) { | ||
window.Branch.getLatestReferringParams().then(function (res) { | ||
expect(typeof(res)).toBe('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.getFirstReferringParams()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return an object response', function (done) { | ||
window.Branch.getFirstReferringParams().then(function (res) { | ||
expect(typeof(res)).toBe('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.setIdentity()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return "Success" response', function (done) { | ||
window.Branch.setIdentity('new_identity').then(function (res) { | ||
expect(res).toBe('Success'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.createBranchUniversalObject()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return an object instance', function (done) { | ||
var properties = { | ||
canonicalIdentifier: 'testbed', | ||
title: 'testbed', | ||
contentDescription: 'Testbed Application', | ||
contentImageUrl: 'https://imgflip.com/s/meme/Derp.jpg', | ||
contentIndexingMode: 'public', | ||
contentMetadata: {} | ||
}; | ||
window.Branch.createBranchUniversalObject(properties).then(function (res) { | ||
expect(typeof(res)).toBe('object'); | ||
expect(res.message).toBe('success'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.userCompletedAction()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should successfully execute the method', function (done) { | ||
window.Branch.userCompletedAction('login'); | ||
expect('Success').toBe('Success'); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('Branch.loadRewards()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return an object response', function (done) { | ||
window.Branch.loadRewards().then(function (res) { | ||
expect(typeof(res)).toBe('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.redeemRewards()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return an object/string error response', function (done) { | ||
window.Branch.redeemRewards(100).then(function (res) { | ||
expect(typeof(res)).toBe('object'); | ||
done(); | ||
}, function (err) { | ||
expect(typeof(err)).toBe('string'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Branch.creditHistory()', function () { | ||
beforeEach(function () { | ||
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; | ||
window.Branch.setDebug(true); | ||
window.Branch.initSession(); | ||
}); | ||
it('should return the credit balance', function (done) { | ||
window.Branch.creditHistory().then(function (res) { | ||
expect(typeof(res)).toBe('number'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
}; |