Skip to content

Commit

Permalink
Merge pull request #191 from renesansz/chore/update-unit-test
Browse files Browse the repository at this point in the history
[CHORE] Updated unit test
  • Loading branch information
aaustin authored Aug 10, 2016
2 parents 76523bb + 37a6e75 commit aab303f
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 64 deletions.
1 change: 0 additions & 1 deletion tests-harness/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<plugin name="cordova-plugin-test-framework" spec="http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git" />
<engine name="android" spec="~5.2.1" />
<engine name="ios" spec="~4.2.0" />
</widget>
8 changes: 8 additions & 0 deletions tests-harness/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
rm -rf plugins platforms android ios

cordova platform add ios android

cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git
cordova plugin add ../ --variable BRANCH_KEY=key_live_fnmRM1FXtu11t6e4LU8WsldpvDcA0bzv --variable URI_SCHEME=testbed
cordova plugin add ../tests
158 changes: 95 additions & 63 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,103 +49,135 @@ exports.defineAutoTests = function () {
});

describe('Branch.getLatestReferringParams()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return an object response', function (done) {
window.Branch.getLatestReferringParams().then(function (res) {
expect(typeof(res)).toBe('object');
done();
});
});
}, 10000);
});

describe('Branch.getFirstReferringParams()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return an object response', function (done) {
window.Branch.getFirstReferringParams().then(function (res) {
expect(typeof(res)).toBe('object');
// We expect false since we won't open this from a branch link
expect(res).toBe(false);
done();
});
});
}, 10000);
});


describe('Branch.setIdentity()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return "Success" response', function (done) {
window.Branch.setIdentity('new_identity').then(function (res) {
expect(res).toBe('Success');
expect(typeof(res)).toBe('object');
done();
});
});
}, 10000);
});

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) {
var branchUniversalObj;

beforeEach(function (done) {
window.Branch.initSession().then(function () {
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) {
branchUniversalObj = res;
done();
});
});
}, 3000);
it('should execute register view', function (done) {
branchUniversalObj.registerView().then(function (res) {
expect(typeof(res)).toBe('object');
expect(res.message).toBe('success');
done();
});
});
}, 5000);
it('should execute generate short url', function (done) {
var properties = {
feature: 'test',
alias: 'testbed',
channel: 'test',
stage: 'test',
duration: 10000
};
var controlParams = {
$fallback_url: 'www.another.com',
$desktop_url: 'www.desktop.com',
$android_url: 'test',
$ios_url: 'ios',
$ipad_url: 'ipad',
$fire_url: 'fire',
$blackberry_url: 'blackberry',
$windows_phone_url: 'win-phone'
};
branchUniversalObj.generateShortUrl(properties, controlParams).then(function (res) {
expect(typeof(res)).toBe('object');
done();
});
}, 5000);
});

describe('Branch.userCompletedAction()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should successfully execute the method', function (done) {
window.Branch.userCompletedAction('login');
expect('Success').toBe('Success');
done();
});
}, 10000);
});

describe('Branch.loadRewards()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return an object response', function (done) {
window.Branch.loadRewards().then(function (res) {
expect(typeof(res)).toBe('object');
expect(typeof(res)).toBe('number');
done();
}, function (err) {
expect(typeof(err)).toBe('string');
done();
});
});
}, 10000);
});

describe('Branch.redeemRewards()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return an object/string error response', function (done) {
window.Branch.redeemRewards(100).then(function (res) {
expect(typeof(res)).toBe('object');
Expand All @@ -154,21 +186,21 @@ exports.defineAutoTests = function () {
expect(typeof(err)).toBe('string');
done();
});
});
}, 10000);
});

describe('Branch.creditHistory()', function () {
beforeEach(function () {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
window.Branch.setDebug(true);
window.Branch.initSession();
});
beforeEach(function (done) {
window.Branch.initSession().then(function () {
done();
});
}, 3000);
it('should return the credit balance', function (done) {
window.Branch.creditHistory().then(function (res) {
expect(typeof(res)).toBe('number');
expect(typeof(res)).toBe('object');
done();
});
});
}, 10000);
});

};

0 comments on commit aab303f

Please sign in to comment.