Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

added $window.analytics.setAllowIDFACollection #1362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mocks/googleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) {
'trackException',
'trackTiming',
'addTransaction',
'addTransactionItem'
'addTransactionItem',
'setAllowIDFACollection'
];

methodsName.forEach(function (funcName) {
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/googleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ angular.module('ngCordova.plugins.googleAnalytics', [])
d.reject(error);
});

return d.promise;
},

setAllowIDFACollection: function (allowIDFACollection) {
var d = $q.defer();

$window.analytics.setAllowIDFACollection(allowIDFACollection, function (response) {
d.resolve(response);
}, function (error) {
d.reject(error);
});

return d.promise;
}
};
Expand Down
7 changes: 6 additions & 1 deletion test/mocks/googleAnalytics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ describe('ngCordovaMocks', function() {
it('should add add a transaction item.', function() {
testPromises('addTransactionItem');
});

it('should add setAllowIDFACollection.', function() {
testPromises('setAllowIDFACollection');
});

});
})
})
42 changes: 42 additions & 0 deletions test/plugins/googleAnalytics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Service: $cordovaGoogleAnalytics', function() {
trackTiming: angular.noop,
addTransaction: angular.noop,
addTransactionItem: angular.noop,
setAllowIDFACollection: angular.noop
};
}));

Expand Down Expand Up @@ -446,4 +447,45 @@ describe('Service: $cordovaGoogleAnalytics', function() {
expect(result).toBe('Tracker not started');
});

it('should call $window\'s analytics.setAllowIDFACollection method', function() {

var result;

spyOn($window.analytics, 'setAllowIDFACollection')
.and.callFake(function (allowIDFACollection, successCb, errorCb) {
successCb('setAllowIDFACollection set');
});

$cordovaGoogleAnalytics
.setAllowIDFACollection(true)
.then(function (response) {
result = response;
});

$rootScope.$digest();

expect(result).toBe('setAllowIDFACollection set');
expect($window.analytics.setAllowIDFACollection.calls.argsFor(0)[0]).toBe(true);
});

it('should call errorCb when in $window\'s analytics.setAllowIDFACollection a error orccurs', function() {

var result;

spyOn($window.analytics, 'setAllowIDFACollection')
.and.callFake(function (allowIDFACollection, successCb, errorCb) {
errorCb('some error');
});

$cordovaGoogleAnalytics.setAllowIDFACollection()
.then(angular.noop, function (response) {
result = response;
});

$rootScope.$digest();

expect(result).toBe('some error');
});


});