Skip to content

Commit

Permalink
Add integration test for shutdown method
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gomez committed Mar 27, 2018
1 parent 573125c commit b57bb3b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
1 change: 0 additions & 1 deletion test/fixtures/Messages.ts
Expand Up @@ -184,7 +184,6 @@ export class InvalidMessage {}
}
})
export class UserCreatedActionMessage implements MessageInterface {

onMessage(message: RabbitMessage) {
return Observable.of({ ack: true });
}
Expand Down
61 changes: 61 additions & 0 deletions test/integration/shutdown.test.ts
@@ -0,0 +1,61 @@
import * as unit from 'unit.js';
import { test, suite } from 'mocha-typescript';

import { HapinessModule, OnStart, Hapiness } from '@hapiness/core';
import { RabbitMQExt } from '../../src/module/rabbitmq.extension';

import { RabbitMQModule } from '../../src/module';
import { RabbitConnectionService } from '../../src/module/services';
import { ConnectionManagerMock } from '../mocks/ConnectionManager';
import { Config } from '@hapiness/config';
import { MessageStore } from '../../src/module/managers';
import { ChannelMock } from '../mocks/Channel';

@suite('- Integration test of RabbitMQ Shutdown feature')
export class RabbitMQShutdownTest {
@test('- Test shutdown')
testShutdown(done) {
@HapinessModule({
version: '1.0.0',
declarations: [],
providers: [],
exports: [],
imports: [RabbitMQModule]
})
class RabbitMQModuleTest implements OnStart {
constructor(
private _connectionService: RabbitConnectionService
) {}

onStart() {
unit.object(this._connectionService).isInstanceOf(RabbitConnectionService);
unit.object(this._connectionService.connectionManager);
unit.string(this._connectionService.connectionManager.uri).is('amqp://localhost:5672');
unit.object(this._connectionService.connection);

// Add one message into the store
MessageStore.addConsumer(<any>new ChannelMock(), 'consumer-1');
MessageStore['messages'] = [];
const { uuid } = MessageStore.addMessage(<any>{});

// Get extension and call onShutdown
const extension = Hapiness['extensions'].find(ext => ext.token === RabbitMQExt);
extension.instance.onShutdown(<any>{}, extension.value).resolver.subscribe(() => done(), err => done(err));

setTimeout(() => {
MessageStore.remove(<any>{ uuid });
}, 500);
}

onError(err) {}
}

Hapiness.bootstrap(RabbitMQModuleTest, [
RabbitMQExt.setConfig({
connection: Config.get('rabbitmq')
})
]).catch(err => done(err));
}
}

RabbitMQExt.ConnectionManager = ConnectionManagerMock;

0 comments on commit b57bb3b

Please sign in to comment.