From a3c127e46936b63cd04309da6cf8cde586063fa9 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 20 Feb 2017 13:53:25 +0000 Subject: [PATCH] added unit tests --- .../RedisManager/RedisManagerTests.coffee | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/services/document-updater/test/unit/coffee/RedisManager/RedisManagerTests.coffee b/services/document-updater/test/unit/coffee/RedisManager/RedisManagerTests.coffee index 6e235b4a9d..daad278174 100644 --- a/services/document-updater/test/unit/coffee/RedisManager/RedisManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/RedisManager/RedisManagerTests.coffee @@ -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