From 96984ea7da3a2b87ad378b5e4cf49cb9f0fc42c3 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Sat, 5 Oct 2024 19:43:53 -0700 Subject: [PATCH] Test: adding checkpoint for passing test --- core/queue/test/queue_test.dart | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/core/queue/test/queue_test.dart b/core/queue/test/queue_test.dart index 6e92f0b6..f5e2568a 100644 --- a/core/queue/test/queue_test.dart +++ b/core/queue/test/queue_test.dart @@ -5,6 +5,7 @@ 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/invalid_payload_exception.dart'; import 'queue_test.mocks.dart'; @GenerateMocks([Container, MQClient, TransactionManager]) @@ -15,7 +16,6 @@ void main() { late TestQueue queue; setUpAll(() { - // Provide a dummy EventBus for Mockito to use provideDummy(DummyEventBus()); }); @@ -25,7 +25,6 @@ void main() { mq = MockMQClient(); queue = TestQueue(container, eventBus, mq); - // Basic setup when(container.has()).thenReturn(true); when(container.has()).thenReturn(false); when(container.make()).thenReturn(eventBus); @@ -41,14 +40,28 @@ void main() { 'test_queue', Duration(minutes: 5), 'test_job', 'test_data'); expect(result, equals('pushed later')); }); + + test('bulk pushes multiple jobs', () async { + await queue.bulk(['job1', 'job2', 'job3'], 'test_data', 'test_queue'); + expect(queue.pushedJobs.length, equals(3)); + expect(queue.pushedJobs, containsAll(['job1', 'job2', 'job3'])); + }); + + test('createPayload throws InvalidPayloadException for invalid job', () { + expect(() => queue.createPayload({}, 'test_queue'), + throwsA(isA())); + }); } class TestQueue extends Queue { + List pushedJobs = []; + TestQueue(Container container, EventBus eventBus, MQClient mq) : super(container, eventBus, mq); @override Future push(dynamic job, [dynamic data = '', String? queue]) async { + pushedJobs.add(job); return 'pushed'; } @@ -57,9 +70,25 @@ class TestQueue extends Queue { [dynamic data = '', String? queue]) async { return 'pushed later'; } + + @override + Future createPayload(dynamic job, String queue, + [dynamic data = '']) async { + if (job is Map && job.isEmpty) { + throw InvalidPayloadException('Invalid job: empty map'); + } + return 'valid payload'; + } } class DummyEventBus implements EventBus { @override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } + +class InvalidPayloadException implements Exception { + final String message; + InvalidPayloadException(this.message); + @override + String toString() => 'InvalidPayloadException: $message'; +}