forked from PlayFab/JavaScriptSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayFabApiTest.js
More file actions
546 lines (546 loc) · 28.7 KB
/
Copy pathPlayFabApiTest.js
File metadata and controls
546 lines (546 loc) · 28.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
var PlayFabApiTests = {
testTitleDataFilename: "testTitleData.json",
testRetryDelay: 250,
testRetryCount: 8,
titleData: {
titleId: null,
developerSecretKey: null,
userEmail: "put valid email associated with an existing account here",
extraHeaders: {}
},
testData: {
entityToken: null,
entityKey: null,
playFabId: null,
testNumber: null,
},
testConstants: {
TEST_DATA_KEY: "testCounter",
TEST_STAT_NAME: "str"
},
ManualExecution: function () {
$.getJSON(PlayFabApiTests.testTitleDataFilename, function (json) {
if (PlayFabApiTests.SetUp(json))
PlayFabApiTests.LoginTests();
}).fail(function () {
if (PlayFabApiTests.SetUp(PlayFabApiTests.titleData))
PlayFabApiTests.LoginTests();
});
},
LoginTests: function () {
// All tests run in parallel, which is a bit tricky.
// Some test rely on data loaded from other tests, and there's no super easy to force tests to be sequential/dependent
// In fact, most of the tests return here before they're done, and report back success/fail in some arbitrary future
QUnit.module("PlayFab Api Test");
QUnit.test("InvalidLogin", PlayFabApiTests.InvalidLogin);
QUnit.test("InvalidRegistration", PlayFabApiTests.InvalidRegistration);
QUnit.test("LoginOrRegister", PlayFabApiTests.LoginOrRegister);
QUnit.test("LoginWithAdvertisingId", PlayFabApiTests.LoginWithAdvertisingId);
setTimeout(function () { PlayFabApiTests.PostLoginTests(0); }, PlayFabApiTests.testRetryDelay);
setTimeout(function () { PlayFabApiTests.PostEntityTokenTests(0); }, PlayFabApiTests.testRetryDelay);
},
PostLoginTests: function (count) {
if (count > PlayFabApiTests.testRetryCount)
return;
if (!PlayFabClientSDK.IsClientLoggedIn()) {
// Wait for login
setTimeout(function () { PlayFabApiTests.PostLoginTests(count + 1); }, PlayFabApiTests.testRetryDelay);
}
else {
// Continue with other tests that require login
QUnit.test("GetEntityToken", PlayFabApiTests.GetEntityToken);
QUnit.test("EntityObjects", PlayFabApiTests.EntityObjects);
QUnit.test("UserDataApi", PlayFabApiTests.UserDataApi);
QUnit.test("PlayerStatisticsApi", PlayFabApiTests.PlayerStatisticsApi);
QUnit.test("UserCharacter", PlayFabApiTests.UserCharacter);
QUnit.test("LeaderBoard", PlayFabApiTests.LeaderBoard);
QUnit.test("AccountInfo", PlayFabApiTests.AccountInfo);
QUnit.test("CloudScript", PlayFabApiTests.CloudScript);
QUnit.test("CloudScriptError", PlayFabApiTests.CloudScriptError);
QUnit.test("WriteEvent", PlayFabApiTests.WriteEvent);
QUnit.test("ForgetCredentials", PlayFabApiTests.ForgetCredentials);
}
},
PostEntityTokenTests: function (count) {
if (count > PlayFabApiTests.testRetryCount)
return;
if (!PlayFab["_internalSettings"].entityToken) {
// Wait for login
setTimeout(function () { PlayFabApiTests.PostEntityTokenTests(count + 1); }, PlayFabApiTests.testRetryDelay);
}
else {
}
},
SetUp: function (inputTitleData) {
// All of these must exist for the titleData load to be successful
var titleDataValid = inputTitleData.hasOwnProperty("titleId") && inputTitleData.titleId != null
&& inputTitleData.hasOwnProperty("developerSecretKey") && inputTitleData.developerSecretKey != null
&& inputTitleData.hasOwnProperty("userEmail");
if (titleDataValid)
PlayFabApiTests.titleData = inputTitleData;
else
console.log("testTitleData input file did not parse correctly");
PlayFab.settings.titleId = PlayFabApiTests.titleData.titleId;
PlayFab.settings.developerSecretKey = PlayFabApiTests.titleData.developerSecretKey;
PlayFab.settings.GlobalHeaderInjection = PlayFabApiTests.titleData.extraHeaders;
return titleDataValid;
},
CallbackWrapper: function (callbackName, callback, assert) {
return function (result, error) {
try {
callback(result, error);
}
catch (e) {
console.log("Exception thrown during " + callbackName + " callback: " + e.toString() + "\n" + e.stack); // Very irritatingly, qunit doesn't report failure results until all async callbacks return, which doesn't always happen when there's an exception
assert.ok(false, "Exception thrown during " + callbackName + " callback: " + e.toString() + "\n" + e.stack);
}
};
},
SimpleCallbackWrapper: function (callbackName, callback, assert) {
return function () {
try {
callback();
}
catch (e) {
console.log("Exception thrown during " + callbackName + " callback: " + e.toString() + "\n" + e.stack); // Very irritatingly, qunit doesn't report failure results until all async callbacks return, which doesn't always happen when there's an exception
assert.ok(false, "Exception thrown during " + callbackName + " callback: " + e.toString() + "\n" + e.stack);
}
};
},
VerifyNullError: function (result, error, assert, message) {
var success = (result !== null && error == null);
if (error != null) {
assert.ok(false, "PlayFab error message: " + PlayFab.GenerateErrorReport(error));
}
else {
assert.ok(success, message);
}
},
/* CLIENT API
* Try to deliberately log in with an inappropriate password,
* and verify that the error displays as expected.
*/
InvalidLogin: function (assert) {
var invalidDone = assert.async();
var invalidRequest = {
Email: PlayFabApiTests.titleData.userEmail,
Password: "INVALID"
};
var invalidLoginCallback = function (result, error) {
assert.ok(result == null, "Login should have failed");
assert.ok(error != null, "Login should have failed");
if (error != null)
assert.ok(error.errorMessage.toLowerCase().indexOf("password") > -1, "Expect errorMessage about invalid password: " + error.errorMessage);
invalidDone();
};
PlayFabClientSDK.LoginWithEmailAddress(invalidRequest, PlayFabApiTests.CallbackWrapper("invalidLoginCallback", invalidLoginCallback, assert));
},
/* CLIENT API
* Try to deliberately register a user with an invalid email and password
* Verify that errorDetails are populated correctly.
*/
InvalidRegistration: function (assert) {
var invalidDone = assert.async();
var invalidRequest = {
Username: "x",
Email: "x",
Password: "x"
};
var registerCallback = function (result, error) {
assert.ok(result == null, "InvalidRegistration should have failed");
assert.ok(error != null, "InvalidRegistration should have failed");
var expectedEmailMsg = "email address is not valid.";
var expectedPasswordMsg = "password must be between";
var errorReport = PlayFab.GenerateErrorReport(error);
assert.ok(errorReport.toLowerCase().indexOf(expectedEmailMsg) > -1, "Expect errorMessage about invalid email: " + errorReport);
assert.ok(errorReport.toLowerCase().indexOf(expectedPasswordMsg) > -1, "Expect errorMessage about invalid password: " + errorReport);
invalidDone();
};
PlayFabClientSDK.RegisterPlayFabUser(invalidRequest, PlayFabApiTests.CallbackWrapper("registerCallback", registerCallback, assert));
},
/* CLIENT API
* Log in or create a user, track their PlayFabId
*/
LoginOrRegister: function (assert) {
var loginRequest = {
CustomId: PlayFab.buildIdentifier,
CreateAccount: true
};
var loginDone = assert.async();
var loginCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Valid login result");
assert.ok(PlayFabClientSDK.IsClientLoggedIn(), "Testing Login credentials cache");
if (result != null)
PlayFabApiTests.testData.playFabId = result.data.PlayFabId; // Save the PlayFabId, it will be used in other tests
loginDone();
};
PlayFabClientSDK.LoginWithCustomID(loginRequest, PlayFabApiTests.CallbackWrapper("loginCallback", loginCallback, assert));
},
/* CLIENT API
* Test that the login call sequence sends the AdvertisingId when set
*/
LoginWithAdvertisingId: function (assert) {
PlayFab.settings.advertisingIdType = PlayFab.settings.AD_TYPE_ANDROID_ID;
PlayFab.settings.advertisingIdValue = "PlayFabTestId";
var loginDone = assert.async();
var count = -1;
var finishAdvertId = function () {
count += 1;
if (count <= 10 && PlayFab.settings.advertisingIdType !== PlayFab.settings.AD_TYPE_ANDROID_ID + "_Successful") {
setTimeout(PlayFabApiTests.SimpleCallbackWrapper("finishAdvertId", finishAdvertId, assert), 200);
}
else {
assert.ok(PlayFab.settings.advertisingIdType === PlayFab.settings.AD_TYPE_ANDROID_ID + "_Successful", "Testing whether advertisingId submitted properly");
loginDone();
}
};
var advertLoginCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Advert-Login result");
setTimeout(PlayFabApiTests.SimpleCallbackWrapper("finishAdvertId", finishAdvertId, assert), 200);
};
var loginRequest = {
CustomId: PlayFab.buildIdentifier,
CreateAccount: true
};
PlayFabClientSDK.LoginWithCustomID(loginRequest, PlayFabApiTests.CallbackWrapper("advertLoginCallback", advertLoginCallback, assert));
},
/* CLIENT API
* Test a sequence of calls that modifies saved data,
* and verifies that the next sequential API call contains updated data.
* Verify that the data is correctly modified on the next call.
* Parameter types tested: string, Dictionary<string, string>, DateTime
*/
UserDataApi: function (assert) {
var getDataRequest = {}; // null also works
// This test is always exactly 3 async calls
var get1Done = assert.async();
var updateDone = assert.async();
var get2Done = assert.async();
var getDataCallback2 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetUserData result");
assert.ok(result.data.Data != null, "Testing GetUserData Data");
assert.ok(result.data.Data.hasOwnProperty(PlayFabApiTests.testConstants.TEST_DATA_KEY), "Testing GetUserData DataKey");
var actualtestNumber = parseInt(result.data.Data[PlayFabApiTests.testConstants.TEST_DATA_KEY].Value, 10);
var timeUpdated = new Date(result.data.Data[PlayFabApiTests.testConstants.TEST_DATA_KEY].LastUpdated).getTime();
var now = Date.now();
var testMin = now - (1000 * 60 * 5);
var testMax = now + (1000 * 60 * 5);
assert.equal(PlayFabApiTests.testData.testNumber, actualtestNumber, "Testing incrementing counter: " + PlayFabApiTests.testData.testNumber + "==" + actualtestNumber);
assert.ok(testMin <= timeUpdated && timeUpdated <= testMax, "Testing incrementing timestamp: " + timeUpdated + " vs " + now);
get2Done();
};
var updateDataCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing UpdateUserData result");
PlayFabClientSDK.GetUserData(getDataRequest, PlayFabApiTests.CallbackWrapper("getDataCallback2", getDataCallback2, assert));
updateDone();
};
var getDataCallback1 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetUserData result");
assert.ok(result.data.Data != null, "Testing GetUserData Data");
var hasData = result.data.Data.hasOwnProperty(PlayFabApiTests.testConstants.TEST_DATA_KEY);
PlayFabApiTests.testData.testNumber = !hasData ? 1 : parseInt(result.data.Data[PlayFabApiTests.testConstants.TEST_DATA_KEY].Value, 10);
PlayFabApiTests.testData.testNumber = (PlayFabApiTests.testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds
var updateDataRequest = {};
updateDataRequest.Data = {};
updateDataRequest.Data[PlayFabApiTests.testConstants.TEST_DATA_KEY] = PlayFabApiTests.testData.testNumber;
PlayFabClientSDK.UpdateUserData(updateDataRequest, PlayFabApiTests.CallbackWrapper("updateDataCallback", updateDataCallback, assert));
get1Done();
};
// Kick off this test process
PlayFabClientSDK.GetUserData(getDataRequest, PlayFabApiTests.CallbackWrapper("getDataCallback1", getDataCallback1, assert));
},
/* CLIENT API
* Test a sequence of calls that modifies saved data,
* and verifies that the next sequential API call contains updated data.
* Verify that the data is saved correctly, and that specific types are tested
* Parameter types tested: Dictionary<string, int>
*/
PlayerStatisticsApi: function (assert) {
var getStatsRequest = {}; // null also works
// This test is always exactly 3 async calls
var get1Done = assert.async();
var updateDone = assert.async();
var get2Done = assert.async();
var getStatsCallback2 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetPlayerStats result");
assert.ok(result.data.Statistics != null, "Testing GetUserData Stats");
var actualtestNumber = -1000;
for (var i = 0; i < result.data.Statistics.length; i++)
if (result.data.Statistics[i].StatisticName === PlayFabApiTests.testConstants.TEST_STAT_NAME)
actualtestNumber = result.data.Statistics[i].Value;
assert.equal(PlayFabApiTests.testData.testNumber, actualtestNumber, "Testing incrementing stat: " + PlayFabApiTests.testData.testNumber + "==" + actualtestNumber);
get2Done();
};
var updateStatsCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing UpdatePlayerStats result");
PlayFabClientSDK.GetPlayerStatistics(getStatsRequest, PlayFabApiTests.CallbackWrapper("getStatsCallback2", getStatsCallback2, assert));
updateDone();
};
var getStatsCallback1 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetPlayerStats result");
assert.ok(result.data.Statistics != null, "Testing GetUserData Stats");
PlayFabApiTests.testData.testNumber = 0;
for (var i = 0; i < result.data.Statistics.length; i++)
if (result.data.Statistics[i].StatisticName === PlayFabApiTests.testConstants.TEST_STAT_NAME)
PlayFabApiTests.testData.testNumber = result.data.Statistics[i].Value;
PlayFabApiTests.testData.testNumber = (PlayFabApiTests.testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds
var updateStatsRequest = {
Statistics: [{ StatisticName: PlayFabApiTests.testConstants.TEST_STAT_NAME, Value: PlayFabApiTests.testData.testNumber }]
};
PlayFabClientSDK.UpdatePlayerStatistics(updateStatsRequest, PlayFabApiTests.CallbackWrapper("updateStatsCallback", updateStatsCallback, assert));
get1Done();
};
// Kick off this test process
PlayFabClientSDK.GetPlayerStatistics(getStatsRequest, PlayFabApiTests.CallbackWrapper("getStatsCallback1", getStatsCallback1, assert));
},
/* CLIENT API
* Get or create the given test character for the given user
* Parameter types tested: Contained-Classes, string
*/
UserCharacter: function (assert) {
var getCharsRequest = {};
var getDone = assert.async();
var getCharsCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetChars result");
getDone();
};
PlayFabClientSDK.GetAllUsersCharacters(getCharsRequest, PlayFabApiTests.CallbackWrapper("getCharsCallback", getCharsCallback, assert));
},
/* CLIENT AND SERVER API
* Test that leaderboard results can be requested
* Parameter types tested: List of contained-classes
*/
LeaderBoard: function (assert) {
var clientRequest = {
MaxResultsCount: 3,
StartPosition: 0,
StatisticName: PlayFabApiTests.testConstants.TEST_STAT_NAME
};
var serverRequest = {
MaxResultsCount: 3,
StartPosition: 0,
StatisticName: PlayFabApiTests.testConstants.TEST_STAT_NAME
};
var lbDoneC = assert.async();
var lbDoneS = assert.async();
var getLeaderboardCallbackC = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetLeaderboard result");
if (result != null) {
assert.ok(result.data.Leaderboard != null, "Testing GetLeaderboard content");
assert.ok(result.data.Leaderboard.length > 0, "Testing GetLeaderboard content-length");
}
lbDoneC();
};
var getLeaderboardCallbackS = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetLeaderboard result");
if (result != null) {
assert.ok(result.data.Leaderboard != null, "Testing GetLeaderboard content");
assert.ok(result.data.Leaderboard.length > 0, "Testing GetLeaderboard content-length");
}
lbDoneS();
};
PlayFabClientSDK.GetLeaderboard(clientRequest, PlayFabApiTests.CallbackWrapper("getLeaderboardCallbackC", getLeaderboardCallbackC, assert));
PlayFabServerSDK.GetLeaderboard(serverRequest, PlayFabApiTests.CallbackWrapper("getLeaderboardCallbackS", getLeaderboardCallbackS, assert));
},
/* CLIENT API
* Test that AccountInfo can be requested
* Parameter types tested: List of enum-as-strings converted to list of enums
*/
AccountInfo: function (assert) {
var getDone = assert.async();
var getAccountInfoCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetAccountInfo result");
assert.ok(result.data.AccountInfo != null, "Testing GetAccountInfo");
assert.ok(result.data.AccountInfo.TitleInfo != null, "Testing TitleInfo");
assert.ok(result.data.AccountInfo.TitleInfo.Origination != null, "Testing Origination");
assert.ok(result.data.AccountInfo.TitleInfo.Origination.length > 0, "Testing Origination string-Enum");
getDone();
};
PlayFabClientSDK.GetAccountInfo({}, PlayFabApiTests.CallbackWrapper("getAccountInfoCallback", getAccountInfoCallback, assert));
},
/* CLIENT API
* Test that CloudScript can be properly set up and invoked
*/
CloudScript: function (assert) {
var hwDone = assert.async();
var helloWorldRequest = {
FunctionName: "helloWorld"
};
var helloWorldCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing HelloWorld result");
if (result != null) {
assert.ok(result.data.FunctionResult != null, "Testing HelloWorld result");
assert.ok(result.data.FunctionResult.messageValue != null, "Testing HelloWorld result message");
assert.equal(result.data.FunctionResult.messageValue, "Hello " + PlayFabApiTests.testData.playFabId + "!", "HelloWorld cloudscript result: " + result.data.FunctionResult.messageValue);
}
hwDone();
};
PlayFabClientSDK.ExecuteCloudScript(helloWorldRequest, PlayFabApiTests.CallbackWrapper("helloWorldCallback", helloWorldCallback, assert));
},
/* CLIENT API
* Test that CloudScript errors can be deciphered
*/
CloudScriptError: function (assert) {
var errDone = assert.async();
var errRequest = {
FunctionName: "throwError"
};
var errCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing Cloud Script Error result");
if (result != null) {
assert.ok(result.data.FunctionResult == null, "Testing Cloud Script Error result");
assert.ok(result.data.Error != null, "Testing Cloud Script Error result message");
assert.equal(result.data.Error.Error, "JavascriptException", "Testing Cloud Script Error result message");
}
errDone();
};
PlayFabClientSDK.ExecuteCloudScript(errRequest, PlayFabApiTests.CallbackWrapper("errCallback", errCallback, assert));
},
/* CLIENT API
* Test that the client can publish custom PlayStream events
*/
WriteEvent: function (assert) {
var writeEventDone = assert.async();
var writeEventRequest = {
EventName: "ForumPostEvent"
};
writeEventRequest.Body = {};
writeEventRequest.Body["Subject"] = "My First Post";
writeEventRequest.Body["Body"] = "This is my awesome post.";
var writeEventCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing WriteEvent result");
writeEventDone();
};
PlayFabClientSDK.WritePlayerEvent(writeEventRequest, PlayFabApiTests.CallbackWrapper("writeEventCallback", writeEventCallback, assert));
},
///* ENTITY API
// * Test a sequence of calls that modifies saved data,
// * and verifies that the next sequential API call contains updated data.
// * Verify that the data is correctly modified on the next call.
// * Parameter types tested: string, Dictionary<string, string>, DateTime
// */
GetEntityToken: function (assert) {
var getTokenDone = assert.async();
var getTokenCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetToken result");
PlayFabApiTests.testData.entityKey = result.data.Entity;
getTokenDone();
};
var getTokenRequest = {};
PlayFabEntitySDK.GetEntityToken(getTokenRequest, PlayFabApiTests.CallbackWrapper("getTokenCallback", getTokenCallback, assert));
},
///* ENTITY API
// * Test a sequence of calls that modifies saved data,
// * and verifies that the next sequential API call contains updated data.
// * Verify that the data is correctly modified on the next call.
// * Parameter types tested: string, Dictionary<string, string>, DateTime
// */
EntityObjects: function (assert) {
var getObjectRequest = {
Entity: PlayFabApiTests.testData.entityKey,
EscapeObject: true,
};
// This test is always exactly 3 async calls
var get1Done = assert.async();
var updateDone = assert.async();
var get2Done = assert.async();
var getObjectCallback2 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetObjects result");
assert.ok(result.data.Objects != null, "Testing GetObjects Objects");
var actualtestNumber = JSON.parse(result.data.Objects[PlayFabApiTests.testConstants.TEST_DATA_KEY].EscapedDataObject);
assert.ok(actualtestNumber != null && typeof actualtestNumber === "number", "Testing GetObjects contains target obj (as number)");
assert.equal(PlayFabApiTests.testData.testNumber, actualtestNumber, "Testing incrementing counter: " + PlayFabApiTests.testData.testNumber + "==" + actualtestNumber);
get2Done();
};
var setObjectCallback = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing SetObjects result");
PlayFabEntitySDK.GetObjects(getObjectRequest, PlayFabApiTests.CallbackWrapper("getObjectCallback2", getObjectCallback2, assert));
updateDone();
};
var getObjectCallback1 = function (result, error) {
PlayFabApiTests.VerifyNullError(result, error, assert, "Testing GetObjects result");
assert.ok(result.data.Objects != null, "Testing GetObjects Objects");
PlayFabApiTests.testData.testNumber = 0;
if (result.data.Objects.hasOwnProperty(PlayFabApiTests.testConstants.TEST_DATA_KEY))
PlayFabApiTests.testData.testNumber = JSON.parse(result.data.Objects[PlayFabApiTests.testConstants.TEST_DATA_KEY].EscapedDataObject);
PlayFabApiTests.testData.testNumber = (PlayFabApiTests.testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds
var updateDataRequest = {
Entity: PlayFabApiTests.testData.entityKey,
Objects: [{ ObjectName: PlayFabApiTests.testConstants.TEST_DATA_KEY, DataObject: PlayFabApiTests.testData.testNumber }]
};
PlayFabEntitySDK.SetObjects(updateDataRequest, PlayFabApiTests.CallbackWrapper("setObjectCallback", setObjectCallback, assert));
get1Done();
};
// Kick off this test process
PlayFabEntitySDK.GetObjects(getObjectRequest, PlayFabApiTests.CallbackWrapper("getObjectCallback1", getObjectCallback1, assert));
},
/* CLIENT API
* Test that the client can log out
*/
ForgetCredentials: function (assert) {
assert.ok(PlayFabClientSDK.IsClientLoggedIn(), "Client should be logged in.");
PlayFabClientSDK.ForgetAllCredentials();
assert.ok(!PlayFabClientSDK.IsClientLoggedIn(), "Client should NOT be logged in.");
},
};
// The test report that will ultimately be relayed back to Cloud Script when the suite finishes
var PfTestReport = [{
name: null,
tests: 0,
failures: 0,
errors: 0,
skipped: 0,
time: 0.0,
timestamp: "",
testResults: []
}];
QUnit.begin(function (details) {
PfTestReport[0].name = PlayFab.buildIdentifier;
PfTestReport[0].timestamp = (new Date()).toISOString();
});
QUnit.testDone(function (details) {
PfTestReport[0].tests += 1;
var isFail = details.failed > 0 || details.passed !== details.total;
if (isFail) {
PfTestReport[0].failures += 1;
PfTestReport[0].testResults.push({
classname: PlayFab.buildIdentifier,
name: details.name,
time: details.runtime / 1000.0,
message: "Test failure message",
failureText: "FAILED"
});
}
else {
PfTestReport[0].testResults.push({
classname: PlayFab.buildIdentifier,
name: details.name,
time: details.runtime / 1000.0
});
}
});
// Register for all the QUnit hooks so we can track all the tests that are complete
QUnit.done(function (details) {
PfTestReport[0].time = details.runtime / 1000.0;
var saveResultsRequest = {
FunctionName: "SaveTestData",
FunctionParameter: { customId: PlayFab.buildIdentifier, testReport: PfTestReport },
GeneratePlayStreamEvent: true
};
var onSaveResultsFinal = function (result, error) {
if (result && !error) {
console.log(PlayFabApiTests.testData.playFabId, ", Test report saved to CloudScript: ", PlayFab.buildIdentifier, "\n", JSON.stringify(PfTestReport, null, 4));
}
else {
console.log(PlayFabApiTests.testData.playFabId, ", Failed to save test report to CloudScript (CS Error): ", PlayFab.buildIdentifier, "\n", JSON.stringify(PfTestReport, null, 4));
}
};
if (PlayFabClientSDK.IsClientLoggedIn()) {
PlayFabClientSDK.ExecuteCloudScript(saveResultsRequest, onSaveResultsFinal);
}
else {
console.log(PlayFabApiTests.testData.playFabId, ", Failed to save test report to CloudScript (Login): ", PlayFab.buildIdentifier, "\n", JSON.stringify(PfTestReport, null, 4));
}
});
PlayFabApiTests.ManualExecution();
//# sourceMappingURL=PlayFabApiTest.js.map