-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d81baa
commit 3483af3
Showing
5 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
RABBITMQ_URL=amqp://queue | ||
RABBITMQ_URL_TEST=amqp://localhost | ||
POSTGRES_URL=database | ||
POSTGRES_PORT=5432 | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 49 additions & 1 deletion
50
server/services/core/interfaces/shared-queue/shared-queue.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,51 @@ | ||
import amqp from 'mock-amqplib'; | ||
import config from '../../config'; | ||
import {SharedQueue} from '../../@types/global'; | ||
import makeSharedQueue from './shared-queue'; | ||
|
||
describe('shared-queue', () => { | ||
it('must pass', () => {}); | ||
let sharedQueue: SharedQueue; | ||
|
||
beforeEach(async () => { | ||
sharedQueue = makeSharedQueue({ | ||
queueLibrary: amqp, | ||
queueUrl: config.rabbitMqUrlTest, | ||
}); | ||
}); | ||
|
||
it('must emit event on a single queue', async () => { | ||
const message = {message: 'i do stuff'}; | ||
const queueName = 'test_queue'; | ||
|
||
// Asserting whether emitting to a single queue was successful | ||
expect(async () => { | ||
await sharedQueue.emit([queueName], message); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('must get emitted messages when listening', async () => { | ||
const message = {message: 'i do stuff'}; | ||
const queueName = 'test_queue'; | ||
|
||
// Asserting whether emitting to a single queue was successful | ||
expect(async () => { | ||
await sharedQueue.emit([queueName], message); | ||
}).not.toThrow(); | ||
|
||
// Defining a callback function and a spy bound to it which will be used to | ||
// verify the callback was called exactly once (only 1 message in queue) | ||
let response: object; | ||
const callbackObject = { | ||
callback: (result: object) => response = result, | ||
}; | ||
const spy = jest.spyOn(callbackObject, 'callback'); | ||
|
||
// Starting to listen for messages | ||
await sharedQueue.listen( | ||
queueName, | ||
callbackObject.callback, | ||
); | ||
expect(response).toEqual(message); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |