<commit_before>﻿/// <reference path="/MobileServicesJavaScriptClient/MobileServices.js" />
/// <reference path="../testFramework.js" />

function defineMiscTestsNamespace() {
    var tests = [];
    var i;
    var roundTripTableName = 'w8jsRoundTripTable';
    var paramsTableName = 'ParamsTestTable';

    tests.push(new zumo.Test('Filter does not modify client', function (test, done) {
        var client = zumo.getClient();
        var filtered = client.withFilter(function (request, next, callback) {
            throw "This is an error";
        });
        var table = client.getTable(roundTripTableName);
        table.take(1).read().done(function (items) {
            test.addLog('Retrieved data successfully: ', items);
            done(true);
        }, function (err) {
            test.addLog('Unexpected error: ', err);
            done(false);
        });
    }));

    var createLoggingFilter = function () {
        var filter = function (request, next, callback) {
            filter.request = request;
            next(request, function (error, response) {
                filter.error = error;
                filter.response = response;
                callback(error, response);
            });
        };

        return filter;
    }

    tests.push(createFilterCaptureTest(true));
    tests.push(createFilterCaptureTest(false));

    tests.push(new zumo.Test('Filter can bypass service', function (test, done) {
        var client = zumo.getClient();
        var filter = function (request, next, callback) {
            request.id = 1;
            callback(null, {
                status: 201,
                responseText: JSON.stringify(request)
            });
        };
        var filtered = client.withFilter(filter);
        var table = filtered.getTable('TableWhichDoesNotExist');
        var item = { name: '<NAME>', age: 33 };
        table.insert(item).done(function (inserted) {
            var expected = { name: item.name, age: item.age, id: 1 };
            var errors = [];
            if (zumo.util.compare(expected, inserted, errors)) {
                done(true);
            } else {
                for (var error in errors) {
                    test.addLog(error);
                }
                test.addLog('Comparison error. Expected: ', expected, ', actual: ', inserted);
                done(false);
            }
        }, function (err) {
            test.addLog('Error on insert: ', err);<commit_msg>[W8 JS Test App] Fix filter used in bypass test<commit_after>﻿/// <reference path="/MobileServicesJavaScriptClient/MobileServices.js" />
/// <reference path="../testFramework.js" />

function defineMiscTestsNamespace() {
    var tests = [];
    var i;
    var roundTripTableName = 'w8jsRoundTripTable';
    var paramsTableName = 'ParamsTestTable';

    tests.push(new zumo.Test('Filter does not modify client', function (test, done) {
        var client = zumo.getClient();
        var filtered = client.withFilter(function (request, next, callback) {
            throw "This is an error";
        });
        var table = client.getTable(roundTripTableName);
        table.take(1).read().done(function (items) {
            test.addLog('Retrieved data successfully: ', items);
            done(true);
        }, function (err) {
            test.addLog('Unexpected error: ', err);
            done(false);
        });
    }));

    var createLoggingFilter = function () {
        var filter = function (request, next, callback) {
            filter.request = request;
            next(request, function (error, response) {
                filter.error = error;
                filter.response = response;
                callback(error, response);
            });
        };

        return filter;
    }

    tests.push(createFilterCaptureTest(true));
    tests.push(createFilterCaptureTest(false));

    tests.push(new zumo.Test('Filter can bypass service', function (test, done) {
        var client = zumo.getClient();
        var filter = function (request, next, callback) {
            var data = JSON.parse(request.data);
            data.id = 1;
            callback(null, {
                status: 201,
                responseText: JSON.stringify(data)
            });
        };
        var filtered = client.withFilter(filter);
        var table = filtered.getTable('TableWhichDoesNotExist');
        var item = { name: '<NAME>', age: 33 };
        table.insert(item).done(function (inserted) {
            var expected = { name: item.name, age: item.age, id: 1 };
            var errors = [];
            if (zumo.util.compare(expected, inserted, errors)) {
                done(true);
            } else {
                for (var error in errors) {
                    test.addLog(error);
                }
                test.addLog('Comparison error. Expected: ', expected, ', actual: ', inserted);
                done(false);
            }
        }, function (err) {
            test.addLog('Error on insert: ', err);
{'fraction_non_alphanumeric': 0.126374725054989, 'fraction_numerical': 0.003799240151969606, 'mean_word_length': 1.9217289719626167, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '6024176', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1292, 'n_words': 319}