Skip to content

Commit

Permalink
テストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 30, 2023
1 parent e1eab97 commit 3538f4c
Show file tree
Hide file tree
Showing 19 changed files with 789 additions and 117 deletions.
46 changes: 36 additions & 10 deletions test/misskey_antennas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'util/misskey_dart_test_util.dart';

void main() async {
test("create", () async {
await userClient.antennas.create(
final antenna = await userClient.antennas.create(
AntennasCreateRequest(
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"]
["keyword"],
],
excludeKeywords: [[]],
users: [],
Expand All @@ -20,6 +20,7 @@ void main() async {
notify: false,
),
);
expect(antenna.name, equals("test"));
});

test("delete", () async {
Expand All @@ -28,7 +29,7 @@ void main() async {
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"]
["keyword"],
],
excludeKeywords: [[]],
users: [],
Expand All @@ -40,10 +41,28 @@ void main() async {
);
await userClient.antennas
.delete(AntennasDeleteRequest(antennaId: antenna.id));
final antennas = await userClient.antennas.list();
expect(antennas.map((e) => e.id), isNot(contains(antenna.id)));
});

test("list", () async {
await userClient.antennas.list();
final antenna = await userClient.antennas.create(
AntennasCreateRequest(
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"],
],
excludeKeywords: [[]],
users: [],
caseSensitive: false,
withReplies: false,
withFile: false,
notify: false,
),
);
final response = await userClient.antennas.list();
expect(response.map((e) => e.id), contains(antenna.id));
});

test("notes", () async {
Expand All @@ -52,7 +71,7 @@ void main() async {
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"]
["keyword"],
],
excludeKeywords: [[]],
users: [],
Expand All @@ -62,8 +81,10 @@ void main() async {
notify: false,
),
);
await userClient.antennas
final note = await userClient.createNote(text: "keyword");
final response = await userClient.antennas
.notes(AntennasNotesRequest(antennaId: antenna.id));
expect(response.map((e) => e.id), contains(note.id));
});

test("show", () async {
Expand All @@ -72,7 +93,7 @@ void main() async {
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"]
["keyword"],
],
excludeKeywords: [[]],
users: [],
Expand All @@ -82,7 +103,9 @@ void main() async {
notify: false,
),
);
await userClient.antennas.show(AntennasShowRequest(antennaId: antenna.id));
final response = await userClient.antennas
.show(AntennasShowRequest(antennaId: antenna.id));
expect(response.name, equals(antenna.name));
});

test("update", () async {
Expand All @@ -91,7 +114,7 @@ void main() async {
name: "test",
src: AntennaSource.all,
keywords: [
["keyword"]
["keyword"],
],
excludeKeywords: [[]],
users: [],
Expand All @@ -108,7 +131,7 @@ void main() async {
src: AntennaSource.users,
keywords: [[]],
excludeKeywords: [
["keyword"]
["keyword"],
],
users: ["@admin"],
caseSensitive: true,
Expand All @@ -117,5 +140,8 @@ void main() async {
notify: true,
),
);
final updated = await userClient.antennas
.show(AntennasShowRequest(antennaId: antenna.id));
expect(updated.name, equals("updated"));
});
}
30 changes: 29 additions & 1 deletion test/misskey_ap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,32 @@ import 'package:test/test.dart';

import 'util/misskey_dart_test_util.dart';

void main() async {}
void main() async {
group("show", () {
test("note", () async {
final note = await userClient.createNote();
final response = await userClient.ap.show(
ApShowRequest(
uri: Uri.parse(
"${userClient.apiService.apiUrl?.split(":")[0] ?? "https"}://"
"${userClient.host}/notes/${note.id}"),
),
);
expect(response.type, equals("Note"));
Note.fromJson(response.object);
});

test("user", () async {
final user = await userClient.i.i();
final response = await userClient.ap.show(
ApShowRequest(
uri: Uri.parse(
"${userClient.apiService.apiUrl?.split(":")[0] ?? "https"}://"
"${userClient.host}/users/${user.id}"),
),
);
expect(response.type, equals("User"));
User.fromJson(response.object);
});
});
}
9 changes: 9 additions & 0 deletions test/misskey_blocking_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ void main() async {
test("create", () async {
final newUser = (await adminClient.createUser()).user;
await userClient.blocking.create(BlockCreateRequest(userId: newUser.id));
final userDetailed =
await userClient.users.show(UsersShowRequest(userId: newUser.id));
expect(userDetailed.isBlocking, isTrue);
});

test("delete", () async {
final newUser = (await adminClient.createUser()).user;
await userClient.blocking.create(BlockCreateRequest(userId: newUser.id));
await userClient.blocking.delete(BlockDeleteRequest(userId: newUser.id));
final userDetailed =
await userClient.users.show(UsersShowRequest(userId: newUser.id));
expect(
userDetailed.isBlocking,
isFalse,
);
});
}
48 changes: 36 additions & 12 deletions test/misskey_channels_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,67 @@ void main() async {
test("timeline", () async {
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels
final note = await userClient.createNote(channelId: channel.id);
final response = await userClient.channels
.timeline(ChannelsTimelineRequest(channelId: channel.id));
expect(response.map((e) => e.id), contains(note.id));
});

test("show", () async {
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels.show(ChannelsShowRequest(channelId: channel.id));
final response = await userClient.channels
.show(ChannelsShowRequest(channelId: channel.id));
expect(response.name, equals(channel.name));
});

test("followed", () async {
final channel =
await adminClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels
.follow(ChannelsFollowRequest(channelId: channel.id));
await userClient.channels.followed(ChannelsFollowedRequest());
final response =
await userClient.channels.followed(ChannelsFollowedRequest());
expect(response.map((e) => e.id), contains(channel.id));
});

test("my-favorites", () async {
final channel =
await adminClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels
.favorite(ChannelsFavoriteRequest(channelId: channel.id));
await userClient.channels.myFavorite(ChannelsMyFavoriteRequest());
final response =
await userClient.channels.myFavorite(ChannelsMyFavoriteRequest());
expect(response.map((e) => e.id), contains(channel.id));
});

test("featured", () async {
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
await adminClient.channels
.favorite(ChannelsFavoriteRequest(channelId: channel.id));
await userClient.channels.featured();
await adminClient.createNote(channelId: channel.id);
final response = await userClient.channels.featured();
expect(response.map((e) => e.id), contains(channel.id));
});

test("owned", () async {
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels.owned(ChannelsOwnedRequest());
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
final response = await userClient.channels.owned(ChannelsOwnedRequest());
expect(response.map((e) => e.id), contains(channel.id));
});

test("search", () async {
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
await userClient.channels.search(ChannelsSearchRequest(query: "test"));
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
final response =
await userClient.channels.search(ChannelsSearchRequest(query: "test"));
expect(response.map((e) => e.id), contains(channel.id));
});

test("create", () async {
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
final channel =
await userClient.channels.create(ChannelsCreateRequest(name: "test"));
expect(channel.name, equals("test"));
});

test("update", () async {
Expand All @@ -69,6 +84,9 @@ void main() async {
color: "#FF0000",
),
);
final updated = await userClient.channels
.show(ChannelsShowRequest(channelId: channel.id));
expect(updated.name, equals("updated"));
});

