<commit_before>var PlayFab = require('./PlayFab.js');
var PlayFabAdmin = require('./PlayFabAdmin.js'); // Not strictly needed for this test, but I want to make sure it compiles/loads
var PlayFabMatchmaker = require('./PlayFabMatchmaker.js'); // Not strictly needed for this test, but I want to make sure it compiles/loads
var PlayFabClient = require('./PlayFabClient.js');
var PlayFabServer = require('./PlayFabServer.js');
var fs = require('fs');

// These tests require that you have installed nodeunit
try {
    var reporter = require('nodeunit').reporters.default;
}
catch (e) {
    console.log("Cannot find nodeunit module.");
    console.log("Install via Command line: npm install nodeunit -g");
    process.exit();
}

var titleData = {
    // You can set default values for testing here
    // Or you can provide the same structure in a json-file and load with LoadTitleData
    titleId: "",
    developerSecretKey: "",
    titleCanUpdateSettings: "",
    userName: "",
    userEmail: "",
    userPassword: "",
    characterName: "",
};

var testConstants = {
    TEST_KEY: "testCounter",
    TEST_STAT_NAME: "str",
};

var testData = {
    playFabId: null,
    characterId: null,
    testNumber: null,
    testTimeStamp: null,
};

// Wrap PlayFab result callbacks so that exceptions in callbacks report into the test as failures
function CallbackWrapper(Callback, test) {
    return function (error, result) {
        try {
            Callback(error, result);
        } catch (e) {
            test.ok(false, "Exception thrown during test callback: " + e.toString());
            test.done(); // This is required to display the error above, and abort the test
        }
    };
}

exports.PlayFabApiTests = {
    setUp: function (callback) {
        var filename = "C:/depot/pf-main/tools/SDKBuildScripts/testTitleData.json"; // TODO: Do not hard code the location of this file
        var prefix = "testTitleData=";
        for (var arg in process.argv)
            if (arg.toLowerCase().indexOf(prefix) == 0)
                filename = arg.substr(prefix.length, arg.length - prefix.length);
        if (filename != null && fs.existsSync(filename)) {
            var inputTitleData = require(filename);

            // All of these must exist for the titleData load to be successful
            var titleDataValid = inputTitleData.hasOwnProperty("titleId")
            && inputTitleData.hasOwnProperty("developerSecretKey")
            && inputTitleData.hasOwnProperty("titleCanUpdateSettings")
            && inputTitleData.hasOwnProperty("userName")
            && inputTitleData.hasOwnProperty("userEmail")
            && inputTitleData.hasOwnProperty("userPassword")
            && inputTitleData.hasOwnProperty("characterName");

            if (titleDataValid)
                titleData = inputTitleData;
            else
                console.log("testTitleData input file did not parse correctly");
        }
        PlayFab.settings.titleId = titleData.titleId;
        PlayFab.settings.developerSecretKey = titleData.developerSecretKey;
        callback();
    },
    tearDown: function (callback) {
        callback();
    },
    InvalidLogin: function (test) {
        var invalidRequest = {
            TitleId: PlayFab.settings.titleId,
            Email: titleData.userEmail,
            Password: <PASSWORD> + "<PASSWORD>",
        };

        var InvalidLoginCallback = function (error, result) {
            test.ok(result == null, "Login should have failed");
            test.ok(error != null, "Login should have failed");
            test.ok(error.errorMessage.toLowerCase().indexOf("password") > -1, error.errorMessage);
            test.done();
        };
        PlayFabClient.LoginWithEmailAddress(invalidRequest, CallbackWrapper(InvalidLoginCallback, test));
    },
    LoginOrRegister: function (test) {
        var loginRequest = {
            // Currently, you need to look up the correct format for this object in the API-docs:
            //   https://api.playfab.com/Documentation/Client/method/LoginWithEmailAddress
            TitleId: PlayFab.settings.titleId,
            Email: titleData.userEmail,
            Password: <PASSWORD>,
        };
        var registerRequest = {
            // Currently, you need to look up the correct format for this object in the API-docs:
            //   https://api.playfab.com/Documentation/Client/method/RegisterPlayFabUser
            TitleId: PlayFab.settings.titleId,
            Username: titleData.userName,
            Email: titleData.userEmail,
            Password: <PASSWORD>,
        };

        var OptionalLoginCallback = function (error, result) {
            // First login falls back upon registration if login failed
            if (result == null) {
                // Register the character and try again
                PlayFabClient.RegisterPlayFabUser(registerRequest, CallbackWrapper(RegisterCallback, test));
            }
            else {
                // Confirm the successful login
                MandatoryLoginCallback(error, result)
            }
        };
        var RegisterCallback = function (error, result) {
            // Second login MUST succeed
            test.ok(error == null, "Registration failed");
            test.ok(result != null, "Registration failed");

            // Log in again, this time with the newly registered account
            PlayFabClient.LoginWithEmailAddress(loginRequest, CallbackWrapper(MandatoryLoginCallback, test));
        };
        var MandatoryLoginCallback = function (error, result) {
            // Login MUST succeed at some point during this test
            test.ok(error == null, "Valid login failed");
            test.ok(result != null, "Valid login failed");
            test.ok(PlayFab.settings.sessionTicket != null, "Login credentials not saved correctly");
            testData.playFabId = result.data.PlayFabId; // Save the PlayFabId, it will be used in other tests
            test.done();
        };
        PlayFabClient.LoginWithEmailAddress(loginRequest, CallbackWrapper(OptionalLoginCallback, test));
    },
    UserDataApi: function (test) {
        var getDataRequest = {}; // null also works

        var GetDataCallback1 = function (error, result) {
            test.ok(error == null, "GetUserData failed");
            test.ok(result != null, "GetUserData failed");
            test.ok(result.data.Data != null, "GetUserData failed");
            test.ok(result.data.Data.hasOwnProperty(testConstants.TEST_KEY), "GetUserData failed");

            testData.testNumber = parseInt(result.data.Data[testConstants.TEST_KEY].Value, 10);
            testData.testTimeStamp = new Date(result.data.Data[testConstants.TEST_KEY].LastUpdated);
            testData.testNumber = (testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds

            var updateDataRequest = {}; // Can't create this until we have the testNumber value
            updateDataRequest.Data = {};
            updateDataRequest.Data[testConstants.TEST_KEY] = testData.testNumber;
            PlayFabClient.UpdateUserData(updateDataRequest, CallbackWrapper(UpdateDataCallback, test));
        };
        var UpdateDataCallback = function (error, result) {
            test.ok(result != null, "UpdateUserData failed");
            test.ok(error == null, "UpdateUserData failed");
            PlayFabClient.GetUserData(getDataRequest, CallbackWrapper(GetDataCallback2, test));
        };
        var GetDataCallback2 = function (error, result) {
            test.ok(result != null, "GetUserData failed");
            test.ok(error == null, "GetUserData failed");
            test.ok(result.data.Data != null, "GetUserData failed");
            test.ok(result.data.Data.hasOwnProperty(testConstants.TEST_KEY), "GetUserData failed");

            var actualtestNumber = parseInt(result.data.Data[testConstants.TEST_KEY].Value, 10);
            var actualTimeStamp = new Date(result.data.Data[testConstants.TEST_KEY].LastUpdated);

            test.equal(testData.testNumber, actualtestNumber, "" + testData.testNumber + "!=" + actualtestNumber);
            test.ok(actualTimeStamp > testData.testTimeStamp, "Timestamp did not increase when incrementing: " + actualTimeStamp + " !> " + testData.testTimeStamp);
            test.done();
        };
<commit_msg>Fixing a minor data-consistency check.<commit_after>var PlayFab = require('./PlayFab.js');
var PlayFabAdmin = require('./PlayFabAdmin.js'); // Not strictly needed for this test, but I want to make sure it compiles/loads
var PlayFabMatchmaker = require('./PlayFabMatchmaker.js'); // Not strictly needed for this test, but I want to make sure it compiles/loads
var PlayFabClient = require('./PlayFabClient.js');
var PlayFabServer = require('./PlayFabServer.js');
var fs = require('fs');

// These tests require that you have installed nodeunit
try {
    var reporter = require('nodeunit').reporters.default;
}
catch (e) {
    console.log("Cannot find nodeunit module.");
    console.log("Install via Command line: npm install nodeunit -g");
    process.exit();
}

var titleData = {
    // You can set default values for testing here
    // Or you can provide the same structure in a json-file and load with LoadTitleData
    titleId: "",
    developerSecretKey: "",
    titleCanUpdateSettings: "",
    userName: "",
    userEmail: "",
    userPassword: "",
    characterName: "",
};

var testConstants = {
    TEST_KEY: "testCounter",
    TEST_STAT_NAME: "str",
};

var testData = {
    playFabId: null,
    characterId: null,
    testNumber: null,
    testTimeStamp: null,
};

// Wrap PlayFab result callbacks so that exceptions in callbacks report into the test as failures
function CallbackWrapper(Callback, test) {
    return function (error, result) {
        try {
            Callback(error, result);
        } catch (e) {
            test.ok(false, "Exception thrown during test callback: " + e.toString());
            test.done(); // This is required to display the error above, and abort the test
        }
    };
}

exports.PlayFabApiTests = {
    setUp: function (callback) {
        var filename = "C:/depot/pf-main/tools/SDKBuildScripts/testTitleData.json"; // TODO: Do not hard code the location of this file
        var prefix = "testTitleData=";
        for (var arg in process.argv)
            if (arg.toLowerCase().indexOf(prefix) == 0)
                filename = arg.substr(prefix.length, arg.length - prefix.length);
        if (filename != null && fs.existsSync(filename)) {
            var inputTitleData = require(filename);

            // All of these must exist for the titleData load to be successful
            var titleDataValid = inputTitleData.hasOwnProperty("titleId")
            && inputTitleData.hasOwnProperty("developerSecretKey")
            && inputTitleData.hasOwnProperty("titleCanUpdateSettings")
            && inputTitleData.hasOwnProperty("userName")
            && inputTitleData.hasOwnProperty("userEmail")
            && inputTitleData.hasOwnProperty("userPassword")
            && inputTitleData.hasOwnProperty("characterName");

            if (titleDataValid)
                titleData = inputTitleData;
            else
                console.log("testTitleData input file did not parse correctly");
        }
        PlayFab.settings.titleId = titleData.titleId;
        PlayFab.settings.developerSecretKey = titleData.developerSecretKey;
        callback();
    },
    tearDown: function (callback) {
        callback();
    },
    InvalidLogin: function (test) {
        var invalidRequest = {
            TitleId: PlayFab.settings.titleId,
            Email: titleData.userEmail,
            Password: <PASSWORD> + "<PASSWORD>",
        };

        var InvalidLoginCallback = function (error, result) {
            test.ok(result == null, "Login should have failed");
            test.ok(error != null, "Login should have failed");
            test.ok(error.errorMessage.toLowerCase().indexOf("password") > -1, error.errorMessage);
            test.done();
        };
        PlayFabClient.LoginWithEmailAddress(invalidRequest, CallbackWrapper(InvalidLoginCallback, test));
    },
    LoginOrRegister: function (test) {
        var loginRequest = {
            // Currently, you need to look up the correct format for this object in the API-docs:
            //   https://api.playfab.com/Documentation/Client/method/LoginWithEmailAddress
            TitleId: PlayFab.settings.titleId,
            Email: titleData.userEmail,
            Password: <PASSWORD>,
        };
        var registerRequest = {
            // Currently, you need to look up the correct format for this object in the API-docs:
            //   https://api.playfab.com/Documentation/Client/method/RegisterPlayFabUser
            TitleId: PlayFab.settings.titleId,
            Username: titleData.userName,
            Email: titleData.userEmail,
            Password: <PASSWORD>,
        };

        var OptionalLoginCallback = function (error, result) {
            // First login falls back upon registration if login failed
            if (result == null) {
                // Register the character and try again
                PlayFabClient.RegisterPlayFabUser(registerRequest, CallbackWrapper(RegisterCallback, test));
            }
            else {
                // Confirm the successful login
                MandatoryLoginCallback(error, result)
            }
        };
        var RegisterCallback = function (error, result) {
            // Second login MUST succeed
            test.ok(error == null, "Registration failed");
            test.ok(result != null, "Registration failed");

            // Log in again, this time with the newly registered account
            PlayFabClient.LoginWithEmailAddress(loginRequest, CallbackWrapper(MandatoryLoginCallback, test));
        };
        var MandatoryLoginCallback = function (error, result) {
            // Login MUST succeed at some point during this test
            test.ok(error == null, "Valid login failed");
            test.ok(result != null, "Valid login failed");
            test.ok(PlayFab.settings.sessionTicket != null, "Login credentials not saved correctly");
            testData.playFabId = result.data.PlayFabId; // Save the PlayFabId, it will be used in other tests
            test.done();
        };
        PlayFabClient.LoginWithEmailAddress(loginRequest, CallbackWrapper(OptionalLoginCallback, test));
    },
    UserDataApi: function (test) {
        var getDataRequest = {}; // null also works

        var GetDataCallback1 = function (error, result) {
            test.ok(error == null, "GetUserData failed");
            test.ok(result != null, "GetUserData failed");
            test.ok(result.data.Data != null, "GetUserData failed");

            if (result.data.Data.hasOwnProperty(testConstants.TEST_KEY)) {
                testData.testNumber = parseInt(result.data.Data[testConstants.TEST_KEY].Value, 10);
                testData.testTimeStamp = new Date(result.data.Data[testConstants.TEST_KEY].LastUpdated);
            } else {
                testData.testNumber = 1;
                testData.testTimeStamp = new Date();
            }
            testData.testNumber = (testData.testNumber + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds

            var updateDataRequest = {}; // Can't create this until we have the testNumber value
            updateDataRequest.Data = {};
            updateDataRequest.Data[testConstants.TEST_KEY] = testData.testNumber;
            PlayFabClient.UpdateUserData(updateDataRequest, CallbackWrapper(UpdateDataCallback, test));
        };
        var UpdateDataCallback = function (error, result) {
            test.ok(result != null, "UpdateUserData failed");
            test.ok(error == null, "UpdateUserData failed");
            PlayFabClient.GetUserData(getDataRequest, CallbackWrapper(GetDataCallback2, test));
        };
        var GetDataCallback2 = function (error, result) {
            test.ok(result != null, "GetUserData failed");
            test.ok(error == null, "GetUserData failed");
            test.ok(result.data.Data != null, "GetUserData failed");
            test.ok(result.data.Data.hasOwnProperty(testConstants.TEST_KEY), "GetUserData failed");

            var actualtestNumber = parseInt(result.data.Data[testConstants.TEST_KEY].Value, 10);
            var actualTimeStamp = new Date(result.data.Data[testConstants.TEST_KEY].LastUpdated);

            test.equal(testData.testNumber, actualtestNumber, "" + testData.testNumber + "!=" + actualtestNumber);
            test.ok(actualTimeStamp > testData.testTimeStamp, "Timestamp did not increase when incrementing: " + actualTimeStamp + " !> " + testData.testTimeStamp);
            test.done();
        };

{'fraction_non_alphanumeric': 0.10581979320531758, 'fraction_numerical': 0.0015952732644017725, 'mean_word_length': 2.5269847884976038, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6697922', 'n_tokens_mistral': 4421, 'n_tokens_neox': 4312, 'n_words': 1163}