diff --git a/.circleci/config.yml b/.circleci/config.yml index 291960c..cd53ab4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,10 +1,5 @@ version: 2 - -machine: - node: - version: 6.3.0 -workflow: jobs: build: docker: @@ -46,4 +41,4 @@ jobs: path: coverage prefix: coverage - store_test_results: - path: test-results.xml \ No newline at end of file + path: test-results.xml diff --git a/index.js b/index.js index 3e38ddb..478f660 100644 --- a/index.js +++ b/index.js @@ -166,11 +166,11 @@ Client.prototype.changeVisibilityTimeout = function (message, newVisibilityTimeo ReceiptHandle: message.ReceiptHandle, VisibilityTimeout: newVisibilityTimeout }, function (err, data) { - if (data) { - return resolve(data); + if (err) { + return reject(err); } - return reject(err); + return resolve(data); }); }); }; diff --git a/tests/change-visibility-timeout.js b/tests/change-visibility-timeout.js new file mode 100644 index 0000000..1952938 --- /dev/null +++ b/tests/change-visibility-timeout.js @@ -0,0 +1,30 @@ +import test from 'ava'; +import sinon from 'sinon'; + +import sqs from '../index'; + +test.beforeEach((t) => { + t.context.client = sqs({ accessKeyId: 'foo', secretAccessKey: 'bar', queue: 'baz' }); + + sinon.stub(t.context.client.sqs, 'changeMessageVisibility', function (params, callback) { + setImmediate(function () { + callback(); + }); + }); +}); + +test.afterEach((t) => { + t.context.client.sqs.changeMessageVisibility.restore(); +}); + +test('returns a promise', (t) => { + const value = t.context.client.changeVisibilityTimeout({ ReceiptHandle: 'foobar' }, 5); + + t.true(typeof value.then === 'function'); +}); + +test('calls changeMessageVisbility with the message receipt', async (t) => { + await t.context.client.changeVisibilityTimeout({ ReceiptHandle: 'foobar' }, 1337); + + t.true(t.context.client.sqs.changeMessageVisibility.calledWith({ ReceiptHandle: 'foobar', VisibilityTimeout: 1337 })); +}); diff --git a/tests/send-message-batch.js b/tests/send-message-batch.js index d035d60..b1e9460 100644 --- a/tests/send-message-batch.js +++ b/tests/send-message-batch.js @@ -29,10 +29,10 @@ test('returns a promise', (t) => { t.true(typeof value.then === 'function'); }); -test('calls sendMessageBatch with the message body', (t) => { +test('calls sendMessageBatch with the message body', async (t) => { const message = { type: 'ACTION_TYPE', payload: 1337 }; - t.context.client.sendMessageBatch([message]); + await t.context.client.sendMessageBatch([message]); t.true(t.context.client.sqs.sendMessageBatch.calledWith({ Entries: [sinon.match({ @@ -41,10 +41,10 @@ test('calls sendMessageBatch with the message body', (t) => { })); }); -test('should extend the default options', (t) => { +test('should extend the default options', async (t) => { const message = { type: 'ACTION_TYPE', payload: 1337 }; - t.context.client.sendMessageBatch([message], { DelaySeconds: 3 }); + await t.context.client.sendMessageBatch([message], { DelaySeconds: 3 }); t.true(t.context.client.sqs.sendMessageBatch.calledWith({ Entries: [sinon.match({