<commit_before>describe 'Find ReadAggregates By Date Range Scenario', ->

  expect   = require 'expect'
  sinon    = require 'sinon'
  eventric = require 'eventric'

  ReadAggregateRoot       = eventric 'ReadAggregateRoot'
  ReadAggregateRepository = eventric 'ReadAggregateRepository'

  describe 'given we want to get all ReadExampleAggregates between two dates', ->

    describe 'when we ask the ReadExampleRepository to find the matching ReadAggregates', ->

      it 'then it should return the corresponding list of ReadExampleAggregates', ->
        # Example Classes
        class ReadExample extends ReadAggregateRoot

        class ReadExampleRepository extends ReadAggregateRepository

          findByDateRange: (start, end) ->
            # criteria not actually used here, just to show how it could look like
            exampleCriteria =
              aggregateName: 'ReadExample'
              eventName: 'create'
              eventTimestamp:
                $gte: start
                $lt: end

            # find the aggregateIds matching the criteria
            aggregateIds = @findIds exampleCriteria

            # find the actual ReadAggregates by id
            readAggregates = @findByIds aggregateIds

        class ExampleAdapter
          find: ->
          _findDomainEventsByAggregateId: ->

        # create a stub instance of the ExampleAdapter
        exampleAdapterStub = sinon.createStubInstance ExampleAdapter

        # stub ExampleAdapter.find to return an example id only
        exampleAdapterStub.find.returns [
          {'id': 1}
        ]

        # stub ExampleAdapter._findDomainEventsByAggregateId to return example DomainEvents
        exampleAdapterStub._findDomainEventsByAggregateId.withArgs(1).returns
          id: 1
          name: 'example'

        # instantiate the ReadExampleRepository with the stubbed Adapter and the ReadExample Class
        readExampleRepository = new ReadExampleRepository exampleAdapterStub, ReadExample

        # example start, end dates
        start = new Date 2013, 10, 1
        end = new Date 2014, 2, 1

        # ask the ReadExampleRepository to find ReagAggregates by DateRange<commit_msg>Change Feature Spec to match the new ReadAggregateRepository structure<commit_after>describe 'Find ReadAggregates By Date Range Scenario', ->

  expect   = require 'expect'
  sinon    = require 'sinon'
  eventric = require 'eventric'

  ReadAggregateRoot       = eventric 'ReadAggregateRoot'
  ReadAggregateRepository = eventric 'ReadAggregateRepository'

  describe 'given we want to get all ReadExampleAggregates between two dates', ->

    describe 'when we ask the ReadExampleRepository to find the matching ReadAggregates', ->

      it 'then it should return the corresponding list of ReadExampleAggregates', ->
        # Example Classes
        class ReadExample extends ReadAggregateRoot

        class ReadExampleRepository extends ReadAggregateRepository

          findByDateRange: (start, end) ->
            # criteria not actually used here, just to show how it could look like
            exampleCriteria =
              aggregateName: 'ReadExample'
              eventName: 'create'
              eventTimestamp:
                $gte: start
                $lt: end

            # find the aggregateIds matching the criteria
            aggregateIds = @findIds exampleCriteria

            # find the actual ReadAggregates by id
            readAggregates = @findByIds aggregateIds

        class ExampleAdapter
          _findAggregateIdsByDomainEventCriteria: ->
          _findDomainEventsByAggregateId: ->

        # create a stub instance of the ExampleAdapter
        exampleAdapterStub = sinon.createStubInstance ExampleAdapter

        # stub ExampleAdapter._findAggregateIdsByDomainEventCriteria to return an example id only
        exampleAdapterStub._findAggregateIdsByDomainEventCriteria.returns [42]

        # stub ExampleAdapter._findDomainEventsByAggregateId to return an example DomainEvent
        exampleAdapterStub._findDomainEventsByAggregateId.withArgs(42).returns [
          name: 'testEvent'
          _changed:
            props:
              name: 'example'
        ]

        # instantiate the ReadExampleRepository with the stubbed Adapter and the ReadExample Class
        readExampleRepository = new ReadExampleRepository exampleAdapterStub, ReadExample

        # example start, end dates
        start = new Date 2013, 10, 1
        end = new Date 2014, 2, 1

        # ask the ReadExampleRepository to find ReagAggregates by DateRange
{'fraction_non_alphanumeric': 0.04750437828371278, 'fraction_numerical': 0.007224168126094571, 'mean_word_length': 2.606156274664562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4553186', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1078, 'n_words': 377}