added unit tests

This commit is contained in:
Brian Gough 2017-02-20 13:53:25 +00:00
parent b5a4458b68
commit a3c127e469

View file

@ -59,7 +59,12 @@ describe "RedisManager", ->
@rclient.get
.calledWith("DocVersion:#{@doc_id}")
.should.equal true
it 'should get the hash', ->
@rclient.get
.calledWith("DocHash:#{@doc_id}")
.should.equal true
it "should get the ranges", ->
@rclient.get
.calledWith("Ranges:#{@doc_id}")
@ -70,6 +75,26 @@ describe "RedisManager", ->
.calledWith(null, @lines, @version, @ranges)
.should.equal true
it 'should not log any errors', ->
@logger.error.calledWith()
.should.equal false
describe "with a corrupted document", ->
beforeEach ->
@badHash = "INVALID-HASH-VALUE"
@rclient.exec = sinon.stub().callsArgWith(0, null, [@jsonlines, @version, @badHash, @project_id, @json_ranges])
@RedisManager.getDoc @project_id, @doc_id, @callback
it 'should log a hash error', ->
@logger.error.calledWith()
.should.equal true
it 'should return the document', ->
@callback
.calledWith(null, @lines, @version, @ranges)
.should.equal true
describe "getDoc with an invalid project id", ->
beforeEach ->
@another_project_id = "project-id-456"
@ -177,6 +202,7 @@ describe "RedisManager", ->
@lines = ["one", "two", "three"]
@ops = [{ op: [{ i: "foo", p: 4 }] },{ op: [{ i: "bar", p: 8 }] }]
@version = 42
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines)).digest('hex')
@ranges = { comments: "mock", entries: "mock" }
@rclient.exec = sinon.stub().callsArg(0)
@ -200,6 +226,11 @@ describe "RedisManager", ->
@rclient.set
.calledWith("DocVersion:#{@doc_id}", @version)
.should.equal true
it "should set the hash", ->
@rclient.set
.calledWith("DocHash:#{@doc_id}", @hash)
.should.equal true
it "should set the ranges", ->
@rclient.set
@ -275,6 +306,7 @@ describe "RedisManager", ->
@rclient.exec.yields()
@lines = ["one", "two", "three"]
@version = 42
@hash = crypto.createHash('sha1').update(JSON.stringify(@lines)).digest('hex')
@ranges = { comments: "mock", entries: "mock" }
describe "with non-empty ranges", ->
@ -290,6 +322,11 @@ describe "RedisManager", ->
@rclient.set
.calledWith("DocVersion:#{@doc_id}", @version)
.should.equal true
it "should set the hash", ->
@rclient.set
.calledWith("DocHash:#{@doc_id}", @hash)
.should.equal true
it "should set the ranges", ->
@rclient.set
@ -336,6 +373,11 @@ describe "RedisManager", ->
@rclient.del
.calledWith("DocVersion:#{@doc_id}")
.should.equal true
it "should delete the hash", ->
@rclient.del
.calledWith("DocHash:#{@doc_id}")
.should.equal true
it "should delete the project_id for the doc", ->
@rclient.del