<commit_before>module 'Unit: EventStream'

fakeStore =
  find: sinon.stub()
  getById: sinon.stub()
  pushPayload: sinon.spy()

eventStream = ETahi.EventStream.create(init: (-> null), store: fakeStore)
sinon.stub(eventStream, "createOrUpdateTask", -> null)


test 'created without a task pushes the data into the store', ->
  data =
    action: 'created'
    meta: null
    foo:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(fakeStore.pushPayload.calledWith({foo: {id: 1}}))

test  'create with a task will add a new task to the store and associate it to a phase', ->
  data =
    action: 'created'
    meta: null
    task:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(eventStream.createOrUpdateTask.calledWith('created', {task: {id: 1}}))

test 'updated with a task pushes the data into the store', ->
  data =
    action: 'updated'
    meta: null
    task:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(eventStream.createOrUpdateTask.calledWith('updated', {task: {id: 1}}))

test 'destroy will remove the task from the store', ->
  task =
    deleteRecord: sinon.stub()
    triggerLater: -> null
  fakeStore.findTask = () -> task

  data =<commit_msg>Reword test descriptions per PR comments.<commit_after>module 'Unit: EventStream'

fakeStore =
  find: sinon.stub()
  getById: sinon.stub()
  pushPayload: sinon.spy()

eventStream = ETahi.EventStream.create(init: (-> null), store: fakeStore)
sinon.stub(eventStream, "createOrUpdateTask", -> null)


test 'action:created without a task will call pushPayload with the data', ->
    action: 'created'
    meta: null
    foo:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(fakeStore.pushPayload.calledWith({foo: {id: 1}}))

test  'action:created with a task will call createOrUpdateTask with the action and data', ->
  data =
    action: 'created'
    meta: null
    task:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(eventStream.createOrUpdateTask.calledWith('created', {task: {id: 1}}))

test 'action:updated with a task will call createOrUpdateTask with the action and data', ->
  data =
    action: 'updated'
    meta: null
    task:
      id: 1

  eventStream.msgResponse({data: (JSON.stringify data)})
  ok(eventStream.createOrUpdateTask.calledWith('updated', {task: {id: 1}}))

test 'action:destroy will try to delete the record from the store', ->
  task =
    deleteRecord: sinon.stub()
    triggerLater: -> null
  fakeStore.findTask = () -> task

  data =
{'fraction_non_alphanumeric': 0.13046875, 'fraction_numerical': 0.0046875, 'mean_word_length': 3.7690875232774674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7387260', 'n_tokens_mistral': 841, 'n_tokens_neox': 813, 'n_words': 242}