rename package folders

This commit is contained in:
Salvatore Giordano
2021-02-01 15:45:58 +01:00
parent 6682ad5e8b
commit 964a428f2e
445 changed files with 1 additions and 343 deletions
@@ -0,0 +1,46 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/action.dart';
void main() {
group('src/models/action', () {
const jsonExample = r'''{
"name": "name",
"style": "style",
"text": "text",
"type": "type",
"value": "value"
}''';
test('should parse json correctly', () {
final action = Action.fromJson(json.decode(jsonExample));
expect(action.name, 'name');
expect(action.style, 'style');
expect(action.text, 'text');
expect(action.type, 'type');
expect(action.value, 'value');
});
test('should serialize to json correctly', () {
final action = Action(
name: 'name',
style: 'style',
text: 'text',
type: 'type',
value: 'value',
);
expect(
action.toJson(),
{
'name': 'name',
'style': 'style',
'text': 'text',
'type': 'type',
'value': 'value',
},
);
});
});
}
@@ -0,0 +1,69 @@
import 'package:stream_chat/src/models/attachment.dart';
import 'package:stream_chat/src/models/action.dart';
import 'dart:convert';
import 'package:test/test.dart';
void main() {
group('src/models/attachment', () {
const jsonExample = r'''{
"type": "giphy",
"title": "awesome",
"title_link": "https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti",
"thumb_url": "https://media0.giphy.com/media/3o7TKnCdBx5cMg0qti/giphy.gif",
"actions": [
{
"name": "image_action",
"text": "Send",
"style": "primary",
"type": "button",
"value": "send"
},
{
"name": "image_action",
"text": "Shuffle",
"style": "default",
"type": "button",
"value": "shuffle"
},
{
"name": "image_action",
"text": "Cancel",
"style": "default",
"type": "button",
"value": "cancel"
}
]
}''';
test('should parse json correctly', () {
final attachment = Attachment.fromJson(json.decode(jsonExample));
expect(attachment.type, "giphy");
expect(attachment.title, "awesome");
expect(attachment.titleLink,
"https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti");
expect(attachment.thumbUrl,
"https://media0.giphy.com/media/3o7TKnCdBx5cMg0qti/giphy.gif");
expect(attachment.actions, hasLength(3));
expect(attachment.actions[0], isA<Action>());
});
test('should serialize to json correctly', () {
final channel = Attachment(
type: "image",
title: "soo",
titleLink:
"https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti");
expect(
channel.toJson(),
{
'type': 'image',
'title': 'soo',
'title_link':
'https://giphy.com/gifs/nrkp3-dance-happy-3o7TKnCdBx5cMg0qti'
},
);
});
});
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,56 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/channel_model.dart';
void main() {
group('src/models/channel', () {
const jsonExample = '''
{
"id": "test",
"type": "livestream",
"cid": "test:livestream",
"cats": true,
"fruit": ["bananas", "apples"]
}
''';
test('should parse json correctly', () {
final channel = ChannelModel.fromJson(json.decode(jsonExample));
expect(channel.id, equals("test"));
expect(channel.type, equals("livestream"));
expect(channel.cid, equals("test:livestream"));
expect(channel.extraData["cats"], equals(true));
expect(channel.extraData["fruit"], equals(["bananas", "apples"]));
});
test('should serialize to json correctly', () {
final channel = ChannelModel(
type: "type",
id: "id",
cid: "a:a",
extraData: {"name": "cool"},
);
expect(
channel.toJson(),
{'id': 'id', 'type': 'type', 'name': 'cool'},
);
});
test('should serialize to json correctly when frozen is provided', () {
final channel = ChannelModel(
type: "type",
id: "id",
cid: "a:a",
extraData: {"name": "cool"},
frozen: false,
);
expect(
channel.toJson(),
{'id': 'id', 'type': 'type', 'name': 'cool', 'frozen': false},
);
});
});
}
@@ -0,0 +1,40 @@
import 'package:stream_chat/src/models/command.dart';
import 'dart:convert';
import 'package:test/test.dart';
void main() {
group('src/models/command', () {
const jsonExample = '''
{
"name": "giphy",
"description": "Post a random gif to the channel",
"args": "[text]"
}
''';
test('should parse json correctly', () {
final command = Command.fromJson(json.decode(jsonExample));
expect(command.name, 'giphy');
expect(command.description, 'Post a random gif to the channel');
expect(command.args, '[text]');
});
test('should serialize to json correctly', () {
final command = Command(
name: 'giphy',
description: 'Post a random gif to the channel',
args: '[text]',
);
expect(
command.toJson(),
{
"name": "giphy",
"description": "Post a random gif to the channel",
"args": "[text]",
},
);
});
});
}
@@ -0,0 +1,31 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/device.dart';
void main() {
group('src/models/device', () {
const jsonExample = r'''{
"id": "device-id",
"push_provider": "push-provider"
}''';
test('should parse json correctly', () {
final device = Device.fromJson(json.decode(jsonExample));
expect(device.id, 'device-id');
expect(device.pushProvider, 'push-provider');
});
test('should serialize to json correctly', () {
final device = Device(id: 'device-id', pushProvider: 'push-provider');
expect(
device.toJson(),
{
'id': 'device-id',
'push_provider': 'push-provider',
},
);
});
});
}
@@ -0,0 +1,89 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/event.dart';
import 'package:stream_chat/src/models/own_user.dart';
import 'package:stream_chat/stream_chat.dart';
void main() {
group('src/models/event', () {
const jsonExample = '''
{
"type": "type",
"cid": "cid",
"connection_id": "connectionId",
"created_at": "2019-04-03T18:43:33.213374Z",
"me": {
"id": "dry-meadow-0",
"role": "user",
"created_at": "2019-03-27T17:40:17.155892Z",
"updated_at": "2020-01-29T03:22:47.641589Z",
"last_active": "2020-01-29T03:22:47.63613Z",
"banned": false,
"online": false,
"image": "https://getstream.io/random_svg/?name=Dry+meadow",
"name": "Dry meadow"
},
"parent_id": null,
"user": {
"id": "dry-meadow-0",
"role": "user",
"created_at": "2019-03-27T17:40:17.155892Z",
"updated_at": "2020-01-29T03:22:47.641589Z",
"last_active": "2020-01-29T03:22:47.63613Z",
"banned": false,
"online": false,
"image": "https://getstream.io/random_svg/?name=Dry+meadow",
"name": "Dry meadow"
}
}
''';
test('should parse json correctly', () {
final event = Event.fromJson(json.decode(jsonExample));
expect(event.type, 'type');
expect(event.cid, 'cid');
expect(event.connectionId, 'connectionId');
expect(event.createdAt, isA<DateTime>());
expect(event.me, isA<OwnUser>());
expect(event.user, isA<User>());
});
test('should serialize to json correctly', () {
final event = Event(
user: User(id: 'id'),
type: 'type',
cid: 'cid',
connectionId: 'connectionId',
createdAt: DateTime.parse("2020-01-29T03:22:47.63613Z"),
me: OwnUser(id: 'id2'),
totalUnreadCount: 1,
unreadChannels: 1,
online: true,
);
expect(
event.toJson(),
{
'type': 'type',
'cid': 'cid',
'connection_id': 'connectionId',
'created_at': '2020-01-29T03:22:47.636130Z',
'me': {'id': 'id2'},
'user': {'id': 'id'},
'reaction': null,
'message': null,
'channel': null,
'total_unread_count': 1,
'unread_channels': 1,
'online': true,
'is_local': true,
'member': null,
'channel_id': null,
'channel_type': null,
'parent_id': null,
},
);
});
});
}
@@ -0,0 +1,35 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/member.dart';
import 'package:stream_chat/src/models/user.dart';
void main() {
group('src/models/member', () {
const jsonExample = '''
{
"user": {
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
"role": "user",
"created_at": "2020-01-28T22:17:30.826259Z",
"updated_at": "2020-01-28T22:17:31.101222Z",
"banned": false,
"online": false,
"name": "Robin Papa",
"image": "https://pbs.twimg.com/profile_images/669512187778498560/L7wQctBt.jpg"
},
"role": "member",
"created_at": "2020-01-28T22:17:30.95443Z",
"updated_at": "2020-01-28T22:17:30.95443Z"
}
''';
test('should parse json correctly', () {
final member = Member.fromJson(json.decode(jsonExample));
expect(member.user, isA<User>());
expect(member.role, 'member');
expect(member.createdAt, DateTime.parse("2020-01-28T22:17:30.95443Z"));
expect(member.updatedAt, DateTime.parse("2020-01-28T22:17:30.95443Z"));
});
});
}
@@ -0,0 +1,153 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/attachment.dart';
import 'package:stream_chat/src/models/message.dart';
import 'package:stream_chat/src/models/reaction.dart';
import 'package:stream_chat/src/models/user.dart';
void main() {
group('src/models/message', () {
const jsonExample = r'''{
"id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
"text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
"type": "regular",
"silent": false,
"status": "SENT",
"user": {
"id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680",
"role": "user",
"created_at": "2020-01-28T22:17:30.83015Z",
"updated_at": "2020-01-28T22:17:31.19435Z",
"banned": false,
"online": false,
"image": "https://randomuser.me/api/portraits/women/2.jpg",
"name": "Mia Denys"
},
"attachments": [
{
"type": "video",
"author_name": "GIPHY",
"title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY",
"title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"text": "Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.",
"image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4",
"og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA"
}
],
"latest_reactions": [
{
"message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
"user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680",
"user": {
"id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680",
"role": "user",
"created_at": "2020-01-28T22:17:30.83015Z",
"updated_at": "2020-01-28T22:17:31.19435Z",
"banned": false,
"online": false,
"image": "https://randomuser.me/api/portraits/women/2.jpg",
"name": "Mia Denys"
},
"type": "love",
"score": 1,
"created_at": "2020-01-28T22:17:31.128376Z",
"updated_at": "2020-01-28T22:17:31.128376Z"
}
],
"own_reactions": [],
"reaction_counts": {
"love": 1
},
"reaction_scores": {
"love": 1
},
"reply_count": 0,
"created_at": "2020-01-28T22:17:31.107978Z",
"updated_at": "2020-01-28T22:17:31.130506Z",
"mentioned_users": []
}''';
test('should parse json correctly', () {
final message = Message.fromJson(json.decode(jsonExample));
expect(message.id, "4637f7e4-a06b-42db-ba5a-8d8270dd926f");
expect(message.text,
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA");
expect(message.type, "regular");
expect(message.user, isA<User>());
expect(message.silent, isA<bool>());
expect(message.attachments, isA<List<Attachment>>());
expect(message.latestReactions, isA<List<Reaction>>());
expect(message.ownReactions, isA<List<Reaction>>());
expect(message.reactionCounts, {'love': 1});
expect(message.reactionScores, {'love': 1});
expect(message.createdAt, DateTime.parse("2020-01-28T22:17:31.107978Z"));
expect(message.updatedAt, DateTime.parse("2020-01-28T22:17:31.130506Z"));
expect(message.mentionedUsers, isA<List<User>>());
});
test('should serialize to json correctly', () {
final message = Message(
id: "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
text:
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
silent: false,
attachments: [
Attachment.fromJson({
"type": "video",
"author_name": "GIPHY",
"title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY",
"title_link":
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"text":
"Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.",
"image_url":
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"thumb_url":
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"asset_url":
"https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4",
"og_scrape_url":
"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA"
})
],
showInChannel: true,
parentId: 'parentId',
extraData: {'hey': 'test'},
status: MessageSendingStatus.sent,
);
expect(
message.toJson(),
json.decode(r'''
{
"id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f",
"text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
"silent": false,
"attachments": [
{
"type": "video",
"title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"title": "The Lion King Disney GIF - Find & Share on GIPHY",
"thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"text": "Discover & share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.",
"og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA",
"image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif",
"author_name": "GIPHY",
"asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4"
}
],
"mentioned_users": null,
"parent_id": "parentId",
"quoted_message": null,
"quoted_message_id": null,
"show_in_channel": true,
"hey": "test"
}
'''),
);
});
});
}
@@ -0,0 +1,72 @@
import 'package:test/test.dart';
import 'package:stream_chat/src/models/reaction.dart';
import 'dart:convert';
import 'package:stream_chat/src/models/user.dart';
void main() {
group('src/models/reaction', () {
const jsonExample = '''
{
"message_id": "76cd8c82-b557-4e48-9d12-87995d3a0e04",
"user_id": "2de0297c-f3f2-489d-b930-ef77342edccf",
"user": {
"id": "2de0297c-f3f2-489d-b930-ef77342edccf",
"role": "user",
"created_at": "2020-01-28T22:17:30.810011Z",
"updated_at": "2020-01-28T22:17:31.077195Z",
"banned": false,
"online": false,
"image": "https://randomuser.me/api/portraits/women/45.jpg",
"name": "Daisy Morgan"
},
"type": "wow",
"score": 1,
"created_at": "2020-01-28T22:17:31.108742Z",
"updated_at": "2020-01-28T22:17:31.108742Z"
}
''';
test('should parse json correctly', () {
final reaction = Reaction.fromJson(json.decode(jsonExample));
expect(reaction.messageId, '76cd8c82-b557-4e48-9d12-87995d3a0e04');
expect(reaction.createdAt, DateTime.parse("2020-01-28T22:17:31.108742Z"));
expect(reaction.type, 'wow');
expect(
reaction.user.toJson(),
User.init("2de0297c-f3f2-489d-b930-ef77342edccf", extraData: {
"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');
expect(reaction.extraData, {'updated_at': '2020-01-28T22:17:31.108742Z'});
});
test('should serialize to json correctly', () {
final reaction = Reaction(
messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04',
createdAt: DateTime.parse("2020-01-28T22:17:31.108742Z"),
type: 'wow',
user: User.init("2de0297c-f3f2-489d-b930-ef77342edccf", extraData: {
"image": "https://randomuser.me/api/portraits/women/45.jpg",
"name": "Daisy Morgan"
}),
userId: "2de0297c-f3f2-489d-b930-ef77342edccf",
extraData: {'bananas': 'yes'},
score: 1,
);
expect(
reaction.toJson(),
{
"message_id": "76cd8c82-b557-4e48-9d12-87995d3a0e04",
"type": "wow",
"score": 1,
"bananas": 'yes',
},
);
});
});
}
@@ -0,0 +1,40 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/read.dart';
import 'package:stream_chat/src/models/user.dart';
void main() {
group('src/models/read', () {
const jsonExample = '''
{
"user": {
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e"
},
"last_read": "2020-01-28T22:17:30.966485504Z",
"unread_messages": 10
}
''';
test('should parse json correctly', () {
final read = Read.fromJson(json.decode(jsonExample));
expect(read.lastRead, DateTime.parse('2020-01-28T22:17:30.966485504Z'));
expect(read.user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
expect(read.unreadMessages, 10);
});
test('should serialize to json correctly', () {
final read = Read(
lastRead: DateTime.parse('2020-01-28T22:17:30.966485504Z'),
user: User.init('bbb19d9a-ee50-45bc-84e5-0584e79d0c9e'),
unreadMessages: 10,
);
expect(read.toJson(), {
"user": {"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e"},
"last_read": "2020-01-28T22:17:30.966485Z",
'unread_messages': 10,
});
});
});
}
@@ -0,0 +1,60 @@
import 'package:test/test.dart';
import 'package:stream_chat/src/models/serialization.dart';
void main() {
group('src/models/serialization', () {
test('should move unknown keys from root to dedicate property', () {
final json = {
'prop1': 'test',
'prop2': 123,
'prop3': true,
};
final result = Serialization.moveToExtraDataFromRoot(json, [
'prop1',
'prop2',
]);
expect(result, {
'prop1': 'test',
'prop2': 123,
'extra_data': {
'prop3': true,
},
});
expect(json, {
'prop1': 'test',
'prop2': 123,
'prop3': true,
});
});
test('should have empty extraData', () {
final result = Serialization.moveToExtraDataFromRoot({
'prop1': 'test',
'prop2': 123,
'prop3': true,
}, [
'prop1',
'prop2',
'prop3'
]);
expect(result, {
'prop1': 'test',
'prop2': 123,
'prop3': true,
'extra_data': {},
});
});
test('should return null', () {
final result = Serialization.moveToExtraDataFromRoot(null, [
'prop1',
'prop2',
]);
expect(result, null);
});
});
}
@@ -0,0 +1,28 @@
import 'dart:convert';
import 'package:test/test.dart';
import 'package:stream_chat/src/models/user.dart';
void main() {
group('src/models/user', () {
const jsonExample = '''
{
"id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e"
}
''';
test('should parse json correctly', () {
final user = User.fromJson(json.decode(jsonExample));
expect(user.id, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e');
});
test('should serialize to json correctly', () {
final user =
User(id: 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e', role: "abc");
expect(user.toJson(), {
'id': "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e",
});
});
});
}