<commit_before>#require('nez').realize 'Message', (Message, test, context, should) -> 
    
{_message, message} = require '../../lib/notice/message'
should  = require 'should'

describe 'Message', -> 

    context 'async create()', ->

        it 'is created with a set of properties', (done) -> 

            Message = message()

            Message.create
                property1: 'value1'
                property2: 'value2'

            .then (m) -> m.should.eql
                property1: 'value1'
                property2: 'value2'
                done()


        it 'can have predefined properties', (done) -> 

            Message = message 
                properties:
                    property3: 
                        default: 'defaultValue'

            Message.create 
                property1: 'value1'

            .then (m) -> m.should.eql
                property3: 'defaultValue'
                property1: 'value1'
                done()


        it 'predefined default values are overridden', (done) ->

            Message = message 
                properties:
                    prop: 
                        default: 1

            Message.create 
                prop: 2
            .then (m) -> 
                m.prop.should.eql 2
                done()


        it 'can set properties to not be enumerated by serializers', (done) -> 

            Message = message 
                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true

            Message.create().then (m) ->
                m.internalCode.should.equal 'R'
                m.internalCode = 'X'
                m.internalCode.should.equal 'X'
                m.should.eql {}
                done()


        it 'calls beforeCreate ahead of property assignment', (done) -> 

            Message = message 
                beforeCreate: (msg, done) -> 
                    msg.preAssigned = 'value'
                    done()

                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true

            Message.create().then (m) ->

                m.should.eql preAssigned: 'value'
                m.internalCode.should.equal 'R'
                done()


        it 'calls afterCreate after property assignment', (done) -> 

            Message = message 
                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true
                afterCreate: (msg, done) ->  
                    msg.one++
                    done()

            Message.create
                one: 1
                two: 2
            .then (m) -> 
                m.one.should.equal 2
                done()


xdescribe 'Message', -> 

    context 'title and description', -> 
<commit_msg>beforeCreate and afterCreate can fail the message creation<commit_after>#require('nez').realize 'Message', (Message, test, context, should) -> 
    
{_message, message} = require '../../lib/notice/message'
should  = require 'should'

describe 'Message', -> 

    context 'async create()', ->

        it 'is created with a set of properties', (done) -> 

            Message = message()

            Message.create
                property1: 'value1'
                property2: 'value2'

            .then (m) -> m.should.eql
                property1: 'value1'
                property2: 'value2'
                done()


        it 'can have predefined properties', (done) -> 

            Message = message 
                properties:
                    property3: 
                        default: 'defaultValue'

            Message.create 
                property1: 'value1'

            .then (m) -> m.should.eql
                property3: 'defaultValue'
                property1: 'value1'
                done()


        it 'predefined default values are overridden', (done) ->

            Message = message 
                properties:
                    prop: 
                        default: 1

            Message.create 
                prop: 2
            .then (m) -> 
                m.prop.should.eql 2
                done()


        it 'can set properties to not be enumerated by serializers', (done) -> 

            Message = message 
                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true

            Message.create().then (m) ->
                m.internalCode.should.equal 'R'
                m.internalCode = 'X'
                m.internalCode.should.equal 'X'
                m.should.eql {}
                done()


        it 'calls beforeCreate ahead of property assignment', (done) -> 

            Message = message 
                beforeCreate: (msg, done) -> 
                    msg.preAssigned = 'value'
                    done()

                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true

            Message.create().then (m) ->

                m.should.eql preAssigned: 'value'
                m.internalCode.should.equal 'R'
                done()


        it 'calls afterCreate after property assignment', (done) -> 

            Message = message 
                properties:
                    internalCode: 
                        default: 'R'
                        hidden:  true
                afterCreate: (msg, done) ->  
                    msg.one++
                    done()

            Message.create
                one: 1
                two: 2
            .then (m) -> 
                m.one.should.equal 2
                done()


        it 'beforeCreate and afterCreate can fail the message creation', (done) -> 

            Message = message 
                beforeCreate: (msg, done) ->  
                    done new Error 'darn, no DB to save initial message state'

            Message.create( 'helloo-oo-oo': 'bat flies out' ).then (->), (error) ->

                error.message.should.equal 'darn, no DB to save initial message state'
                done()


xdescribe 'Message', -> 

    context 'title and description', -> 

{'fraction_non_alphanumeric': 0.0936951316839585, 'fraction_numerical': 0.006384676775738229, 'mean_word_length': 1.0239018087855296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '2623751', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1402, 'n_words': 412}