null+****@clear*****
null+****@clear*****
2012年 7月 6日 (金) 16:20:29 JST
SHIMODA Hiroshi 2012-07-06 16:20:29 +0900 (Fri, 06 Jul 2012) New Revision: a497f2bcdd5477aedc4c32d82ff440c7a0b25d31 https://github.com/groonga/gcs/commit/a497f2bcdd5477aedc4c32d82ff440c7a0b25d31 Log: Update tests for batch API about "delete" batches #34 Modified files: test/api-batch.test.js Modified: test/api-batch.test.js (+43 -3) =================================================================== --- test/api-batch.test.js 2012-07-06 16:13:08 +0900 (21506fd) +++ test/api-batch.test.js 2012-07-06 16:20:29 +0900 (3b0baa0) @@ -4,6 +4,10 @@ var fs = require('fs'); var schemeDump = fs.readFileSync(__dirname + '/fixture/companies/ddl.grn', 'UTF-8').replace(/\s+$/, ''); var loadDump = fs.readFileSync(__dirname + '/fixture/companies/data.grn', 'UTF-8').replace(/\s+$/, ''); +var deletedLoadDump = fs.readFileSync(__dirname + '/fixture/companies/data-deleted.grn', 'UTF-8').replace(/\s+$/, ''); + +var addBatch = fs.readFileSync(__dirname + '/fixture/companies/add.sdf.json', 'UTF-8'); +var deleteBatch = fs.readFileSync(__dirname + '/fixture/companies/delete.sdf.json', 'UTF-8'); var temporaryDatabase; @@ -32,11 +36,10 @@ suite('documents/batch API', function() { }); test('add', function(done) { - var batch = fs.readFileSync(__dirname + '/fixture/companies/add.sdf.json', 'UTF-8'); var path = '/2011-02-01/documents/batch'; - utils.post(path, batch, { + utils.post(path, addBatch, { 'Content-Type': 'application/json', - 'Content-Length': batch.length, + 'Content-Length': addBatch.length, 'Host': 'doc-companies-00000000000000000000000000.localhost' }) .next(function(response) { @@ -62,6 +65,43 @@ suite('documents/batch API', function() { }); }); + test('delete', function(done) { + var path = '/2011-02-01/documents/batch'; + utils.post(path, addBatch, { + 'Content-Type': 'application/json', + 'Content-Length': addBatch.length, + 'Host': 'doc-companies-00000000000000000000000000.localhost' + }) + .next(function(response) { + return utils.post(path, deleteBatch, { + 'Content-Type': 'application/json', + 'Content-Length': deleteBatch.length, + 'Host': 'doc-companies-00000000000000000000000000.localhost' + }); + }) + .next(function(response) { + var expected = { + statusCode: 200, + body: JSON.stringify({ + status: 'success', + adds: 0, + deletes: 1 + }) + }; + assert.deepEqual(response, expected); + + var dump = database.commandSync('dump', { + tables: 'companies' + }); + assert.equal(dump, schemeDump + '\n' + deletedLoadDump); + + done(); + }) + .error(function(error) { + done(error); + }); + }); + test('no content type', function(done) { var path = '/2011-02-01/documents/batch'; utils.post(path, 'foobar', { -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download