Skip to content

Commit 325c663

Browse files
committed
api: Add remove{Apns,Fcm}Token
It's no longer true that these endpoints are undocumented, so, link to them.
1 parent ed1adbe commit 325c663

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/api/route/notifications.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import '../core.dart';
32

43
/// https://zulip.com/api/add-fcm-token
@@ -10,6 +9,15 @@ Future<void> addFcmToken(ApiConnection connection, {
109
});
1110
}
1211

12+
/// https://zulip.com/api/remove-fcm-token
13+
Future<void> removeFcmToken(ApiConnection connection, {
14+
required String token,
15+
}) {
16+
return connection.delete('removeFcmToken', (_) {}, 'users/me/android_gcm_reg_id', {
17+
'token': RawParameter(token),
18+
});
19+
}
20+
1321
/// https://zulip.com/api/add-apns-token
1422
Future<void> addApnsToken(ApiConnection connection, {
1523
required String token,
@@ -20,3 +28,12 @@ Future<void> addApnsToken(ApiConnection connection, {
2028
'appid': RawParameter(appid),
2129
});
2230
}
31+
32+
/// https://zulip.com/api/remove-apns-token
33+
Future<void> removeApnsToken(ApiConnection connection, {
34+
required String token,
35+
}) {
36+
return connection.delete('removeApnsToken', (_) {}, 'users/me/apns_device_token', {
37+
'token': RawParameter(token),
38+
});
39+
}

test/api/route/notifications_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ void main() {
2828
});
2929
});
3030

31+
group('removeFcmToken', () {
32+
Future<void> checkRemoveFcmToken(FakeApiConnection connection, {
33+
required String token,
34+
}) async {
35+
connection.prepare(json: {});
36+
await removeFcmToken(connection, token: token);
37+
check(connection.lastRequest).isA<http.Request>()
38+
..method.equals('DELETE')
39+
..url.path.equals('/api/v1/users/me/android_gcm_reg_id')
40+
..bodyFields.deepEquals({
41+
'token': token,
42+
});
43+
}
44+
45+
test('smoke', () {
46+
return FakeApiConnection.with_((connection) async {
47+
await checkRemoveFcmToken(connection, token: 'asdf');
48+
});
49+
});
50+
});
51+
3152
group('addApnsToken', () {
3253
Future<void> checkAddApnsToken(FakeApiConnection connection, {
3354
required String token,
@@ -50,4 +71,25 @@ void main() {
5071
});
5172
});
5273
});
74+
75+
group('removeApnsToken', () {
76+
Future<void> checkRemoveApnsToken(FakeApiConnection connection, {
77+
required String token,
78+
}) async {
79+
connection.prepare(json: {});
80+
await removeApnsToken(connection, token: token);
81+
check(connection.lastRequest).isA<http.Request>()
82+
..method.equals('DELETE')
83+
..url.path.equals('/api/v1/users/me/apns_device_token')
84+
..bodyFields.deepEquals({
85+
'token': token,
86+
});
87+
}
88+
89+
test('smoke', () {
90+
return FakeApiConnection.with_((connection) async {
91+
await checkRemoveApnsToken(connection, token: 'asdf');
92+
});
93+
});
94+
});
5395
}

0 commit comments

Comments
 (0)