Merge branch 'develop' of https://github.com/GetStream/stream-chat-flutter into cds-189
Conflicts: packages/stream_chat/lib/src/client/channel.dart packages/stream_chat_flutter/example/lib/main.dart packages/stream_chat_flutter/lib/src/message_list_view.dart
This commit is contained in:
@@ -72,6 +72,40 @@ void main() {
|
||||
expect(channel.extraData.containsKey('name'), isTrue);
|
||||
expect(channel.extraData['name'], 'test-channel-name');
|
||||
});
|
||||
|
||||
test('should be able to get and set `image`', () {
|
||||
expect(channel.extraData.isEmpty, isTrue);
|
||||
|
||||
const imageUrl = 'https://getstream.io/some-image';
|
||||
channel.image = imageUrl;
|
||||
|
||||
expect(channel.image, imageUrl);
|
||||
expect(channel.extraData['image'], imageUrl);
|
||||
|
||||
const newImage = 'https://getstream.io/new-image';
|
||||
final newChannelInstance =
|
||||
Channel(client, channelType, channelId, image: newImage);
|
||||
|
||||
expect(newChannelInstance.image, newImage);
|
||||
expect(newChannelInstance.extraData['image'], newImage);
|
||||
});
|
||||
|
||||
test('should be able to get and set `name`', () {
|
||||
expect(channel.extraData.isEmpty, isTrue);
|
||||
|
||||
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
|
||||
@@ -192,6 +226,22 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('should throw if trying to set `image`', () {
|
||||
try {
|
||||
channel.image = 'https://stream.io/some-image';
|
||||
} catch (e) {
|
||||
expect(e, isA<StateError>());
|
||||
}
|
||||
});
|
||||
|
||||
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');
|
||||
@@ -1192,6 +1242,62 @@ void main() {
|
||||
message: any(named: 'message'))).called(1);
|
||||
});
|
||||
|
||||
test('`.updateImage`', () async {
|
||||
const image = 'https://getstream.io/new-image';
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
extraData: {'image': image},
|
||||
);
|
||||
|
||||
when(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'image': image},
|
||||
)).thenAnswer(
|
||||
(_) async => PartialUpdateChannelResponse()..channel = channelModel,
|
||||
);
|
||||
|
||||
final res = await channel.updateImage(image);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.channel.extraData['image'], image);
|
||||
|
||||
verify(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'image': image},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('`.updateName`', () async {
|
||||
const name = 'Name';
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
extraData: {'name': name},
|
||||
);
|
||||
|
||||
when(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
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(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'name': name},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('`.updatePartial`', () async {
|
||||
const set = {
|
||||
'name': 'Stream Team',
|
||||
|
||||
@@ -176,7 +176,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('markAllRead', () async {
|
||||
const path = 'channels/read';
|
||||
const path = '/channels/read';
|
||||
when(() => client.post(path)).thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat/src/core/models/own_user.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../utils.dart';
|
||||
|
||||
class MockMute extends Mock implements Mute {}
|
||||
|
||||
class MockDevice extends Mock implements Device {}
|
||||
|
||||
void main() {
|
||||
final devices = [MockDevice(), MockDevice()];
|
||||
final mutes = [MockMute(), MockMute()];
|
||||
final channelMutes = [MockMute()];
|
||||
final createdAt = DateTime.parse('2021-05-03 12:39:21.817646');
|
||||
final updatedAt = DateTime.parse('2021-04-03 12:39:21.817646');
|
||||
final lastActive = DateTime.parse('2021-03-03 12:39:21.817646');
|
||||
|
||||
group('src/models/own_user', () {
|
||||
test('should parse json correctly', () {
|
||||
final ownUser = OwnUser.fromJson(jsonFixture('own_user.json'));
|
||||
@@ -22,6 +35,7 @@ void main() {
|
||||
expect(ownUser.channelMutes.length, 1);
|
||||
expect(ownUser.totalUnreadCount, 0);
|
||||
expect(ownUser.unreadChannels, 0);
|
||||
expect(ownUser.image, 'https://placehold.jp/150x150.png');
|
||||
expect(ownUser.extraData['image'], 'https://placehold.jp/150x150.png');
|
||||
expect(ownUser.extraData['name'], 'Proud darkness');
|
||||
expect(ownUser.extraData['username'], 'Rioland');
|
||||
@@ -40,6 +54,7 @@ void main() {
|
||||
expect(ownUser.online, user.online);
|
||||
expect(ownUser.banned, user.banned);
|
||||
expect(ownUser.extraData, user.extraData);
|
||||
expect(ownUser.image, user.image);
|
||||
});
|
||||
|
||||
test('copyWith', () {
|
||||
@@ -49,35 +64,116 @@ void main() {
|
||||
expect(newUser.id, user.id);
|
||||
expect(newUser.role, user.role);
|
||||
expect(newUser.name, user.name);
|
||||
expect(newUser.devices, user.devices);
|
||||
expect(newUser.mutes, user.mutes);
|
||||
expect(newUser.totalUnreadCount, user.totalUnreadCount);
|
||||
expect(newUser.channelMutes, user.channelMutes);
|
||||
expect(newUser.createdAt, user.createdAt);
|
||||
expect(newUser.updatedAt, user.updatedAt);
|
||||
expect(newUser.lastActive, user.lastActive);
|
||||
expect(newUser.online, user.online);
|
||||
expect(newUser.extraData, user.extraData);
|
||||
expect(newUser.banned, user.banned);
|
||||
expect(newUser.teams, user.teams);
|
||||
expect(newUser.language, user.language);
|
||||
expect(newUser.image, user.image);
|
||||
|
||||
newUser = user.copyWith(
|
||||
id: 'test',
|
||||
role: 'test',
|
||||
image: 'https://getstream.io/image-new',
|
||||
extraData: {
|
||||
'name': 'test',
|
||||
},
|
||||
devices: devices,
|
||||
mutes: mutes,
|
||||
totalUnreadCount: 10,
|
||||
unreadChannels: 5,
|
||||
channelMutes: channelMutes,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
lastActive: lastActive,
|
||||
online: true,
|
||||
banned: true,
|
||||
teams: ['team1', 'team2'],
|
||||
language: 'fr',
|
||||
);
|
||||
|
||||
expect(newUser.id, 'test');
|
||||
expect(newUser.role, 'test');
|
||||
expect(newUser.name, 'test');
|
||||
expect(newUser.image, 'https://getstream.io/image-new');
|
||||
expect(
|
||||
newUser.extraData,
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'https://getstream.io/image-new',
|
||||
},
|
||||
reason: 'Should get image from user.image',
|
||||
);
|
||||
expect(newUser.devices, devices);
|
||||
expect(newUser.mutes, mutes);
|
||||
expect(newUser.totalUnreadCount, 10);
|
||||
expect(newUser.unreadChannels, 5);
|
||||
expect(newUser.channelMutes, channelMutes);
|
||||
expect(newUser.createdAt, createdAt);
|
||||
expect(newUser.updatedAt, updatedAt);
|
||||
expect(newUser.createdAt, createdAt);
|
||||
expect(newUser.online, true);
|
||||
expect(newUser.banned, true);
|
||||
expect(newUser.teams, ['team1', 'team2']);
|
||||
expect(newUser.language, 'fr');
|
||||
});
|
||||
|
||||
test('merge', () {
|
||||
final user = OwnUser.fromJson(jsonFixture('own_user.json'));
|
||||
final newUser = user.merge(OwnUser(
|
||||
id: 'test',
|
||||
role: 'test',
|
||||
extraData: const {
|
||||
'name': 'test',
|
||||
},
|
||||
banned: true,
|
||||
));
|
||||
final newUser = user.merge(
|
||||
OwnUser(
|
||||
id: 'test',
|
||||
role: 'test',
|
||||
extraData: const {
|
||||
'name': 'test',
|
||||
},
|
||||
image: 'https://getstream.io/image-new',
|
||||
devices: devices,
|
||||
mutes: mutes,
|
||||
totalUnreadCount: 10,
|
||||
unreadChannels: 5,
|
||||
channelMutes: channelMutes,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
lastActive: lastActive,
|
||||
online: true,
|
||||
banned: true,
|
||||
teams: const ['team1', 'team2'],
|
||||
language: 'fr',
|
||||
),
|
||||
);
|
||||
|
||||
expect(newUser.id, 'test');
|
||||
expect(newUser.role, 'test');
|
||||
expect(newUser.name, 'test');
|
||||
expect(newUser.image, 'https://getstream.io/image-new');
|
||||
expect(
|
||||
newUser.extraData,
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'https://getstream.io/image-new',
|
||||
},
|
||||
reason: 'Should get image from user.image',
|
||||
);
|
||||
expect(newUser.devices, devices);
|
||||
expect(newUser.mutes, mutes);
|
||||
expect(newUser.totalUnreadCount, 10);
|
||||
expect(newUser.unreadChannels, 5);
|
||||
expect(newUser.channelMutes, channelMutes);
|
||||
expect(newUser.createdAt, createdAt);
|
||||
expect(newUser.updatedAt, updatedAt);
|
||||
expect(newUser.createdAt, createdAt);
|
||||
expect(newUser.online, true);
|
||||
expect(newUser.banned, true);
|
||||
expect(newUser.teams, ['team1', 'team2']);
|
||||
expect(newUser.language, 'fr');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ void main() {
|
||||
expect(reaction.type, 'wow');
|
||||
expect(
|
||||
reaction.user?.toJson(),
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}).toJson(),
|
||||
User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
).toJson(),
|
||||
);
|
||||
expect(reaction.score, 1);
|
||||
expect(reaction.userId, '2de0297c-f3f2-489d-b930-ef77342edccf');
|
||||
@@ -28,11 +29,11 @@ void main() {
|
||||
messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04',
|
||||
createdAt: DateTime.parse('2020-01-28T22:17:31.108742Z'),
|
||||
type: 'wow',
|
||||
user:
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}),
|
||||
user: User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
),
|
||||
userId: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
extraData: {'bananas': 'yes'},
|
||||
score: 1,
|
||||
@@ -58,10 +59,11 @@ void main() {
|
||||
expect(newReaction.type, 'wow');
|
||||
expect(
|
||||
newReaction.user?.toJson(),
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan',
|
||||
}).toJson(),
|
||||
User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
).toJson(),
|
||||
);
|
||||
expect(newReaction.score, 1);
|
||||
expect(newReaction.userId, '2de0297c-f3f2-489d-b930-ef77342edccf');
|
||||
|
||||
@@ -4,21 +4,73 @@ import 'package:test/test.dart';
|
||||
import '../../utils.dart';
|
||||
|
||||
void main() {
|
||||
const id = 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e';
|
||||
const role = 'test-role';
|
||||
const name = 'John';
|
||||
const image =
|
||||
'https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow';
|
||||
const extraDataStringTest = 'Extra data test';
|
||||
const extraDataIntTest = 1;
|
||||
const extraDataDoubleTest = 1.1;
|
||||
const extraDataBoolTest = true;
|
||||
const online = true;
|
||||
const banned = true;
|
||||
const teams = ['team-1', 'team-2'];
|
||||
const createdAtString = '2021-08-03 12:39:21.817646';
|
||||
const updatedAtString = '2021-08-04 12:39:21.817646';
|
||||
const lastActiveString = '2021-08-05 12:39:21.817646';
|
||||
|
||||
group('src/models/user', () {
|
||||
test('should parse json correctly', () {
|
||||
final user = User.fromJson(jsonFixture('user.json'));
|
||||
expect(user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
|
||||
expect(user.name, 'John');
|
||||
expect(user.id, id);
|
||||
expect(user.role, role);
|
||||
expect(user.name, name);
|
||||
expect(user.image, image);
|
||||
expect(user.extraData['image'], image);
|
||||
expect(user.extraData['extraDataStringTest'], extraDataStringTest);
|
||||
expect(user.extraData['extraDataIntTest'], extraDataIntTest);
|
||||
expect(user.extraData['extraDataDoubleTest'], extraDataDoubleTest);
|
||||
expect(user.extraData['extraDataBoolTest'], extraDataBoolTest);
|
||||
expect(user.online, online);
|
||||
expect(user.banned, banned);
|
||||
expect(user.teams, teams);
|
||||
expect(user.createdAt, DateTime.parse(createdAtString));
|
||||
expect(user.updatedAt, DateTime.parse(updatedAtString));
|
||||
expect(user.lastActive, DateTime.parse(lastActiveString));
|
||||
expect(user.language, 'en');
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
final user = User(
|
||||
id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
|
||||
role: 'abc',
|
||||
id: id,
|
||||
role: role,
|
||||
name: name,
|
||||
image: image,
|
||||
extraData: const {
|
||||
'extraDataStringTest': extraDataStringTest,
|
||||
'extraDataIntTest': extraDataIntTest,
|
||||
'extraDataDoubleTest': extraDataDoubleTest,
|
||||
'extraDataBoolTest': extraDataBoolTest,
|
||||
},
|
||||
createdAt: DateTime.parse(createdAtString),
|
||||
updatedAt: DateTime.parse(updatedAtString),
|
||||
lastActive: DateTime.parse(lastActiveString),
|
||||
banned: online,
|
||||
online: banned,
|
||||
teams: const ['team-1', 'team-2'],
|
||||
language: 'fr',
|
||||
);
|
||||
|
||||
expect(user.toJson(), {
|
||||
'id': 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e',
|
||||
'id': id,
|
||||
'name': name,
|
||||
'image': image,
|
||||
'extraDataStringTest': extraDataStringTest,
|
||||
'extraDataIntTest': extraDataIntTest,
|
||||
'extraDataDoubleTest': extraDataDoubleTest,
|
||||
'extraDataBoolTest': extraDataBoolTest,
|
||||
'language': 'fr',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,18 +81,141 @@ void main() {
|
||||
expect(newUser.id, user.id);
|
||||
expect(newUser.role, user.role);
|
||||
expect(newUser.name, user.name);
|
||||
expect(newUser.image, user.image);
|
||||
expect(newUser.online, user.online);
|
||||
expect(newUser.banned, user.banned);
|
||||
expect(newUser.teams, user.teams);
|
||||
expect(newUser.createdAt, user.createdAt);
|
||||
expect(newUser.updatedAt, user.updatedAt);
|
||||
expect(newUser.lastActive, user.lastActive);
|
||||
expect(newUser.language, user.language);
|
||||
|
||||
newUser = user.copyWith(
|
||||
id: 'test',
|
||||
role: 'test',
|
||||
extraData: {
|
||||
'name': 'test',
|
||||
},
|
||||
name: 'test',
|
||||
image: 'https://stream.io/new-image',
|
||||
online: false,
|
||||
banned: false,
|
||||
teams: ['new-team1', 'new-team2'],
|
||||
createdAt: DateTime.parse('2021-05-03 12:39:21.817646'),
|
||||
updatedAt: DateTime.parse('2021-05-04 12:39:21.817646'),
|
||||
lastActive: DateTime.parse('2021-05-06 12:39:21.817646'),
|
||||
language: 'it',
|
||||
);
|
||||
|
||||
expect(newUser.id, 'test');
|
||||
expect(newUser.role, 'test');
|
||||
expect(newUser.name, 'test');
|
||||
expect(newUser.image, 'https://stream.io/new-image');
|
||||
expect(newUser.extraData['image'], 'https://stream.io/new-image');
|
||||
expect(newUser.online, false);
|
||||
expect(newUser.banned, false);
|
||||
expect(newUser.teams, ['new-team1', 'new-team2']);
|
||||
expect(newUser.createdAt, DateTime.parse('2021-05-03 12:39:21.817646'));
|
||||
expect(newUser.updatedAt, DateTime.parse('2021-05-04 12:39:21.817646'));
|
||||
expect(newUser.lastActive, DateTime.parse('2021-05-06 12:39:21.817646'));
|
||||
expect(newUser.language, 'it');
|
||||
});
|
||||
|
||||
test('name property and extraData manipulation', () {
|
||||
final user = User(id: id, name: name);
|
||||
|
||||
expect(user.name, name);
|
||||
expect(user.extraData['name'], name);
|
||||
expect(user.toJson(), {'id': id, 'name': name});
|
||||
expect(User.fromJson(user.toJson()).toJson(), {'id': id, 'name': name});
|
||||
|
||||
const nameOne = 'Name One';
|
||||
var newUser = user.copyWith(
|
||||
extraData: {'name': nameOne},
|
||||
);
|
||||
|
||||
expect(newUser.extraData['name'], nameOne);
|
||||
expect(newUser.name, nameOne);
|
||||
|
||||
const nameTwo = 'Name Two';
|
||||
newUser = user.copyWith(
|
||||
name: nameTwo,
|
||||
);
|
||||
|
||||
expect(newUser.extraData['name'], nameTwo);
|
||||
expect(newUser.name, nameTwo);
|
||||
|
||||
const nameThree = 'Name Three';
|
||||
newUser = user.copyWith(
|
||||
name: nameThree,
|
||||
extraData: {'name': nameThree},
|
||||
);
|
||||
|
||||
expect(newUser.extraData['name'], nameThree);
|
||||
expect(newUser.name, nameThree);
|
||||
});
|
||||
|
||||
test('image property and extraData manipulation', () {
|
||||
final user = User(id: id, image: image);
|
||||
|
||||
expect(user.image, image);
|
||||
expect(user.extraData['image'], image);
|
||||
expect(user.toJson(), {'id': id, 'image': image});
|
||||
expect(User.fromJson(user.toJson()).toJson(), {'id': id, 'image': image});
|
||||
|
||||
const imageURLOne = 'https://stream.io/image-one';
|
||||
var newUser = user.copyWith(
|
||||
extraData: {'image': imageURLOne},
|
||||
);
|
||||
|
||||
expect(newUser.extraData['image'], imageURLOne);
|
||||
expect(newUser.image, imageURLOne);
|
||||
|
||||
const imageURLTwo = 'https://stream.io/image-two';
|
||||
newUser = user.copyWith(
|
||||
image: imageURLTwo,
|
||||
);
|
||||
|
||||
expect(newUser.extraData['image'], imageURLTwo);
|
||||
expect(newUser.image, imageURLTwo);
|
||||
|
||||
const imageURLThree = 'https://stream.io/image-three';
|
||||
newUser = user.copyWith(
|
||||
image: imageURLThree,
|
||||
extraData: {'image': imageURLThree},
|
||||
);
|
||||
|
||||
expect(newUser.extraData['image'], imageURLThree);
|
||||
expect(newUser.image, imageURLThree);
|
||||
});
|
||||
|
||||
test('default values, constructor', () {
|
||||
final user = User(id: id);
|
||||
|
||||
expect(user.id, id);
|
||||
expect(user.role, null);
|
||||
expect(user.name, id, reason: 'if a name is not supplied, default to id');
|
||||
expect(user.image, null);
|
||||
expect(user.extraData, const {});
|
||||
expect(user.online, false);
|
||||
expect(user.banned, false);
|
||||
expect(user.teams, []);
|
||||
expect(user.lastActive, null);
|
||||
expect(user.createdAt, isNotNull);
|
||||
expect(user.updatedAt, isNotNull);
|
||||
});
|
||||
|
||||
test('default values, parse json', () {
|
||||
final user = User.fromJson(const {'id': id});
|
||||
|
||||
expect(user.id, id);
|
||||
expect(user.role, null);
|
||||
expect(user.name, id, reason: 'if a name is not supplied, default to id');
|
||||
expect(user.image, null);
|
||||
expect(user.extraData, const {});
|
||||
expect(user.online, false);
|
||||
expect(user.banned, false);
|
||||
expect(user.teams, []);
|
||||
expect(user.lastActive, null);
|
||||
expect(user.createdAt, isNotNull);
|
||||
expect(user.updatedAt, isNotNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user