Permalink
Browse files

added /token endpoint and better error reporting

  • Loading branch information...
toolness committed Jul 30, 2012
1 parent 9224a50 commit d46602a80ef679fc79a851b19cb8a3dcbfbff4a7
Showing with 34 additions and 2 deletions.
  1. +4 −2 simple-git-server.js
  2. +30 −0 test/test-simple-git-server.js
View
@@ -38,10 +38,11 @@ function makeCommitHandler(git, postCommit) {
postCommit(git);
git.end(function(err) {
if (err) {
- if (!err.stderr)
+ var message = err.stderr || err.stdout;
+ if (!message)
return res.send('an unknown error occurred', 500);
return res.send({
- error: err.stderr
+ error: message
}, 409);
}
res.send(200);
@@ -72,6 +73,7 @@ module.exports = function SimpleGitServer(config) {
self.use(express.bodyParser());
self.use(bic.accessToken);
self.use(bic.fullCORS);
+ self.post('/token', bic.handleTokenRequest);
self.post('/commit', self.handleCommit);
self.get('/ls', self.handleList);
@@ -161,6 +161,28 @@ describe("SimpleGitServer", function() {
.expect(500, 'an unknown error occurred', done);
});
+ it("should return 200 when commit results in no change", function(done) {
+ request(cfg(SimpleGitServer({
+ git: {
+ rm: function() {},
+ commit: function() {},
+ end: function(cb) {
+ cb({
+ stderr: '',
+ stdout: '# On branch master\nnothing to commit (working directory clean)\n',
+ exitCode: 1
+ });
+ }
+ }
+ })))
+ .post('/commit')
+ .set('X-Access-Token', 'abcd')
+ .send({remove: ['meh']})
+ .expect(409, {
+ error: '# On branch master\nnothing to commit (working directory clean)\n'
+ }, done);
+ });
+
it("should return 409 w/ info for known git errors", function(done) {
request(cfg(SimpleGitServer({
git: {
@@ -203,6 +225,14 @@ describe("SimpleGitServer", function() {
.expect(200, {files: ['bloop/bap.js']}, done);
});
+ it("should have /token endpoint", function(done) {
+ request(cfg(SimpleGitServer({git: {}})))
+ .post('/token')
+ .set('Origin', 'http://lol.org')
+ .send()
+ .expect(400, 'assertion required', done);
+ });
+
it("should support CORS", function(done) {
request(cfg(SimpleGitServer({git: {}})))
.head('/')

0 comments on commit d46602a

Please sign in to comment.