Test: adding checkpoint for passing test
This commit is contained in:
parent
5e25d7729d
commit
42596c1026
1 changed files with 79 additions and 8 deletions
|
@ -6,24 +6,26 @@ 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/job_queueing_event.dart';
|
||||
import 'package:angel3_queue/src/job_queued_event.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';
|
||||
|
||||
@GenerateMocks([Container, MQClient, TransactionManager])
|
||||
@GenerateMocks([Container, EventBus, MQClient, TransactionManager])
|
||||
void main() {
|
||||
late MockContainer container;
|
||||
late EventBus eventBus;
|
||||
late MockEventBus eventBus;
|
||||
late MockMQClient mq;
|
||||
late TestQueue queue;
|
||||
|
||||
setUpAll(() {
|
||||
provideDummy<EventBus>(DummyEventBus());
|
||||
provideDummy<EventBus>(MockEventBus());
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
container = MockContainer();
|
||||
eventBus = DummyEventBus();
|
||||
eventBus = MockEventBus();
|
||||
mq = MockMQClient();
|
||||
queue = TestQueue(container, eventBus, mq);
|
||||
|
||||
|
@ -34,6 +36,16 @@ void main() {
|
|||
when(container.has<EventBus>()).thenReturn(true);
|
||||
when(container.has<TransactionManager>()).thenReturn(false);
|
||||
when(container.make<EventBus>()).thenReturn(eventBus);
|
||||
|
||||
// Setup for EventBus mock
|
||||
when(eventBus.fire(any)).thenAnswer((_) => Future<void>.value());
|
||||
|
||||
// // Setup for MQClient mock
|
||||
// when(mq.sendMessage(
|
||||
// message: any,
|
||||
// exchangeName: any,
|
||||
// routingKey: any,
|
||||
// )).thenAnswer((_) => Future<void>.value());
|
||||
});
|
||||
|
||||
test('pushOn calls push with correct arguments', () async {
|
||||
|
@ -65,6 +77,32 @@ void main() {
|
|||
queue.dispatchAfterCommit = true;
|
||||
expect(queue.shouldDispatchAfterCommit({}), isTrue);
|
||||
});
|
||||
|
||||
test('enqueueUsing publishes message and fires events', () async {
|
||||
when(container.has<TransactionManager>()).thenReturn(false);
|
||||
|
||||
await queue.enqueueUsing(
|
||||
'test_job',
|
||||
'test_payload',
|
||||
'test_queue',
|
||||
null,
|
||||
(payload, queue, delay) async => 'job_id',
|
||||
);
|
||||
|
||||
// Verify that events were fired
|
||||
verify(eventBus.fire(any)).called(2);
|
||||
|
||||
// More specific verification
|
||||
verify(eventBus.fire(argThat(isA<JobQueueingEvent>()))).called(1);
|
||||
verify(eventBus.fire(argThat(isA<JobQueuedEvent>()))).called(1);
|
||||
|
||||
// Verify that message was sent
|
||||
verify(mq.sendMessage(
|
||||
message: argThat(isA<Message>()),
|
||||
exchangeName: '',
|
||||
routingKey: 'test_queue',
|
||||
)).called(1);
|
||||
});
|
||||
}
|
||||
|
||||
class TestQueue extends Queue {
|
||||
|
@ -101,12 +139,45 @@ class TestQueue extends Queue {
|
|||
}
|
||||
return dispatchAfterCommit;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<dynamic> enqueueUsing(
|
||||
dynamic job,
|
||||
String payload,
|
||||
String? queue,
|
||||
Duration? delay,
|
||||
Future<dynamic> Function(String, String?, Duration?) callback,
|
||||
) async {
|
||||
await raiseJobQueueingEvent(queue, job, payload, delay);
|
||||
final result = await callback(payload, queue, delay);
|
||||
await raiseJobQueuedEvent(queue, result, job, payload, delay);
|
||||
|
||||
mq.sendMessage(
|
||||
message: Message(
|
||||
id: 'test-id',
|
||||
headers: {},
|
||||
payload: payload,
|
||||
timestamp: DateTime.now().toIso8601String(),
|
||||
),
|
||||
exchangeName: '',
|
||||
routingKey: queue ?? 'default',
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class DummyEventBus implements EventBus {
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
// class DummyEventBus implements EventBus {
|
||||
// List<AppEvent> firedEvents = [];
|
||||
|
||||
// @override
|
||||
// Future<void> fire(AppEvent event) async {
|
||||
// firedEvents.add(event);
|
||||
// }
|
||||
|
||||
// @override
|
||||
// dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
// }
|
||||
|
||||
class InvalidPayloadException implements Exception {
|
||||
final String message;
|
||||
|
|
Loading…
Reference in a new issue