From e0cc60dd9504ef0570863ba63ce9ec9504206c40 Mon Sep 17 00:00:00 2001 From: Jagadeesh Branch <102190347+JagadeeshKaricherla-branch@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:25:54 -0700 Subject: [PATCH] feat(core): remove v1/logout API calls (#917) - feat(core): remove v1/logout API calls --- src/2_resources.js | 8 ---- src/6_branch.js | 36 ++++------------- test/3_api.js | 90 ------------------------------------------- test/7_integration.js | 35 ----------------- 4 files changed, 8 insertions(+), 161 deletions(-) diff --git a/src/2_resources.js b/src/2_resources.js index 94efb07e..ec1ed5b7 100644 --- a/src/2_resources.js +++ b/src/2_resources.js @@ -136,14 +136,6 @@ resources.linkClick = { } }; -resources.logout = { - destination: config.api_endpoint, - endpoint: "/v1/logout", - method: utils.httpMethod.POST, - params: defaults({ - "session_id": validator(true, validationTypes.STRING) - }) -}; resources.link = { destination: config.api_endpoint, diff --git a/src/6_branch.js b/src/6_branch.js index 35940eeb..4218ee2f 100644 --- a/src/6_branch.js +++ b/src/6_branch.js @@ -828,36 +828,16 @@ Branch.prototype['setIdentity'] = wrap(callback_params.CALLBACK_ERR_DATA, functi /*** +TOC_ITEM #logoutcallback &.logout()& ^ALL ***/ Branch.prototype['logout'] = wrap(callback_params.CALLBACK_ERR, function(done) { var self = this; - this._api(resources.logout, { }, function(err, data) { - if (err) { - done(err); - } - - data = data || { }; - data = { - "data_parsed": null, - "data": null, - "referring_link": null, - "click_id": null, - "link_click_id": null, - "identity": null, // data.identity is usually/always null anyway, but force it here - "session_id": data['session_id'], - "identity_id": data['identity_id'], - "link": data['link'], - "device_fingerprint_id": self.device_fingerprint_id || null - }; + var data = { + "identity": null + }; - // /v1/logout will return a new identity_id and a new session_id - self.sessionLink = data['link']; - self.session_id = data['session_id']; - self.identity_id = data['identity_id']; - self.identity = null; - // make sure to update both session and local. removeNull = true deletes, in particular, - // identity instead of inserting null in storage. - session.patch(self._storage, data, /* updateLocalStorage */ true, /* removeNull */ true); + self.identity = null; + // make sure to update both session and local. removeNull = true deletes, in particular, + // identity instead of inserting null in storage. + session.patch(self._storage, data, /* updateLocalStorage */ true, /* removeNull */ true); - done(null); - }); + done(null); }); Branch.prototype['getBrowserFingerprintId'] = wrap(callback_params.CALLBACK_ERR_DATA, function(done) { diff --git a/test/3_api.js b/test/3_api.js index 013c63f2..e7af1b31 100644 --- a/test/3_api.js +++ b/test/3_api.js @@ -411,96 +411,6 @@ describe('Server', function() { }); }); - describe('/v1/logout', function() { - beforeEach(function() { - requests = []; - storage.clear(); - }); - - it('should pass in branch_key and session_id', function(done) { - storage['set']('use_jsonp', false); - var assert = testUtils.plan(5, done); - server.request(resources.logout, testUtils.params({ }), storage, assert.done); - - assert.strictEqual(requests.length, 1, 'Request made'); - assert.strictEqual( - requests[0].url, - config.api_endpoint + '/v1/logout', 'Endpoint correct', - 'Expected url for the first request' - ); - assert.strictEqual(requests[0].method, 'POST', 'Method correct'); - assert.strictEqual( - requests[0].requestBody, - "session_id=" + session_id + - "&browser_fingerprint_id=" + browser_fingerprint_id + - "&identity_id=" + identity_id + - "&sdk=web" + config.version + - "&branch_key=" + branch_sample_key, - 'Expected request body for the first request' - ); - - requests[0].respond( - 200, - { "Content-Type": "application/json" }, - '{ "session_id": 123 }' - ); - }); - - it('should pass as a jsonp request', function(done) { - var assert = testUtils.plan(3, done); - storage['set']('use_jsonp', true); - - var completeParams = testUtils.params({ }); - server.request(resources.logout, completeParams, storage, assert.done); - assert.strictEqual(requests.length, 1, 'Request made'); - - var encodedData = encodeURIComponent( - utils.base64encode(goog.json.serialize(completeParams)) - ); - assert.strictEqual( - requests[0].src, - config.api_endpoint + '/v1/logout?&data=' + encodedData + - '&callback=branch_callback__' + (server._jsonp_callback_index - 1), - 'Endpoint correct' - ); - requests[0].callback(); - }); - - it('should fail without branch_key', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.logout, - testUtils.params({ }, [ 'branch_key' ]), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/logout missing parameter branch_key or app_id" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - - it('should fail without session_id', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.logout, - testUtils.params({ }, [ 'session_id' ]), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/logout missing parameter session_id" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - }); - describe('/_r', function() { beforeEach(function() { requests = []; diff --git a/test/7_integration.js b/test/7_integration.js index cdd633b1..150d3edf 100644 --- a/test/7_integration.js +++ b/test/7_integration.js @@ -290,41 +290,6 @@ describe('Integration tests', function() { }); }); - describe('logout', function() { - it('should make two requests and logout session', function(done) { - var assert = testUtils.plan(numberOfAsserts(5), done); - branchInit(assert); - branch.logout(function(err, data) { - assert.strictEqual(err, null, 'Expect no err'); - assert.strictEqual(branch.session_id, newSessionId, 'branch session was replaced'); - assert.strictEqual( - branch.identity_id, - newIdentityId, - 'branch identity was replaced' - ); - assert.strictEqual(branch.sessionLink, newLink, 'link was replaced'); - }); - var newSessionId = 'new_session'; - var newIdentityId = 'new_id'; - var newLink = 'new_link'; - - assert.strictEqual( - requests.length, - indexOfLastInitRequest(3), - 'Expect requests length' - ); - requests[indexOfLastInitRequest(2)].respond( - 200, - { "Content-Type": "application/json" }, - JSON.stringify({ - "session_id": newSessionId, - "identity_id": newIdentityId, - "link": newLink - }) - ); - }); - }); - describe('getBrowserFingerprintId', function() { it('it should return browser-fingerprint-id with value 79336952217731267', function(done) { var assert = testUtils.plan(numberOfAsserts(1), done);