Skip to content

Commit c129917

Browse files
author
pgilmorepf
committed
Merge branch 'master' into versioned
https://api.playfab.com/releaseNotes#160606
2 parents 33ab71a + ae09060 commit c129917

File tree

5 files changed

+119
-104
lines changed

5 files changed

+119
-104
lines changed

PlayFabApiTest.js

Lines changed: 103 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ var PlayFabApiTests = {
2929
},
3030
testConstants: {
3131
TEST_KEY: "testCounter",
32-
TEST_STAT_NAME: "str"
32+
TEST_STAT_NAME: "str",
33+
CHAR_TEST_TYPE: "Fighter"
3334
},
3435

3536
ManualExecution: function () {
@@ -60,7 +61,7 @@ var PlayFabApiTests = {
6061
if (count > 5)
6162
return;
6263

63-
if (PlayFab._internalSettings.sessionTicket == null) {
64+
if (!PlayFabClientSDK.IsClientLoggedIn()) {
6465
// Wait for login
6566
setTimeout(function () { PlayFabApiTests.PostLoginTests(count + 1); }, 200);
6667
} else {
@@ -200,55 +201,22 @@ var PlayFabApiTests = {
200201
LoginOrRegister: function (assert) {
201202
var loginRequest = {
202203
// Currently, you need to look up the correct format for this object in the API-docs:
203-
// https://api.playfab.com/Documentation/Client/method/LoginWithEmailAddress
204+
// https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
204205
TitleId: PlayFab.settings.titleId,
205-
Email: PlayFabApiTests.titleData.userEmail,
206-
Password: PlayFabApiTests.titleData.userPassword
207-
};
208-
var registerRequest = {
209-
// Currently, you need to look up the correct format for this object in the API-docs:
210-
// https://api.playfab.com/Documentation/Client/method/RegisterPlayFabUser
211-
TitleId: PlayFab.settings.titleId,
212-
Username: PlayFabApiTests.titleData.userName,
213-
Email: PlayFabApiTests.titleData.userEmail,
214-
Password: PlayFabApiTests.titleData.userPassword
206+
CustomId: PlayFab._internalSettings.buildIdentifier,
207+
CreateAccount: true
215208
};
216209

217-
// We don't know at this point how many async calls we'll make
218-
var loginDone = null;
219-
var registerDone = null;
220-
221-
var mandatoryLoginCallback = function (result, error) {
222-
// Login MUST succeed at some point during this test
210+
var loginDone = assert.async();
211+
var loginCallback = function (result, error) {
223212
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Valid login result");
224-
assert.ok(PlayFab._internalSettings.sessionTicket != null, "Testing Login credentials cache");
225-
PlayFabApiTests.testData.playFabId = result.data.PlayFabId; // Save the PlayFabId, it will be used in other tests
213+
assert.ok(PlayFabClientSDK.IsClientLoggedIn(), "Testing Login credentials cache");
214+
if (result != null)
215+
PlayFabApiTests.testData.playFabId = result.data.PlayFabId; // Save the PlayFabId, it will be used in other tests
226216
loginDone();
227217
};
228-
var registerCallback = function (result, error) {
229-
// Second login MUST succeed
230-
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Registration result");
231-
232-
// Log in again, this time with the newly registered account
233-
loginDone = assert.async();
234-
PlayFabClientSDK.LoginWithEmailAddress(loginRequest, PlayFabApiTests.CallbackWrapper("mandatoryLoginCallback", mandatoryLoginCallback, assert));
235-
registerDone();
236-
};
237-
var optionalLoginCallback = function (result, error) {
238-
// First login falls back upon registration if login failed
239-
if (result == null) {
240-
// Register the character and try again
241-
registerDone = assert.async();
242-
PlayFabClientSDK.RegisterPlayFabUser(registerRequest, PlayFabApiTests.CallbackWrapper("registerCallback", registerCallback, assert));
243-
loginDone();
244-
}
245-
else {
246-
// Confirm the successful login
247-
mandatoryLoginCallback(result, error);
248-
}
249-
};
250-
loginDone = assert.async();
251-
PlayFabClientSDK.LoginWithEmailAddress(loginRequest, PlayFabApiTests.CallbackWrapper("optionalLoginCallback", optionalLoginCallback, assert));
218+
219+
PlayFabClientSDK.LoginWithCustomID(loginRequest, PlayFabApiTests.CallbackWrapper("loginCallback", loginCallback, assert));
252220
},
253221

254222
/// <summary>
@@ -263,25 +231,25 @@ var PlayFabApiTests = {
263231
var count = -1;
264232
var finishAdvertId = function () {
265233
count += 1;
266-
if (count > 10)
267-
assert.ok(false, "The advertisingId was not submitted properly");
268-
else if (PlayFab.settings.advertisingIdType === PlayFab.settings.AD_TYPE_ANDROID_ID + "_Successful")
269-
loginDone();
270-
else
234+
if (count <= 10 && PlayFab.settings.advertisingIdType !== PlayFab.settings.AD_TYPE_ANDROID_ID + "_Successful") {
271235
setTimeout(PlayFabApiTests.SimpleCallbackWrapper("finishAdvertId", finishAdvertId, assert), 200);
236+
} else {
237+
assert.ok(PlayFab.settings.advertisingIdType === PlayFab.settings.AD_TYPE_ANDROID_ID + "_Successful", "Testing whether advertisingId submitted properly");
238+
loginDone();
239+
}
272240
};
273241
var advertLoginCallback = function (result, error) {
274242
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Advert-Login result");
275243
setTimeout(PlayFabApiTests.SimpleCallbackWrapper("finishAdvertId", finishAdvertId, assert), 200);
276244
};
277245
var loginRequest = {
278246
// Currently, you need to look up the correct format for this object in the API-docs:
279-
// https://api.playfab.com/Documentation/Client/method/LoginWithEmailAddress
247+
// https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
280248
TitleId: PlayFab.settings.titleId,
281-
Email: PlayFabApiTests.titleData.userEmail,
282-
Password: PlayFabApiTests.titleData.userPassword
249+
CustomId: PlayFab._internalSettings.buildIdentifier,
250+
CreateAccount: true
283251
};
284-
PlayFabClientSDK.LoginWithEmailAddress(loginRequest, PlayFabApiTests.CallbackWrapper("advertLoginCallback", advertLoginCallback, assert));
252+
PlayFabClientSDK.LoginWithCustomID(loginRequest, PlayFabApiTests.CallbackWrapper("advertLoginCallback", advertLoginCallback, assert));
285253
},
286254

287255
/// <summary>
@@ -323,9 +291,9 @@ var PlayFabApiTests = {
323291
var getDataCallback1 = function (result, error) {
324292
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetUserData result");
325293
assert.ok(result.data.Data != null, "Testing GetUserData Data");
326-
assert.ok(result.data.Data.hasOwnProperty(PlayFabApiTests.testConstants.TEST_KEY), "Testing GetUserData DataKey");
327294

328-
PlayFabApiTests.testData.testNumber = parseInt(result.data.Data[PlayFabApiTests.testConstants.TEST_KEY].Value, 10);
295+
var hasData = result.data.Data.hasOwnProperty(PlayFabApiTests.testConstants.TEST_KEY);
296+
PlayFabApiTests.testData.testNumber = !hasData ? 1 : parseInt(result.data.Data[PlayFabApiTests.testConstants.TEST_KEY].Value, 10);
329297
PlayFabApiTests.testData.testNumber = (PlayFabApiTests.testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds
330298

331299
var updateDataRequest = {
@@ -375,9 +343,9 @@ var PlayFabApiTests = {
375343
var getStatsCallback1 = function (result, error) {
376344
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetUserStats result");
377345
assert.ok(result.data.UserStatistics != null, "Testing GetUserData Stats");
378-
assert.ok(result.data.UserStatistics.hasOwnProperty(PlayFabApiTests.testConstants.TEST_STAT_NAME), "Testing GetUserData Stat-value");
379346

380-
PlayFabApiTests.testData.testNumber = result.data.UserStatistics[PlayFabApiTests.testConstants.TEST_STAT_NAME];
347+
var hasData = result.data.UserStatistics.hasOwnProperty(PlayFabApiTests.testConstants.TEST_STAT_NAME);
348+
PlayFabApiTests.testData.testNumber = !hasData ? 1 : result.data.UserStatistics[PlayFabApiTests.testConstants.TEST_STAT_NAME];
381349
PlayFabApiTests.testData.testNumber = (PlayFabApiTests.testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds
382350

383351
var updateStatsRequest = {
@@ -406,8 +374,8 @@ var PlayFabApiTests = {
406374
// https://api.playfab.com/Documentation/Server/method/GrantCharacterToUser
407375
TitleId: PlayFabApiTests.titleData.titleId,
408376
PlayFabId: PlayFabApiTests.testData.playFabId,
409-
CharacterName: PlayFabApiTests.titleData.CHAR_NAME,
410-
CharacterType: PlayFabApiTests.titleData.CHAR_TEST_TYPE
377+
CharacterName: PlayFabApiTests.titleData.characterName,
378+
CharacterType: PlayFabApiTests.testConstants.CHAR_TEST_TYPE
411379
};
412380

413381
// We don't know at this point how many async calls we'll make
@@ -431,12 +399,12 @@ var PlayFabApiTests = {
431399

432400
// Get chars again, this time with the newly granted character
433401
getDone = assert.async();
434-
PlayFabClientSDK.GetAllUsersCharacters(getCharsRequest, PlayFabApiTests.CallbackWrapper("mandatoryGetCharsCallback", mandatoryGetCharsCallback, assert));
402+
PlayFabClientSDK.GetAllUsersCharacters(grantCharRequest, PlayFabApiTests.CallbackWrapper("mandatoryGetCharsCallback", mandatoryGetCharsCallback, assert));
435403
grantDone();
436404
};
437405
var optionalGetCharsCallback = function (result, error) {
438406
// First get chars falls back upon grant-char if target character not present
439-
if (result == null) {
407+
if (result.data.Characters.length === 0) {
440408
// Register the character and try again
441409
grantDone = assert.async();
442410
PlayFabServerSDK.GrantCharacterToUser(grantCharRequest, PlayFabApiTests.CallbackWrapper("grantCharCallback", grantCharCallback, assert));
@@ -520,45 +488,25 @@ var PlayFabApiTests = {
520488
/// Test that CloudScript can be properly set up and invoked
521489
/// </summary>
522490
CloudScript: function (assert) {
523-
var urlDone = null;
524-
var hwDone = null;
491+
var hwDone = assert.async();
525492

526-
if (PlayFab._internalSettings.logicServerUrl == null) {
527-
var getCloudUrlRequest = {};
528-
529-
var getCloudScriptUrlCallback = function (result, error) {
530-
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetCloudUrl result");
531-
532-
if (PlayFab._internalSettings.logicServerUrl != null)
533-
PlayFabApiTests.CloudScript(assert); // Recursively call this test to get the case below
534-
else
535-
assert.ok(false, "GetCloudScriptUrl did not retrieve the logicServerUrl");
536-
537-
urlDone();
538-
};
539-
540-
urlDone = assert.async();
541-
PlayFabClientSDK.GetCloudScriptUrl(getCloudUrlRequest, PlayFabApiTests.CallbackWrapper("getCloudScriptUrlCallback", getCloudScriptUrlCallback, assert));
542-
} else {
543-
var helloWorldRequest = {
544-
// Currently, you need to look up the correct format for this object in the API-docs:
545-
// https://api.playfab.com/Documentation/Client/method/RunCloudScript
546-
ActionId: "helloWorld"
547-
};
548-
549-
var helloWorldCallback = function (result, error) {
550-
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing HelloWorld result");
551-
if (result != null) {
552-
assert.ok(result.data.Results != null, "Testing HelloWorld result");
553-
assert.ok(result.data.Results.messageValue != null, "Testing HelloWorld result message");
554-
assert.equal(result.data.Results.messageValue, "Hello " + PlayFabApiTests.testData.playFabId + "!", "HelloWorld cloudscript result: " + result.data.Results.messageValue);
555-
}
556-
hwDone();
557-
};
558-
559-
hwDone = assert.async();
560-
PlayFabClientSDK.RunCloudScript(helloWorldRequest, PlayFabApiTests.CallbackWrapper("helloWorldCallback", helloWorldCallback, assert));
561-
}
493+
var helloWorldRequest = {
494+
// Currently, you need to look up the correct format for this object in the API-docs:
495+
// https://api.playfab.com/Documentation/Client/method/ExecuteCloudScript
496+
FunctionName: "helloWorld"
497+
};
498+
499+
var helloWorldCallback = function (result, error) {
500+
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing HelloWorld result");
501+
if (result != null) {
502+
assert.ok(result.data.FunctionResult != null, "Testing HelloWorld result");
503+
assert.ok(result.data.FunctionResult.messageValue != null, "Testing HelloWorld result message");
504+
assert.equal(result.data.FunctionResult.messageValue, "Hello " + PlayFabApiTests.testData.playFabId + "!", "HelloWorld cloudscript result: " + result.data.FunctionResult.messageValue);
505+
}
506+
hwDone();
507+
};
508+
509+
PlayFabClientSDK.ExecuteCloudScript(helloWorldRequest, PlayFabApiTests.CallbackWrapper("helloWorldCallback", helloWorldCallback, assert));
562510
},
563511

564512
/// <summary>
@@ -587,4 +535,59 @@ var PlayFabApiTests = {
587535
},
588536
};
589537

538+
// The test report that will ultimately be relayed back to Cloud Script when the suite finishes
539+
var PfTestReport = [{
540+
name: PlayFab._internalSettings.buildIdentifier,
541+
tests: 0,
542+
failures: 0,
543+
errors: 0,
544+
skipped: 0,
545+
time: 0.0,
546+
timestamp: "",
547+
testResults: []
548+
}];
549+
550+
QUnit.begin(function (details) {
551+
PfTestReport[0].timestamp = (new Date()).toISOString();
552+
});
553+
554+
QUnit.testDone(function (details) {
555+
PfTestReport[0].tests += 1;
556+
var isFail = details.failed > 0 || details.passed !== details.total;
557+
if (isFail) {
558+
PfTestReport[0].failures += 1;
559+
PfTestReport[0].testResults.push({
560+
classname: PlayFab._internalSettings.buildIdentifier,
561+
name: details.name,
562+
time: details.runtime / 1000.0,
563+
message: "Test failure message", // TODO: Can we get the real test message here?
564+
failureText: "FAILED"
565+
});
566+
} else {
567+
PfTestReport[0].testResults.push({
568+
classname: PlayFab._internalSettings.buildIdentifier,
569+
name: details.name,
570+
time: details.runtime / 1000.0
571+
});
572+
}
573+
});
574+
575+
// Register for all the QUnit hooks so we can track all the tests that are complete
576+
QUnit.done(function (details) {
577+
PfTestReport[0].time = details.runtime / 1000.0;
578+
579+
var saveResultsRequest = {
580+
// Currently, you need to look up the correct format for this object in the API-docs:
581+
// https://api.playfab.com/Documentation/Client/method/ExecuteCloudScript
582+
FunctionName: "SaveTestData",
583+
FunctionParameter: { customId: PlayFab._internalSettings.buildIdentifier, testReport: PfTestReport }
584+
};
585+
if (PlayFabClientSDK.IsClientLoggedIn()) {
586+
PlayFabClientSDK.ExecuteCloudScript(saveResultsRequest, null);
587+
console.log(PlayFabApiTests.testData.playFabId, ", Test report saved to CloudScript: ", PlayFab._internalSettings.buildIdentifier, "\n", JSON.stringify(PfTestReport, null, 4));
588+
} else {
589+
console.log(PlayFabApiTests.testData.playFabId, ", Failed to save test report to CloudScript: ", PlayFab._internalSettings.buildIdentifier, "\n", JSON.stringify(PfTestReport, null, 4));
590+
}
591+
});
592+
590593
PlayFabApiTests.ManualExecution();

PlayFabSDK/PlayFabAdminApi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.18.160523",
21+
sdkVersion: "0.19.160606",
22+
buildIdentifier: "jbuild_javascriptsdk_1180",
2223
productionServerUrl: ".playfabapi.com",
2324
logicServerUrl: null,
2425

@@ -104,6 +105,7 @@ if(!PlayFab._internalSettings) {
104105
}
105106

106107
PlayFab.AdminApi = {
108+
107109
GetUserAccountInfo: function (request, callback) {
108110
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
109111

PlayFabSDK/PlayFabClientApi.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.18.160523",
21+
sdkVersion: "0.19.160606",
22+
buildIdentifier: "jbuild_javascriptsdk_1180",
2223
productionServerUrl: ".playfabapi.com",
2324
logicServerUrl: null,
2425

@@ -104,6 +105,11 @@ if(!PlayFab._internalSettings) {
104105
}
105106

106107
PlayFab.ClientApi = {
108+
109+
IsClientLoggedIn: function () {
110+
return PlayFab._internalSettings.sessionTicket != null && PlayFab._internalSettings.sessionTicket.length > 0;
111+
},
112+
107113
GetPhotonAuthenticationToken: function (request, callback) {
108114
if (PlayFab._internalSettings.sessionTicket == null) throw "Must be logged in to call this method";
109115

PlayFabSDK/PlayFabMatchmakerApi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.18.160523",
21+
sdkVersion: "0.19.160606",
22+
buildIdentifier: "jbuild_javascriptsdk_1180",
2223
productionServerUrl: ".playfabapi.com",
2324
logicServerUrl: null,
2425

@@ -104,6 +105,7 @@ if(!PlayFab._internalSettings) {
104105
}
105106

106107
PlayFab.MatchmakerApi = {
108+
107109
AuthUser: function (request, callback) {
108110
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
109111

PlayFabSDK/PlayFabServerApi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.18.160523",
21+
sdkVersion: "0.19.160606",
22+
buildIdentifier: "jbuild_javascriptsdk_1180",
2223
productionServerUrl: ".playfabapi.com",
2324
logicServerUrl: null,
2425

@@ -104,6 +105,7 @@ if(!PlayFab._internalSettings) {
104105
}
105106

106107
PlayFab.ServerApi = {
108+
107109
AuthenticateSessionTicket: function (request, callback) {
108110
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
109111

0 commit comments

Comments
 (0)