feat: add name get, set and update on Channel

This commit is contained in:
Gordon Hayes
2021-08-10 11:53:30 +02:00
parent 131019d77a
commit adfc0adea9
3 changed files with 160 additions and 28 deletions
@@ -89,6 +89,28 @@ void main() {
expect(newChannelInstance.image, newImage);
expect(newChannelInstance.extraData['image'], newImage);
});
test('should be able to get and set `name`', () {
expect(channel.extraData.isEmpty, isTrue);
expect(
channel.name,
channelId,
reason: 'if name is not set then use channel id',
);
const name = 'Channel name';
channel.name = name;
expect(channel.name, name);
expect(channel.extraData['name'], name);
const newName = 'New channel name';
final newChannelInstance =
Channel(client, channelType, channelId, name: newName);
expect(newChannelInstance.name, newName);
expect(newChannelInstance.extraData['name'], newName);
});
});
// TODO : test all persistence related logic in this group
@@ -217,6 +239,14 @@ void main() {
}
});
test('should throw if trying to set `name`', () {
try {
channel.name = 'New name';
} catch (e) {
expect(e, isA<StateError>());
}
});
group('`.sendMessage`', () {
test('should work fine', () async {
final message = Message(id: 'test-message-id');
@@ -1246,6 +1276,35 @@ void main() {
).called(1);
});
test('`.updateName`', () async {
const name = 'Name';
final channelModel = ChannelModel(
cid: channelCid,
extraData: {'name': name},
);
when(() => client.updateChannelPartial(
any(),
any(),
set: {'name': name},
)).thenAnswer(
(_) async => PartialUpdateChannelResponse()..channel = channelModel,
);
final res = await channel.updateName(name);
expect(res, isNotNull);
expect(res.channel.extraData['name'], name);
verify(
() => client.updateChannelPartial(
any(),
any(),
set: {'name': name},
),
).called(1);
});
test('`.updatePartial`', () async {
const set = {
'name': 'Stream Team',