-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Add route updateUserTopic and its compat helper
For the legacy case, there can be an error when muting a topic that is already muted or unmuting one that is already unmuted. The callers are not expected to handle such errors because they aren't really actionable. Similar to getMessageCompat, updateUserTopicCompat is expected to be dropped, eventually. Signed-off-by: Zixuan James Li <zixuan@zulip.com>
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/api/model/model.dart'; | ||
import 'package:zulip/api/route/channels.dart'; | ||
|
||
import '../../stdlib_checks.dart'; | ||
import '../fake_api.dart'; | ||
|
||
void main() { | ||
test('smoke updateUserTopic', () { | ||
return FakeApiConnection.with_((connection) async { | ||
connection.prepare(json: {}); | ||
await updateUserTopic(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.followed); | ||
check(connection.takeRequests()).single.isA<http.Request>() | ||
..method.equals('POST') | ||
..url.path.equals('/api/v1/user_topics') | ||
..bodyFields.deepEquals({ | ||
'stream_id': '1', | ||
'topic': 'topic', | ||
'visibility_policy': '3', | ||
}); | ||
}); | ||
}); | ||
|
||
test('updateUserTopic only accepts valid visibility policy', () { | ||
return FakeApiConnection.with_((connection) async { | ||
check(() => updateUserTopic(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.unknown), | ||
).throws<AssertionError>(); | ||
}); | ||
}); | ||
|
||
test('updateUserTopicCompat when FL >= 170', () { | ||
return FakeApiConnection.with_((connection) async { | ||
connection.prepare(json: {}); | ||
await updateUserTopicCompat(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.followed); | ||
check(connection.takeRequests()).single.isA<http.Request>() | ||
..method.equals('POST') | ||
..url.path.equals('/api/v1/user_topics') | ||
..bodyFields.deepEquals({ | ||
'stream_id': '1', | ||
'topic': 'topic', | ||
'visibility_policy': '3', | ||
}); | ||
}); | ||
}); | ||
|
||
group('legacy: use muteTopic when FL < 170', () { | ||
test('updateUserTopic throws AssertionError when FL < 170', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async { | ||
check(() => updateUserTopic(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.followed), | ||
).throws<AssertionError>(); | ||
}); | ||
}); | ||
|
||
test('policy: none -> op: remove', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async { | ||
connection.prepare(json: {}); | ||
await updateUserTopicCompat(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.none); | ||
check(connection.takeRequests()).single.isA<http.Request>() | ||
..method.equals('PATCH') | ||
..url.path.equals('/api/v1/users/me/subscriptions/muted_topics') | ||
..bodyFields.deepEquals({ | ||
'stream_id': '1', | ||
'topic': 'topic', | ||
'op': 'remove', | ||
}); | ||
}); | ||
}); | ||
|
||
test('policy: muted -> op: add', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async { | ||
connection.prepare(json: {}); | ||
await updateUserTopicCompat(connection, | ||
streamId: 1, topic: 'topic', | ||
visibilityPolicy: UserTopicVisibilityPolicy.muted); | ||
check(connection.takeRequests()).single.isA<http.Request>() | ||
..method.equals('PATCH') | ||
..url.path.equals('/api/v1/users/me/subscriptions/muted_topics') | ||
..bodyFields.deepEquals({ | ||
'stream_id': '1', | ||
'topic': 'topic', | ||
'op': 'add', | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |