|
| 1 | +import 'package:checks/checks.dart'; |
| 2 | +import 'package:http/http.dart' as http; |
| 3 | +import 'package:test/scaffolding.dart'; |
| 4 | +import 'package:zulip/api/route/notifications.dart'; |
| 5 | + |
| 6 | +import '../../stdlib_checks.dart'; |
| 7 | +import '../fake_api.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('registerFcmToken', () { |
| 11 | + Future<void> checkRegisterFcmToken(FakeApiConnection connection, { |
| 12 | + required String token, |
| 13 | + }) async { |
| 14 | + connection.prepare(json: {}); |
| 15 | + await registerFcmToken(connection, token: token); |
| 16 | + check(connection.lastRequest).isA<http.Request>() |
| 17 | + ..method.equals('POST') |
| 18 | + ..url.path.equals('/api/v1/users/me/android_gcm_reg_id') |
| 19 | + ..bodyFields.deepEquals({ |
| 20 | + 'token': token, |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + test('smoke', () { |
| 25 | + return FakeApiConnection.with_((connection) async { |
| 26 | + await checkRegisterFcmToken(connection, token: 'asdf'); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + group('registerApnsToken', () { |
| 32 | + Future<void> checkRegisterApnsToken(FakeApiConnection connection, { |
| 33 | + required String token, |
| 34 | + required String? appid, |
| 35 | + }) async { |
| 36 | + connection.prepare(json: {}); |
| 37 | + await registerApnsToken(connection, token: token, appid: appid); |
| 38 | + check(connection.lastRequest).isA<http.Request>() |
| 39 | + ..method.equals('POST') |
| 40 | + ..url.path.equals('/api/v1/users/me/apns_device_token') |
| 41 | + ..bodyFields.deepEquals({ |
| 42 | + 'token': token, |
| 43 | + if (appid != null) 'appid': appid, |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + test('no appid', () { |
| 48 | + return FakeApiConnection.with_((connection) async { |
| 49 | + await checkRegisterApnsToken(connection, token: 'asdf', appid: null); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + test('with appid', () { |
| 54 | + return FakeApiConnection.with_((connection) async { |
| 55 | + await checkRegisterApnsToken(connection, token: 'asdf', appid: 'qwer'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | +} |
0 commit comments