<commit_before>var vumigo = require("vumigo_v02");
var AppTester = vumigo.AppTester;

var fixtures_IdentityStore = require('./fixtures_identity_store');
var fixtures_StageBasedMessaging = require('./fixtures_stage_based_messaging');
var fixtures_MessageSender = require('./fixtures_message_sender');
var fixtures_Hub = require('./fixtures_hub');
var fixtures_Jembi = require('./fixtures_jembi');
var fixtures_ServiceRating = require('./fixtures_service_rating');

var utils = require('seed-jsbox-utils').utils;

describe("app", function() {
    describe("for ussd_public use", function() {
        var app;
        var tester;

        beforeEach(function() {
            app = new go.app.GoNDOH();

            tester = new AppTester(app);

            tester
                .setup.config.app({
                    name: 'ussd_public',
                    testing_today: "2014-04-04",
                    logging: "off",
                    no_timeout_redirects: [
                        "state_start", "state_end_not_pregnant", "state_end_consent_refused",
                        "state_end_success", "state_registered_full", "state_registered_not_full",
                        "state_end_compliment", "state_end_complaint", "state_end_go_clinic"],
                    channel: "*120*550#",
                    services: {
                        identity_store: {
                            url: 'http://is/api/v1/',
                            token: 'test IdentityStore'
                        },
                        stage_based_messaging: {
                            url: 'http://sbm/api/v1/',
                            token: 'test StageBasedMessaging'
                        },
                        hub: {
                            url: 'http://hub/api/v1/',
                            token: 'test Hub'
                        },
                        message_sender: {
                            url: 'http://ms/api/v1/',
                            token: 'test MessageSender'
                        }
                    },
                })
                .setup(function(api) {
                    // add fixtures for services used
                    fixtures_Hub().forEach(api.http.fixtures.add); // fixtures 0 - 49
                    fixtures_StageBasedMessaging().forEach(api.http.fixtures.add); // 50 - 99
                    fixtures_MessageSender().forEach(api.http.fixtures.add); // 100 - 139
                    fixtures_ServiceRating().forEach(api.http.fixtures.add); // 140 - 149
                    fixtures_Jembi().forEach(api.http.fixtures.add);  // 150 - 159
                    fixtures_IdentityStore().forEach(api.http.fixtures.add); // 160 ->
                });
        });

        describe("timeout testing", function() {
            describe("when you timeout and dial back in", function() {
                describe("when on a registration state", function() {
                    it("should go to state_timed_out", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                        )
                        .check.interaction({
                            state: "state_timed_out",
                            reply: [
                                'Welcome back. Please select an option:',
                                '1. Continue signing up for messages',
                                '2. Main menu'
                            ].join('\n')
                        })
                        .run();
                    });
                });
                describe("when on a non-registration state", function() {
                    it("should restart, not go state_timed_out", function() {
                        return tester
                        .setup.user.addr("27820001002")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_registered_full - compliment
                            , {session_event: "close"}
                            , {session_event: "new"}
                        )
                        .check.interaction({
                            state: "state_registered_full",
                        })
                        .run();
                    });
                });
            });

            describe("when you've reached state_timed_out", function() {
                describe("choosing to continue", function() {
                    it("should go back to the state you were on", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , "1"  // state_timed_out - continue
                        )
                        .check.interaction({
                            state: "state_suspect_pregnancy",
                        })
                        .run();
                    });
                });
                describe("choosing to abort", function() {
                    it("should restart", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , "2"  // state_timed_out - main menu
                        )
                        .check.interaction({
                            state: "state_language",
                        })
                        .run();
                    });
                });
            });
        });

        describe("dialback sms testing", function() {
            it("send if redial sms not yet sent", function() {
                return tester
                .setup.user.addr("27820001001")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_language - isiZulu
                    , {session_event: 'close'}
                )
                .check.user.answer("redial_sms_sent", true)
                .check(function(api) {
                    utils.check_fixtures_used(api, [125, 160, 163]);
                })
                .run();
            });
            it("don't send if redial sms already sent", function() {
                return tester
                .setup.user.addr("27820001011")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_registered_full - compliment
                    , {session_event: 'close'}
                )
                .check.user.answer("redial_sms_sent", true)
                .check(function(api) {
                    utils.check_fixtures_used(api, [53, 54, 127, 187]);
                })
                .run();
            });
            it("updates identity with redial_sms_sent 'false'", function() {
                return tester
                .setup.user.addr("27820001001")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_language - zul_ZA<commit_msg>change description for test (testing a timeout on non-dialback state)<commit_after>var vumigo = require("vumigo_v02");
var AppTester = vumigo.AppTester;

var fixtures_IdentityStore = require('./fixtures_identity_store');
var fixtures_StageBasedMessaging = require('./fixtures_stage_based_messaging');
var fixtures_MessageSender = require('./fixtures_message_sender');
var fixtures_Hub = require('./fixtures_hub');
var fixtures_Jembi = require('./fixtures_jembi');
var fixtures_ServiceRating = require('./fixtures_service_rating');

var utils = require('seed-jsbox-utils').utils;

describe("app", function() {
    describe("for ussd_public use", function() {
        var app;
        var tester;

        beforeEach(function() {
            app = new go.app.GoNDOH();

            tester = new AppTester(app);

            tester
                .setup.config.app({
                    name: 'ussd_public',
                    testing_today: "2014-04-04",
                    logging: "off",
                    no_timeout_redirects: [
                        "state_start", "state_end_not_pregnant", "state_end_consent_refused",
                        "state_end_success", "state_registered_full", "state_registered_not_full",
                        "state_end_compliment", "state_end_complaint", "state_end_go_clinic"],
                    channel: "*120*550#",
                    services: {
                        identity_store: {
                            url: 'http://is/api/v1/',
                            token: 'test IdentityStore'
                        },
                        stage_based_messaging: {
                            url: 'http://sbm/api/v1/',
                            token: 'test StageBasedMessaging'
                        },
                        hub: {
                            url: 'http://hub/api/v1/',
                            token: 'test Hub'
                        },
                        message_sender: {
                            url: 'http://ms/api/v1/',
                            token: 'test <PASSWORD>'
                        }
                    },
                })
                .setup(function(api) {
                    // add fixtures for services used
                    fixtures_Hub().forEach(api.http.fixtures.add); // fixtures 0 - 49
                    fixtures_StageBasedMessaging().forEach(api.http.fixtures.add); // 50 - 99
                    fixtures_MessageSender().forEach(api.http.fixtures.add); // 100 - 139
                    fixtures_ServiceRating().forEach(api.http.fixtures.add); // 140 - 149
                    fixtures_Jembi().forEach(api.http.fixtures.add);  // 150 - 159
                    fixtures_IdentityStore().forEach(api.http.fixtures.add); // 160 ->
                });
        });

        describe("timeout testing", function() {
            describe("when you timeout and dial back in", function() {
                describe("when on a registration state", function() {
                    it("should go to state_timed_out", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                        )
                        .check.interaction({
                            state: "state_timed_out",
                            reply: [
                                'Welcome back. Please select an option:',
                                '1. Continue signing up for messages',
                                '2. Main menu'
                            ].join('\n')
                        })
                        .run();
                    });
                });
                describe("when on a non-registration state", function() {
                    it("should restart, not go state_timed_out", function() {
                        return tester
                        .setup.user.addr("27820001002")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_registered_full - compliment
                            , {session_event: "close"}
                            , {session_event: "new"}
                        )
                        .check.interaction({
                            state: "state_registered_full",
                        })
                        .run();
                    });
                });
            });

            describe("when you've reached state_timed_out", function() {
                describe("choosing to continue", function() {
                    it("should go back to the state you were on", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , "1"  // state_timed_out - continue
                        )
                        .check.interaction({
                            state: "state_suspect_pregnancy",
                        })
                        .run();
                    });
                });
                describe("choosing to abort", function() {
                    it("should restart", function() {
                        return tester
                        .setup.user.addr("27820001001")
                        .inputs(
                            {session_event: "new"}
                            , "1"  // state_language - zul_ZA
                            , {session_event: "close"}
                            , {session_event: "new"}
                            , "2"  // state_timed_out - main menu
                        )
                        .check.interaction({
                            state: "state_language",
                        })
                        .run();
                    });
                });
            });
        });

        describe("dialback sms testing", function() {
            it("send if redial sms not yet sent", function() {
                return tester
                .setup.user.addr("27820001001")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_language - isiZulu
                    , {session_event: 'close'}
                )
                .check.user.answer("redial_sms_sent", true)
                .check(function(api) {
                    utils.check_fixtures_used(api, [125, 160, 163]);
                })
                .run();
            });
            it("don't send if redial sms already sent", function() {
                return tester
                .setup.user.addr("27820001011")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_registered_full - compliment
                    , {session_event: 'close'}
                )
                .check.user.answer("redial_sms_sent", true)
                .check(function(api) {
                    utils.check_fixtures_used(api, [53, 54, 127, 187]);
                })
                .run();
            });
            it("don't send when timeout occurs on a non-dialback state", function() {
                return tester
                .setup.user.addr("27820001001")
                .inputs(
                    {session_event: 'new'}  // dial in
                    , "1"  // state_language - zul_ZA
{'fraction_non_alphanumeric': 0.10593971631205673, 'fraction_numerical': 0.01963019250253293, 'mean_word_length': 0.9701846307385229, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5798316', 'n_tokens_mistral': 4111, 'n_tokens_neox': 3585, 'n_words': 710}