Skip to content

Commit

Permalink
[FEAT] Added unit-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Renemari Padillo committed Mar 9, 2016
1 parent a30665d commit 9d0a17b
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 2 deletions.
9 changes: 7 additions & 2 deletions testbed/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
<description>
Testbed application for Branch.IO Cordova.
</description>

<content src="index.html" />

<!-- Replace <content> with this, if you want to run the unit-test -->
<!-- <content src="cdvtests/index.html" /> -->

<plugin name="cordova-plugin-whitelist" spec="1" />
<preference name="AndroidLaunchMode" value="singleTask" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
Expand All @@ -26,7 +32,6 @@
</platform>
<universal-links>
<ios-team-id value="4XE8MVRXHY" />
<host name="bnc.lt">
</host>
<host name="bnc.lt"></host>
</universal-links>
</widget>
5 changes: 5 additions & 0 deletions testbed/init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
cordova platform add ios android

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 ../tests --link --variable BRANCH_LIVE_KEY=key_live_fnmRM1FXtu11t6e4LU8WsldpvDcA0bzv --variable URI_SCHEME=testbed --variable ENCODED_ID=X9Ug
10 changes: 10 additions & 0 deletions tests/README.md
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 this 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.
36 changes: 36 additions & 0 deletions tests/plugin.xml
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>
174 changes: 174 additions & 0 deletions tests/tests.js
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();
});
});
});

};

0 comments on commit 9d0a17b

Please sign in to comment.