Skip to content

Commit 881fc54

Browse files
committed
remove SDKState dependency on noFunctional flag
1 parent c7e0a7f commit 881fc54

File tree

3 files changed

+16
-182
lines changed

3 files changed

+16
-182
lines changed

src/persistence.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export default function _Persistence(mpInstance) {
3535
mpInstance._Store.isFirstRun = false;
3636
}
3737

38-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
39-
return;
40-
}
41-
4238
// https://go.mparticle.com/work/SQDSDKS-6045
4339
if (!mpInstance._Store.isLocalStorageAvailable) {
4440
mpInstance._Store.SDKConfig.useCookieStorage = true;
@@ -117,10 +113,7 @@ export default function _Persistence(mpInstance) {
117113
};
118114

119115
this.update = function() {
120-
if (
121-
!mpInstance._Store.webviewBridgeEnabled &&
122-
!mpInstance._Store.getPrivacyFlag('SDKState')
123-
) {
116+
if (!mpInstance._Store.webviewBridgeEnabled) {
124117
if (mpInstance._Store.SDKConfig.useCookieStorage) {
125118
self.setCookie();
126119
}
@@ -810,9 +803,6 @@ export default function _Persistence(mpInstance) {
810803

811804
// https://go.mparticle.com/work/SQDSDKS-6021
812805
this.savePersistence = function(persistence) {
813-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
814-
return;
815-
}
816806
var encodedPersistence = self.encodePersistence(
817807
JSON.stringify(persistence)
818808
),
@@ -857,9 +847,6 @@ export default function _Persistence(mpInstance) {
857847
};
858848

859849
this.getPersistence = function() {
860-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
861-
return null;
862-
}
863850
var persistence = this.useLocalStorage()
864851
? this.getLocalStorage()
865852
: this.getCookie();

test/jest/persistence.spec.ts

Lines changed: 15 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -39,101 +39,30 @@ describe('Persistence', () => {
3939
});
4040

4141
describe('#update', () => {
42-
describe('noFunctional privacy flag set to true', () => {
43-
beforeEach(() => {
44-
store.setNoFunctional(true);
45-
store.webviewBridgeEnabled = false;
46-
});
47-
48-
it('should NOT write to cookie and localStorage when useCookieStorage is true', () => {
49-
store.SDKConfig.useCookieStorage = true;
50-
51-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
52-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
53-
54-
persistence.update();
55-
56-
expect(setCookieSpy).not.toHaveBeenCalled();
57-
expect(setLocalStorageSpy).not.toHaveBeenCalled();
58-
});
59-
60-
it('should NOT write to localStorage when useCookieStorage is false', () => {
61-
store.SDKConfig.useCookieStorage = false;
62-
63-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
64-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
65-
66-
persistence.update();
67-
68-
expect(setCookieSpy).not.toHaveBeenCalled();
69-
expect(setLocalStorageSpy).not.toHaveBeenCalled();
70-
});
71-
});
72-
73-
describe('noFunctional privacy flag set to false', () => {
74-
beforeEach(() => {
75-
store.setNoFunctional(false);
76-
store.webviewBridgeEnabled = false;
77-
});
78-
79-
it('should write to cookie and localStorage when useCookieStorage is true', () => {
80-
store.SDKConfig.useCookieStorage = true;
81-
82-
jest.spyOn(persistence, 'getCookie').mockReturnValue(null);
83-
84-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
85-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
86-
87-
persistence.update();
88-
89-
expect(setCookieSpy).toHaveBeenCalled();
90-
expect(setLocalStorageSpy).toHaveBeenCalled();
91-
});
42+
it('should write to cookie and localStorage by default when useCookieStorage is true', () => {
43+
store.SDKConfig.useCookieStorage = true;
9244

93-
it('should write to localStorage when useCookieStorage is false', () => {
94-
store.SDKConfig.useCookieStorage = false;
45+
jest.spyOn(persistence, 'getCookie').mockReturnValue(null);
9546

96-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
97-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
47+
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
48+
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
9849

99-
persistence.update();
50+
persistence.update();
10051

101-
expect(setCookieSpy).not.toHaveBeenCalled();
102-
expect(setLocalStorageSpy).toHaveBeenCalled();
103-
});
52+
expect(setCookieSpy).toHaveBeenCalled();
53+
expect(setLocalStorageSpy).toHaveBeenCalled();
10454
});
10555

106-
describe('noFunctional privacy flag set to false by default', () => {
107-
beforeEach(() => {
108-
// default is false
109-
store.webviewBridgeEnabled = false;
110-
});
111-
112-
it('should write to cookie and localStorage by default when useCookieStorage is true', () => {
113-
store.SDKConfig.useCookieStorage = true;
114-
115-
jest.spyOn(persistence, 'getCookie').mockReturnValue(null);
116-
117-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
118-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
56+
it('should write to localStorage by default when useCookieStorage is false', () => {
57+
store.SDKConfig.useCookieStorage = false;
11958

120-
persistence.update();
121-
122-
expect(setCookieSpy).toHaveBeenCalled();
123-
expect(setLocalStorageSpy).toHaveBeenCalled();
124-
});
125-
126-
it('should write to localStorage by default when useCookieStorage is false', () => {
127-
store.SDKConfig.useCookieStorage = false;
128-
129-
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
130-
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
59+
const setCookieSpy = jest.spyOn(persistence, 'setCookie');
60+
const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage');
13161

132-
persistence.update();
62+
persistence.update();
13363

134-
expect(setCookieSpy).not.toHaveBeenCalled();
135-
expect(setLocalStorageSpy).toHaveBeenCalled();
136-
});
64+
expect(setCookieSpy).not.toHaveBeenCalled();
65+
expect(setLocalStorageSpy).toHaveBeenCalled();
13766
});
13867

13968
it('should NOT write to storage when webviewBridgeEnabled is true', () => {

test/src/tests-persistence.ts

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,86 +1876,4 @@ describe('persistence', () => {
18761876
user2.getAllUserAttributes()['ua-list'][1].should.equal('<b>');
18771877
user2.getAllUserAttributes()['ua-1'].should.equal('a');
18781878
});
1879-
1880-
describe('noFunctional privacy flag', () => {
1881-
describe('set to true', () => {
1882-
beforeEach(() => {
1883-
mParticle.config.launcherOptions = { noFunctional: true };
1884-
});
1885-
1886-
it('should NOT store cookie when useCookieStorage = true', async () => {
1887-
mParticle.config.useCookieStorage = true;
1888-
1889-
mParticle.init(apiKey, mParticle.config);
1890-
await waitForCondition(hasIdentifyReturned);
1891-
1892-
mParticle.getInstance()._Persistence.update();
1893-
1894-
expect(findCookie()).to.not.be.ok;
1895-
});
1896-
1897-
it('should NOT write localStorage when useCookieStorage = false', async () => {
1898-
mParticle.config.useCookieStorage = false;
1899-
1900-
mParticle.init(apiKey, mParticle.config);
1901-
await waitForCondition(hasIdentifyReturned);
1902-
1903-
mParticle.getInstance()._Persistence.update();
1904-
1905-
expect(getLocalStorage()).to.not.be.ok;
1906-
});
1907-
});
1908-
1909-
describe('set to false', () => {
1910-
beforeEach(() => {
1911-
mParticle.config.launcherOptions = { noFunctional: false };
1912-
});
1913-
1914-
it('should store cookie when useCookieStorage = true', async () => {
1915-
mParticle.config.useCookieStorage = true;
1916-
1917-
mParticle.init(apiKey, mParticle.config);
1918-
await waitForCondition(hasIdentifyReturned);
1919-
1920-
mParticle.getInstance()._Persistence.update();
1921-
1922-
expect(findCookie()).to.be.ok;
1923-
});
1924-
1925-
it('should store localStorage when useCookieStorage = false', async () => {
1926-
mParticle.config.useCookieStorage = false;
1927-
1928-
mParticle.init(apiKey, mParticle.config);
1929-
await waitForCondition(hasIdentifyReturned);
1930-
1931-
mParticle.getInstance()._Persistence.update();
1932-
1933-
expect(getLocalStorage()).to.be.ok;
1934-
});
1935-
});
1936-
1937-
describe('is false by default', () => {
1938-
it('should store cookie when useCookieStorage = true', async () => {
1939-
mParticle.config.useCookieStorage = true;
1940-
1941-
mParticle.init(apiKey, mParticle.config);
1942-
await waitForCondition(hasIdentifyReturned);
1943-
1944-
mParticle.getInstance()._Persistence.update();
1945-
1946-
expect(findCookie()).to.be.ok;
1947-
});
1948-
1949-
it('should store localStorage when useCookieStorage = false', async () => {
1950-
mParticle.config.useCookieStorage = false;
1951-
1952-
mParticle.init(apiKey, mParticle.config);
1953-
await waitForCondition(hasIdentifyReturned);
1954-
1955-
mParticle.getInstance()._Persistence.update();
1956-
1957-
expect(getLocalStorage()).to.be.ok;
1958-
});
1959-
});
1960-
});
19611879
});

0 commit comments

Comments
 (0)