jeudi 3 septembre 2015

Jasmine Unit Test Mock Functions Which Are Not Passed

I have two functions I want to mock. The first one is straight forward instead of passing the real TCP client I mock one and pass it

But inside the sendAcknowlegmentMessage function is the hl7Date() function I want to mock also. This second function returns a date-time-string which makes the comparison of the result more difficult because it will be every time another date-time.

hl7.spec.coffee

describe('>>>>>>>>>>>>>>>>>>>>>>>>>  HL7 FUNCTIONS  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<', () ->

  it('should be able to send an AA ACK Message', (done) ->
    err = ''
    client = {}
    client.write = (message)->
      expect(message).toBe(testDummies.hl7.expectedACK)
      done()

    hl7.sendAcknowlegmentMessage(testDummies.hl7.parsedMessage, true, err, client)

hl7.coffee

hl7Date = () ->
  new Date().toISOString().slice(0,16).replace(/-|:|T/g,"") ##YYYYMMDDHHMMSS.UUUU[+|-ZZzz] digits on the right side can be skipped

exports.sendAcknowlegmentMessage = (message, accept, err, client) ->
...
  msh = 'MSH|^~\\&|' + sendingApplication + '|' + sendingFacility + '|' + receivingApplication + '|' + receivingFacility + '|' + hl7Date() + '||ACK' + messageType + '|' + answerMessageId + '|P|' + versionID + '\r\n'
  msa = 'MSA|' + messageAccepted + '|' + messageControllId + '|' + err + '|' + '\r\n'
  returnMessage = '\v' + msh + msa + '\r\n'
  client.write(returnMessage)
...

Aucun commentaire:

Enregistrer un commentaire