<commit_before>var vumigo = require('vumigo_v02');
var AppTester = vumigo.AppTester;
var fixtures_IdentityStore = require('./fixtures_identity_store');
var fixtures_Pilot = require('./fixtures_pilot');
var _ = require('lodash');

describe('app', function() {
    describe('for ussd_nurse_rapidpro use', function() {
        var app;
        var tester;

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

            tester
                .setup.config.app({
                    name: 'ussd_nurse_rapidpro',
                    env: 'test',
                    no_timeout_redirects: ['state_start'],
                    channel: '*134*550*5#',
                    services: {
                        //will be replaced
                        identity_store: {
                            url: 'http://is/api/v1/',
                            token: '<PASSWORD>'
                        }
                    },
                })
                .setup(function(api) {
                    // add fixtures for services used
                    fixtures_IdentityStore().forEach(api.http.fixtures.add);
                    _.map(['27820001001', '27820001003', '27820001004'], function(address) {
                        api.http.fixtures.add(
                            fixtures_Pilot().not_exists({
                                number: '+27820001004',
                                address: address,
                                wait: false
                            }));
                        api.http.fixtures.add(
                            fixtures_Pilot().not_exists({
                                number: '+27820001004',
                                address: address,
                                wait: true
                            }));
                    });
                });

        });


        describe('state_start', function() {

            describe('user registered on nurseconnect', function(){
                it('should go to state_registered_menu', function(){
                    return tester
                    .setup.user.addr('27820001003')
                    .setup.char_limit(140)  // limit first state chars
                    .inputs(
                        {session_event: 'new'}  // dial in
                    )
                    .check.interaction({
                        state: 'state_registered',
                        reply: [
                                "Welcome back to NurseConnect. Do you want to:",
                                "1. Help a friend sign up",
                                "2. Change your number",
                                "3. Opt out",
                                "4. Change facility code",
                                "5. More"
                        ].join('\n')
                    })
                    .run();
                });

                it("should give more options when user selects more", function() {
                    return tester
                        .setup.user.addr('27820001003')
                        .setup.char_limit(140)  // limit first state chars
                        .inputs(
                            {session_event: 'new'}  // dial in
                            , '5'  // 'state_registered' - more options
                        )
                        .check.interaction({
                            state: 'state_registered',
                            reply: [
                                    "Welcome back to NurseConnect. Do you want to:",
                                    "1. Change ID no.",
                                    "2. Change SANC no.",
                                    "3. Change Persal no.",
                                    "4. Back",
                            ].join('\n')
                        })
                        .run();
                });

                it("should give the first 3 options when user selects back", function() {
                    return tester
                        .setup.user.addr('27820001003')
                        .setup.char_limit(140)  // limit first state chars
                        .inputs(
                            {session_event: 'new'}  // dial in
                            , '5'  // 'state_registered' - more options
                            , '4'  // 'state_registered' - back to first set of options
                        )
                        .check.interaction({
                            state: 'state_registered',
                            reply: [
                                "Welcome back to NurseConnect. Do you want to:",
                                "1. Help a friend sign up",
                                "2. Change your number",
                                "3. Opt out",
                                "4. Change facility code",
                                "5. More",
                            ].join('\n')
                        })
                        .run();
                });
            }); //end of registered state

            describe('user not registered on nurseconnect', function() {
                it('should go to state_not_registered', function() {
                    return tester
                    .setup.user.addr('27820001001')
                    .inputs(
                        {session_event: 'new'} // dial in<commit_msg>added tests for opt out state, for msisdn that has not yet opted out<commit_after>var vumigo = require('vumigo_v02');
var AppTester = vumigo.AppTester;
var fixtures_IdentityStore = require('./fixtures_identity_store');
var fixtures_Pilot = require('./fixtures_pilot');
var _ = require('lodash');

describe('app', function() {
    describe('for ussd_nurse_rapidpro use', function() {
        var app;
        var tester;

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

            tester
                .setup.config.app({
                    name: 'ussd_nurse_rapidpro',
                    env: 'test',
                    no_timeout_redirects: ['state_start'],
                    channel: '*134*550*5#',
                    services: {
                        //will be replaced
                        identity_store: {
                            url: 'http://is/api/v1/',
                            token: '<PASSWORD>'
                        }
                    },
                })
                .setup(function(api) {
                    // add fixtures for services used
                    fixtures_IdentityStore().forEach(api.http.fixtures.add);
                    _.map(['27820001001', '27820001003', '27820001004'], function(address) {
                        api.http.fixtures.add(
                            fixtures_Pilot().not_exists({
                                number: '+27820001004',
                                address: address,
                                wait: false
                            }));
                        api.http.fixtures.add(
                            fixtures_Pilot().not_exists({
                                number: '+27820001004',
                                address: address,
                                wait: true
                            }));
                    });
                });

        });


        describe('state_start', function() {

            describe('user registered on nurseconnect', function(){
                it('should go to state_registered_menu', function(){
                    return tester
                    .setup.user.addr('27820001003')
                    .setup.char_limit(140)  // limit first state chars
                    .inputs(
                        {session_event: 'new'}  // dial in
                    )
                    .check.interaction({
                        state: 'state_registered',
                        reply: [
                                "Welcome back to NurseConnect. Do you want to:",
                                "1. Help a friend sign up",
                                "2. Change your number",
                                "3. Opt out",
                                "4. Change facility code",
                                "5. More"
                        ].join('\n')
                    })
                    .run();
                });

                it("should give more options when user selects more", function() {
                    return tester
                        .setup.user.addr('27820001003')
                        .setup.char_limit(140)  // limit first state chars
                        .inputs(
                            {session_event: 'new'}  // dial in
                            , '5'  // 'state_registered' - more options
                        )
                        .check.interaction({
                            state: 'state_registered',
                            reply: [
                                    "Welcome back to NurseConnect. Do you want to:",
                                    "1. Change ID no.",
                                    "2. Change SANC no.",
                                    "3. Change Persal no.",
                                    "4. Back",
                            ].join('\n')
                        })
                        .run();
                });

                it("should give the first 3 options when user selects back", function() {
                    return tester
                        .setup.user.addr('27820001003')
                        .setup.char_limit(140)  // limit first state chars
                        .inputs(
                            {session_event: 'new'}  // dial in
                            , '5'  // 'state_registered' - more options
                            , '4'  // 'state_registered' - back to first set of options
                        )
                        .check.interaction({
                            state: 'state_registered',
                            reply: [
                                "Welcome back to NurseConnect. Do you want to:",
                                "1. Help a friend sign up",
                                "2. Change your number",
                                "3. Opt out",
                                "4. Change facility code",
                                "5. More",
                            ].join('\n')
                        })
                        .run();
                });
            }); //end of registered state

            //registered -- opt out
            describe("opt out for registered user", function() {
                describe("registered user - not opted out", function() {
                    describe("should reach state_optout", function() {
                        it("should ask optout reason", function() {
                            return tester
                                .setup.user.addr('27820001003')
                                .inputs(
                                    {session_event: 'new'}  // dial in
                                    , '3'  // state_registered - choose opt out
                                )
                                .check.interaction({
                                    state: 'state_optout',
                                    reply: [
                                        "Why do you want to stop getting messages?",
                                        "1. I'm not a nurse or midwife",
                                        "2. I've taken over another number",
                                        "3. The messages aren't useful",
                                        "4. Other",
                                        "5. Main Menu",
                                    ].join("\n")
                                })
                                .run();
                        });
                    });
    
                    describe("should reach state_opted_out", function() {
                        it("should thank them", function() {
                            return tester
                                .setup.user.addr('27820001003')
                                .inputs(
                                    {session_event: 'new'}  // dial in
                                    , '3'  // state_registered - choose opt out
                                    , '1'  // state_optout - not a nurse
                                )
                                .check.interaction({
                                    state: 'state_opted_out',
                                })
                                .run();
                        });
                    });

                    describe("chooses main menu", function() {
                        it("should go to state_registered", function() {
                            return tester
                                .setup.user.addr('27820001003')
                                .inputs(
                                    {session_event: 'new'}  // dial in
                                    , '3'  // state_registered - opt out
                                    , '5'  // state_optout - main menu
                                )
                                .check.interaction({
                                    state: 'state_registered',
                                })
                                .run();
                        });
                });
            });
            });

            describe('user not registered on nurseconnect', function() {
                it('should go to state_not_registered', function() {
                    return tester
                    .setup.user.addr('27820001001')
                    .inputs(
                        {session_event: 'new'} // dial in
{'fraction_non_alphanumeric': 0.09151031557760046, 'fraction_numerical': 0.022643950830278196, 'mean_word_length': 0.7357454772301933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 70, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3082347', 'n_tokens_mistral': 3269, 'n_tokens_neox': 2784, 'n_words': 707}