diff --git a/core/queue/test/queue_test.dart b/core/queue/test/queue_test.dart index f5e2568a..607666e0 100644 --- a/core/queue/test/queue_test.dart +++ b/core/queue/test/queue_test.dart @@ -5,6 +5,8 @@ import 'package:angel3_container/angel3_container.dart'; import 'package:angel3_event_bus/event_bus.dart'; import 'package:angel3_mq/mq.dart'; import 'package:angel3_queue/src/queue.dart'; + +import 'package:angel3_queue/src/should_queue_after_commit.dart'; //import 'package:angel3_queue/src/invalid_payload_exception.dart'; import 'queue_test.mocks.dart'; @@ -25,6 +27,10 @@ void main() { mq = MockMQClient(); queue = TestQueue(container, eventBus, mq); + // Inject the other mocks into the queue + // queue.container = container; + // queue.mq = mq; + when(container.has()).thenReturn(true); when(container.has()).thenReturn(false); when(container.make()).thenReturn(eventBus); @@ -51,6 +57,14 @@ void main() { expect(() => queue.createPayload({}, 'test_queue'), throwsA(isA())); }); + test('shouldDispatchAfterCommit returns correct value', () { + expect( + queue.shouldDispatchAfterCommit(MockShouldQueueAfterCommit()), isTrue); + expect(queue.shouldDispatchAfterCommit({}), isFalse); + + queue.dispatchAfterCommit = true; + expect(queue.shouldDispatchAfterCommit({}), isTrue); + }); } class TestQueue extends Queue { @@ -79,6 +93,14 @@ class TestQueue extends Queue { } return 'valid payload'; } + + @override + bool shouldDispatchAfterCommit(dynamic job) { + if (job is ShouldQueueAfterCommit) { + return true; + } + return dispatchAfterCommit; + } } class DummyEventBus implements EventBus { @@ -92,3 +114,5 @@ class InvalidPayloadException implements Exception { @override String toString() => 'InvalidPayloadException: $message'; } + +class MockShouldQueueAfterCommit implements ShouldQueueAfterCommit {}