Tests using rest version of nyxx. Restructure tests

This commit is contained in:
Szymon Uglis 2021-03-09 00:30:46 +01:00
parent a33d651d01
commit 0bc1e37e27
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
3 changed files with 106 additions and 20 deletions

View file

@ -17,7 +17,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, User> createCacheableUser(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_UserCacheable(client, id);
/// Retrieves a cached Guild.
@ -28,7 +28,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, Guild> createCacheableGuild(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_GuildCacheable(client, id);
/// Retrieves a cached Role.
@ -40,7 +40,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, Role> createCacheableRole(
Nyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
INyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
_RoleCacheable(client, id, guild);
/// Retrieves a cached IChannel. Can be cast.
@ -51,7 +51,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, IChannel> createCacheableChannel(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_ChannelCacheable(client, id);
/// Retrieves a cached TextChannel.
@ -62,7 +62,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, TextChannel> createCacheableTextChannel(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_ChannelCacheable(client, id);
/// Retrieves a cached VoiceChannel.
@ -73,7 +73,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, VoiceGuildChannel> createCacheableVoiceChannel(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_ChannelCacheable(client, id);
/// Retrieves a cached DMChannel.
@ -84,7 +84,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, DMChannel> createCacheableDMChannel(
Nyxx client, Snowflake id) =>
INyxx client, Snowflake id) =>
_ChannelCacheable(client, id);
/// Retrieves a cached Guild Member.
@ -96,7 +96,7 @@ class CacheUtility {
/// }
/// ```
static Cacheable<Snowflake, Member> createCacheableMember(
Nyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
INyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
_MemberCacheable(client, id, guild);
/// Retrieves a cached Guild Message.
@ -107,7 +107,7 @@ class CacheUtility {
/// Cacheable<Snowflake, Member> cachedMember = CacheUtility.createCacheableMessage(bot, Snowflake(''), cachedChannel);
/// }
/// ```
static Cacheable<Snowflake, Message> createCacheableMessage(Nyxx client,
static Cacheable<Snowflake, Message> createCacheableMessage(INyxx client,
Snowflake id, Cacheable<Snowflake, TextChannel> channel) =>
_MessageCacheable(client, id, channel);
}

View file

@ -18,7 +18,7 @@ class EntityUtility {
/// User user = EntityUtility.createUser(bot, rawJson);
/// }
/// ```
static User createUser(Nyxx client, Map<String, dynamic> rawJson) =>
static User createUser(INyxx client, Map<String, dynamic> rawJson) =>
User._new(client, rawJson);
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
@ -29,7 +29,7 @@ class EntityUtility {
/// Guild guild = EntityUtility.createGuild(bot, rawJson);
/// }
/// ```
static Guild createGuild(Nyxx client, Map<String, dynamic> rawJson) =>
static Guild createGuild(INyxx client, Map<String, dynamic> rawJson) =>
Guild._new(client, rawJson);
/// Creates a Role object, can be used for other classes where you have correct rawJson data from the API.
@ -41,7 +41,7 @@ class EntityUtility {
/// }
/// ```
static Role createRole(
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
INyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
Role._new(client, rawJson, guildId);
/// Creates a CategoryGuildChannel object, can be used for other classes where you have correct rawJson data from the API.
@ -53,7 +53,7 @@ class EntityUtility {
/// }
/// ```
static CategoryGuildChannel createCategoryGuildChannel(
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
INyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
CategoryGuildChannel._new(client, rawJson, guildId);
/// Creates a VoiceGuildChannel object, can be used for other classes where you have correct rawJson data from the API.
@ -65,7 +65,7 @@ class EntityUtility {
/// }
/// ```
static VoiceGuildChannel createVoiceGuildChannel(
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
INyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
VoiceGuildChannel._new(client, rawJson, guildId);
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
@ -77,7 +77,7 @@ class EntityUtility {
/// }
/// ```
static TextGuildChannel createTextGuildChannel(
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
INyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
TextGuildChannel._new(client, rawJson, guildId);
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
@ -88,7 +88,7 @@ class EntityUtility {
/// DMChannel dmChannel = EntityUtility.createDMChannel(bot, rawJson);
/// }
/// ```
static DMChannel createDMChannel(Nyxx client, Map<String, dynamic> rawJson) =>
static DMChannel createDMChannel(INyxx client, Map<String, dynamic> rawJson) =>
DMChannel._new(client, rawJson);
/// Creates a Guild Member object, can be used for other classes where you have correct rawJson data from the API.
@ -100,6 +100,6 @@ class EntityUtility {
/// }
/// ```
static Member createGuildMember(
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
INyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
Member._new(client, rawJson, guildId);
}

View file

@ -7,10 +7,36 @@ import "package:test/test.dart";
const snowflakeAYear = 2017;
const snowflakeBYear = 2018;
void main() {
final snowflakeA = Snowflake.fromDateTime(DateTime.utc(snowflakeAYear));
final snowflakeB = Snowflake.fromDateTime(DateTime.utc(snowflakeBYear));
final snowflakeA = Snowflake.fromDateTime(DateTime.utc(snowflakeAYear));
final snowflakeB = Snowflake.fromDateTime(DateTime.utc(snowflakeBYear));
final sampleUserRawData = {
"id": 123,
"username": "Test test",
"discriminator": "123",
"avatar": null,
"bot": false,
"system": false,
"public_flags": 1 << 0 // Discord employee
};
final sampleMemberData = {
"user": {
"id": 123
},
"nick": "This is nick",
"deaf": false,
"mute": false,
"roles": [
"1234564"
"1234563"
],
"joined_at": DateTime.now().toIso8601String()
};
final client = NyxxRest("dum", 0);
void main() {
group("Snowflake tests", () {
test("Snowflakes should have correct date", () {
expect(snowflakeA.timestamp.year, snowflakeAYear);
@ -102,4 +128,64 @@ void main() {
expect(PermissionsUtils.isApplied(permissionInt, 0x10), false);
});
});
group("Cache utils", () {
test("Cacheable User", () {
final cacheable = CacheUtility.createCacheableUser(client, 123.toSnowflake());
expect(123.toSnowflake(), cacheable.id);
});
test("Cacheable Guild", () {
final cacheable = CacheUtility.createCacheableGuild(client, 123.toSnowflake());
expect(123.toSnowflake(), cacheable.id);
});
test("Cacheable Role", () {
final cacheableGuild = CacheUtility.createCacheableGuild(client, 123.toSnowflake());
final cacheable = CacheUtility.createCacheableRole(client, 123.toSnowflake(), cacheableGuild);
expect(123.toSnowflake(), cacheable.id);
expect(123.toSnowflake(), cacheableGuild.id);
});
test("Cacheable Channel", () {
final cacheable = CacheUtility.createCacheableChannel(client, 123.toSnowflake());
expect(123.toSnowflake(), cacheable.id);
});
test("Cacheable Member", () {
final cacheableGuild = CacheUtility.createCacheableGuild(client, 123.toSnowflake());
final cacheable = CacheUtility.createCacheableMember(client, 123.toSnowflake(), cacheableGuild);
expect(123.toSnowflake(), cacheable.id);
expect(123.toSnowflake(), cacheableGuild.id);
});
test("Cacheable Message", () {
final cacheableChannel = CacheUtility.createCacheableTextChannel(client, 123.toSnowflake());
final cacheable = CacheUtility.createCacheableMessage(client, 123.toSnowflake(), cacheableChannel);
expect(123.toSnowflake(), cacheable.id);
expect(123.toSnowflake(), cacheableChannel.id);
});
});
group("Entity utils", () {
test("Create user object", () {
final user = EntityUtility.createUser(client, sampleUserRawData);
expect(123.toSnowflake(), user.id);
expect("Test test", user.username);
expect(123, user.discriminator);
expect(user.avatarURL(), isNotNull);
expect(user.avatarURL(), contains("${123 % 5}.png"));
expect(user.bot, false);
expect(user.system, false);
expect(user.userFlags, isNotNull);
expect(user.userFlags!.discordEmployee, true);
expect(user.userFlags!.earlySupporter, false);
});
test("Create member object", () {
final member = EntityUtility.createGuildMember(client, 123.toSnowflake(), sampleMemberData);
});
});
}