Skip to content

Commit

Permalink
Merge pull request #128 from getbraincloud/reset
Browse files Browse the repository at this point in the history
resetComms in Init, and multi init tests
  • Loading branch information
davidstl authored Sep 9, 2020
2 parents 6af228a + a629d5e commit 2165b99
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/brainCloudBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ function BrainCloudManager ()
bcm._sendQueue = [];
bcm._inProgressQueue = [];
bcm._sessionId = "";
bcm.packetId = -1;
bcm._isAuthenticated = false;
bcm._requestInProgress = false;

Expand Down
2 changes: 2 additions & 0 deletions src/brainCloudClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function BrainCloudClient() {
* version - The app version (e.g. "1.0.0").
*/
bcc.initialize = function(appId, secret, appVersion) {
bcc.resetCommunication();
function isBlank(str) {
return (!str || /^\s*$/.test(str));
};
Expand All @@ -206,6 +207,7 @@ function BrainCloudClient() {
};

bcc.initializeWithApps = function(defaultAppId, secretMap, appVersion) {
bcc.resetCommunication();
function isBlank(str) {
return (!str || /^\s*$/.test(str));
};
Expand Down
40 changes: 40 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5104,6 +5104,46 @@ async function testWrapper()
});
});

await asyncTest("reInit()", 5, function() {
var secretMap = {};
secretMap[GAME_ID] = SECRET;
secretMap[CHILD_APP_ID] = CHILD_SECRET;

var initCounter = 1;
//case 1 multiple init
bc.brainCloudClient.initializeWithApps(GAME_ID, secretMap, GAME_VERSION);
equal(initCounter == 1, true, "inits passed 1");
initCounter++;
bc.brainCloudClient.initializeWithApps(GAME_ID, secretMap, GAME_VERSION);
equal(initCounter == 2, true, "inits passed 2");
initCounter++;
bc.brainCloudClient.initializeWithApps(GAME_ID, secretMap, GAME_VERSION);
equal(initCounter == 3, true, "inits passed 3");

//auth
bc.brainCloudClient.authentication.authenticateAnonymous(
true, function(result) {
equal(result.status, 200, JSON.stringify(result));
resolve_test();
});

//call
bc.time.readServerTime(function(result) {
ok(true, JSON.stringify(result));
equal(result.status, 200, "Expecting 200");
resolve_test();
});

//reinit
bc.brainCloudClient.initializeWithApps(GAME_ID, secretMap, GAME_VERSION);

//call - expect fail becasue of no session
bc.time.readServerTime(function(result) {
ok(true, JSON.stringify(result));
equal(result.status, 403, "No Session");
resolve_test();
});
});
}

async function testChat()
Expand Down

0 comments on commit 2165b99

Please sign in to comment.