Skip to content

Commit

Permalink
Adds tests for change message visibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickharrison committed Jun 17, 2020
1 parent b0f7cf6 commit 755e684
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
7 changes: 1 addition & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
version: 2

machine:
node:
version: 6.3.0

workflow:
jobs:
build:
docker:
Expand Down Expand Up @@ -46,4 +41,4 @@ jobs:
path: coverage
prefix: coverage
- store_test_results:
path: test-results.xml
path: test-results.xml
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
};
Expand Down
30 changes: 30 additions & 0 deletions tests/change-visibility-timeout.js
Original file line number Diff line number Diff line change
@@ -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 }));
});
8 changes: 4 additions & 4 deletions tests/send-message-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit 755e684

Please sign in to comment.