Skip to content

Commit

Permalink
Add tests for lib/state-store
Browse files Browse the repository at this point in the history
  • Loading branch information
eaviles committed Jun 3, 2019
1 parent c3f30a8 commit 54662a1
Show file tree
Hide file tree
Showing 7 changed files with 1,761 additions and 418 deletions.
2 changes: 1 addition & 1 deletion lib/__mocks__/aws-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Kinesis = jest.fn(({ endpoint } = {}) => {
createStream,
deregisterStreamConsumer,
describeStream,
endpoint: { host: endpoint || '' },
endpoint: new URL(endpoint || 'https://kinesis.amazonaws.com/'),
getRecords,
getShardIterator,
isEndpointLocal,
Expand Down
14 changes: 14 additions & 0 deletions lib/__mocks__/short-uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

let counter = 0;

module.exports = {
generate: () => {
const value = counter.toString().padStart(4, '0');
counter += 1;
return value;
},
resetMockCounter: () => {
counter = 0;
}
};
20 changes: 3 additions & 17 deletions lib/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const shortUuid = require('short-uuid');
const { resetMockCounter } = require('short-uuid');

const ConsumersManager = require('./consumers-manager');
const HeartbeatManager = require('./heartbeat-manager');
const KinesisClient = require('./kinesis-client');
Expand All @@ -11,20 +12,6 @@ const stream = require('./stream');

const Kinesis = require('.');

jest.mock('short-uuid', () => {
let counter = 0;
return {
clearMockData: () => {
counter = 0;
},
generate: () => {
const id = counter.toString().padStart(4, '0');
counter += 1;
return id;
}
};
});

jest.mock('./stats');

jest.mock('./consumers-manager', () => {
Expand Down Expand Up @@ -125,8 +112,6 @@ describe('lib/index', () => {
});

afterEach(() => {
shortUuid.clearMockData();

const consumersManager = new ConsumersManager();
consumersManager.reconcile.mockClear();
consumersManager.stop.mockClear();
Expand Down Expand Up @@ -167,6 +152,7 @@ describe('lib/index', () => {
stream.clearMockData();

setTimeout.mockClear();
resetMockCounter();
});

test('the module exports the expected', () => {
Expand Down
14 changes: 7 additions & 7 deletions lib/kinesis-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('lib/kinesis-client', () => {
if (methodName === 'putRecords') {
test('putRecords should retry failed records until it succeeds', async () => {
let mockedSeqNum = 0;
function putHalfOfRecords(params) {
function putTwoRecords(params) {
return {
promise: () => {
let FailedRecordCount = 0;
Expand All @@ -181,8 +181,8 @@ describe('lib/kinesis-client', () => {
}
};
}
sdkClient.putRecords.mockImplementationOnce(putHalfOfRecords);
sdkClient.putRecords.mockImplementationOnce(putHalfOfRecords);
sdkClient.putRecords.mockImplementationOnce(putTwoRecords);
sdkClient.putRecords.mockImplementationOnce(putTwoRecords);
await expect(
client.putRecords({ Records: [{ Data: 'foo' }, { Data: 'bar' }, { Data: 'baz' }] })
).resolves.toEqual({
Expand All @@ -195,10 +195,10 @@ describe('lib/kinesis-client', () => {

describe('isEndpointLocal', () => {
test.each`
endpoint | expected | scenario
${undefined} | ${false} | ${'no'}
${'localhost'} | ${true} | ${'a local'}
${'localstack'} | ${true} | ${'a LocalStack'}
endpoint | expected | scenario
${undefined} | ${false} | ${'no'}
${'http://localhost'} | ${true} | ${'a local'}
${'http://localstack'} | ${true} | ${'a LocalStack'}
`(
'isEndpointLocal should return $expected with $scenario endpoint',
({ endpoint, expected }) => {
Expand Down
Loading

0 comments on commit 54662a1

Please sign in to comment.