test("favorite", () async {
Expand All @@ -85,6 +103,9 @@ void main() async {
.favorite(ChannelsFavoriteRequest(channelId: channel.id));
await userClient.channels
.unfavorite(ChannelsUnfavoriteRequest(channelId: channel.id));
final channels =
await userClient.channels.myFavorite(ChannelsMyFavoriteRequest());
expect(channels.map((e) => e.id), isNot(contains(channel.id)));
});

test("follow", () async {
Expand All @@ -101,5 +122,8 @@ void main() async {
.follow(ChannelsFollowRequest(channelId: channel.id));
await userClient.channels
.unfollow(ChannelsUnfollowRequest(channelId: channel.id));
final channels =
await userClient.channels.followed(ChannelsFollowedRequest());
expect(channels.map((e) => e.id), isNot(contains(channel.id)));
});
}
30 changes: 24 additions & 6 deletions test/misskey_clips_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import 'util/misskey_dart_test_util.dart';

void main() async {
test("list", () async {
await userClient.clips.create(ClipsCreateRequest(name: "test"));
await userClient.clips.list();
final clip =
await userClient.clips.create(ClipsCreateRequest(name: "test"));
final response = await userClient.clips.list();
expect(response.map((e) => e.id), contains(clip.id));
});

test("my-favorites", () async {
Expand All @@ -17,7 +19,8 @@ void main() async {
),
);
await userClient.clips.favorite(ClipsFavoriteRequest(clipId: clip.id));
await userClient.clips.myFavorites();
final response = await userClient.clips.myFavorites();
expect(response.map((e) => e.id), contains(clip.id));
});

test("notes", () async {
Expand All @@ -26,6 +29,9 @@ void main() async {
final note = await userClient.createNote();
await userClient.clips
.addNote(ClipsAddNoteRequest(clipId: clip.id, noteId: note.id));
final response =
await userClient.clips.notes(ClipsNotesRequest(clipId: clip.id));
expect(response.map((e) => e.id), contains(note.id));
});

test("add-note", () async {
Expand All @@ -45,16 +51,23 @@ void main() async {
await userClient.clips.removeNote(
ClipsRemoveNoteRequest(clipId: clip.id, noteId: note.id),
);
final notes =
await userClient.clips.notes(ClipsNotesRequest(clipId: clip.id));
expect(notes.map((e) => e.id), isNot(contains(note.id)));
});

test("create", () async {
await userClient.clips.create(ClipsCreateRequest(name: "test"));
final clip =
await userClient.clips.create(ClipsCreateRequest(name: "test"));
expect(clip.name, equals("test"));
});

test("delete", () async {
final clip =
await userClient.clips.create(ClipsCreateRequest(name: "test"));
await userClient.clips.delete(ClipsDeleteRequest(clipId: clip.id));
final clips = await userClient.clips.list();
expect(clips.map((e) => e.id), isNot(contains(clip.id)));
});

test("update", () async {
Expand All @@ -65,19 +78,22 @@ void main() async {
description: "test",
),
);
await userClient.clips.update(
final updated = await userClient.clips.update(
ClipsUpdateRequest(
clipId: clip.id,
name: "updated",
isPublic: true,
),
);
expect(updated.name, equals("updated"));
});

test("show", () async {
final clip =
await userClient.clips.create(ClipsCreateRequest(name: "test"));
await userClient.clips.show(ClipsShowRequest(clipId: clip.id));
final response =
await userClient.clips.show(ClipsShowRequest(clipId: clip.id));
expect(response.name, equals(clip.name));
});

test("favorite", () async {
Expand All @@ -99,5 +115,7 @@ void main() async {
);
await userClient.clips.favorite(ClipsFavoriteRequest(clipId: clip.id));
await userClient.clips.unfavorite(ClipsUnfavoriteRequest(clipId: clip.id));
final clips = await userClient.clips.myFavorites();
expect(clips.map((e) => e.id), isNot(contains(clip.id)));
});
}
Loading

0 comments on commit 3538f4c

Please sign in to comment.