|
| 1 | +var assert = require("assert"); |
| 2 | +var path = require("path"); |
| 3 | +var local = path.join.bind(path, __dirname); |
| 4 | + |
| 5 | +describe("Note", function() { |
| 6 | + var NodeGit = require("../../"); |
| 7 | + var Note = NodeGit.Note; |
| 8 | + var Signature = NodeGit.Signature; |
| 9 | + var reposPath = local("../repos/merge"); |
| 10 | + |
| 11 | + beforeEach(function() { |
| 12 | + var test = this; |
| 13 | + |
| 14 | + return NodeGit.Repository.open(reposPath).then(function(repository) { |
| 15 | + test.repository = repository; |
| 16 | + |
| 17 | + return repository.getMasterCommit().then(function(commit) { |
| 18 | + test.commit = commit; |
| 19 | + }); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it("can be created", function() { |
| 24 | + var sha = this.commit.id(); |
| 25 | + var sig = Signature.create("John", "john@doe.com", Date.now(), 0); |
| 26 | + var noteRef = "refs/notes/commits"; |
| 27 | + |
| 28 | + return Note.create(this.repository, noteRef, sig, sig, sha, "Testing!", 1); |
| 29 | + }); |
| 30 | + |
| 31 | + it("can be read", function() { |
| 32 | + var sha = this.commit.id(); |
| 33 | + var noteRef = "refs/notes/commits"; |
| 34 | + |
| 35 | + return Note.read(this.repository, noteRef, sha).then(function(note) { |
| 36 | + assert.equal(note.message(), "Testing!"); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it("can be removed", function(done) { |
| 41 | + var sha = this.commit.id(); |
| 42 | + var noteRef = "refs/notes/commits"; |
| 43 | + var sig = Signature.create("John", "john@doe.com", Date.now(), 0); |
| 44 | + |
| 45 | + Note.remove(this.repository, noteRef, sig, sig, sha); |
| 46 | + |
| 47 | + return Note.read(this.repository, noteRef, sha).catch(function(ex) { |
| 48 | + assert.equal(ex.message, "Note could not be found"); |
| 49 | + done(); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments