Skip to content

Commit 212b3d3

Browse files
committed
api test: Test sendMessage's checking of the realm
This is mostly for the sake of starting to exercise FakeApiConnection, though this is functionality that it's probably best to have a test for in any case.
1 parent 6be6dd9 commit 212b3d3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/api/route/messages_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'dart:convert';
2+
3+
import 'package:checks/checks.dart';
4+
import 'package:test/scaffolding.dart';
5+
import 'package:zulip/api/route/messages.dart';
6+
7+
import '../fake_api.dart';
8+
import 'route_checks.dart';
9+
10+
void main() {
11+
test('sendMessage accepts fixture realm', () async {
12+
final connection = FakeApiConnection(
13+
realmUrl: 'https://chat.zulip.org/', email: '[email protected]');
14+
connection.prepare(jsonEncode(SendMessageResult(id: 42).toJson()));
15+
check(sendMessage(connection, content: 'hello', topic: 'world'))
16+
.completes(it()..id.equals(42));
17+
});
18+
19+
test('sendMessage rejects unexpected realm', () async {
20+
final connection = FakeApiConnection(
21+
realmUrl: 'https://chat.example/', email: '[email protected]');
22+
connection.prepare(jsonEncode(SendMessageResult(id: 42).toJson()));
23+
check(sendMessage(connection, content: 'hello', topic: 'world'))
24+
.throws();
25+
});
26+
}

test/api/route/route_checks.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ignore_for_file: non_constant_identifier_names
2+
3+
import 'package:checks/checks.dart';
4+
import 'package:zulip/api/route/messages.dart';
5+
6+
extension SendMessageResultChecks on Subject<SendMessageResult> {
7+
Subject<int> get id => has((e) => e.id, 'id');
8+
Subject<String?> get deliver_at => has((e) => e.deliver_at, 'deliver_at');
9+
}
10+
11+
// TODO add similar extensions for other classes in api/route/*.dart

0 commit comments

Comments
 (0)