Skip to content

Commit

Permalink
feat(core): remove v1/logout API calls (#917)
Browse files Browse the repository at this point in the history
- feat(core): remove v1/logout API calls
  • Loading branch information
JagadeeshKaricherla-branch authored Aug 15, 2023
1 parent 32886f5 commit e0cc60d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 161 deletions.
8 changes: 0 additions & 8 deletions src/2_resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 8 additions & 28 deletions src/6_branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
90 changes: 0 additions & 90 deletions test/3_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
35 changes: 0 additions & 35 deletions test/7_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e0cc60d

Please sign in to comment.