Skip to content

Commit

Permalink
test: increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Mar 30, 2024
1 parent 15bd959 commit e9d84e8
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 87 deletions.
87 changes: 0 additions & 87 deletions tests/tests/misc/test00002.test.ts

This file was deleted.

45 changes: 45 additions & 0 deletions tests/tests/namespace/test00001.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c)
* Weyoss <weyoss@protonmail.com>
* https://github.com/weyoss
*
* This source code is licensed under the MIT license found in the LICENSE file
* in the root directory of this source tree.
*/

import { expect, test } from '@jest/globals';
import bluebird from 'bluebird';
import {
EQueueDeliveryModel,
EQueueType,
Namespace,
NamespaceNotFoundError,
Queue,
} from '../../../src/lib/index.js';

test('Namespace', async () => {
const queue = bluebird.promisifyAll(new Queue());
await queue.saveAsync(
'myqueue',
EQueueType.FIFO_QUEUE,
EQueueDeliveryModel.POINT_TO_POINT,
);

const namespace = bluebird.promisifyAll(new Namespace());
const nsList = await namespace.getNamespacesAsync();
expect(nsList).toEqual(['testing']);

const nsQueues = await namespace.getNamespaceQueuesAsync('testing');
expect(nsQueues).toEqual([{ ns: 'testing', name: 'myqueue' }]);

await namespace.deleteAsync('testing');
const nsList1 = await namespace.getNamespacesAsync();
expect(nsList1).toEqual([]);

await expect(namespace.getNamespaceQueuesAsync('testing')).rejects.toThrow(
NamespaceNotFoundError,
);

await queue.shutdownAsync();
await namespace.shutdownAsync();
});
44 changes: 44 additions & 0 deletions tests/tests/queue-consumer-groups/test00006.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c)
* Weyoss <weyoss@protonmail.com>
* https://github.com/weyoss
*
* This source code is licensed under the MIT license found in the LICENSE file
* in the root directory of this source tree.
*/

import { expect, test } from '@jest/globals';
import bluebird from 'bluebird';
import {
Consumer,
ConsumerGroupIdNotSupportedError,
EQueueDeliveryModel,
EQueueType,
IQueueParams,
} from '../../../src/lib/index.js';
import { getQueue } from '../../common/queue.js';

test('ConsumerGroupIdNotSupportedError', async () => {
const queue1: IQueueParams = {
name: 'test-queue',
ns: 'ns1',
};

const queue = await getQueue();
await queue.saveAsync(
queue1,
EQueueType.PRIORITY_QUEUE,
EQueueDeliveryModel.POINT_TO_POINT,
);

const consumer1 = bluebird.promisifyAll(new Consumer());
await consumer1.consumeAsync(
{ queue: queue1, groupId: 'my-group-1' },
(msg, cb) => cb(),
);

await expect(consumer1.runAsync()).rejects.toThrow(
ConsumerGroupIdNotSupportedError,
);
await consumer1.shutdownAsync();
});
50 changes: 50 additions & 0 deletions tests/tests/queue-consumer-groups/test00007.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c)
* Weyoss <weyoss@protonmail.com>
* https://github.com/weyoss
*
* This source code is licensed under the MIT license found in the LICENSE file
* in the root directory of this source tree.
*/

import { expect, test } from '@jest/globals';
import bluebird from 'bluebird';
import { RedisKeysError } from '../../../src/common/redis-keys/redis-keys.error.js';
import {
Consumer,
ConsumerGroups,
EQueueDeliveryModel,
EQueueType,
IQueueParams,
} from '../../../src/lib/index.js';
import { getQueue } from '../../common/queue.js';

test('Consumer group ID validation', async () => {
const queue1: IQueueParams = {
name: 'test-queue',
ns: 'ns1',
};

const queue = await getQueue();
await queue.saveAsync(
queue1,
EQueueType.PRIORITY_QUEUE,
EQueueDeliveryModel.PUB_SUB,
);

const consumer1 = bluebird.promisifyAll(new Consumer());
await expect(
consumer1.consumeAsync(
{ queue: queue1, groupId: 'my-group-1!' },
(msg, cb) => cb(),
),
).rejects.toThrow(RedisKeysError);

const consumerGroups = bluebird.promisifyAll(new ConsumerGroups());
await expect(
consumerGroups.saveConsumerGroupAsync(queue1, 'my-group-1!'),
).rejects.toThrow(RedisKeysError);

await consumerGroups.shutdownAsync();
await consumer1.shutdownAsync();
});

0 comments on commit e9d84e8

Please sign in to comment.