Add basic unit tests

This commit is contained in:
Lea 2023-02-06 09:13:27 +01:00
parent b55b4e53a5
commit cbdb14b1ce
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

56
test/api_test.dart Normal file
View file

@ -0,0 +1,56 @@
import 'package:feet/api/api.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group("API", () {
test("API key hashing", () {
final hash = FeverAPI.generateApiKey("bob", "abcdefgh");
expect(hash, "0fd86d2d609be5de9dce2ac77ad939a4");
});
test("API request builder", () {
final api = FeverAPI(apiUrl: "https://deez.org");
final item = Item(api,
id: 44,
feedId: 4,
title: "Morbius",
author: "Imposter from Among",
html: "<p>deez</p>",
url: "https://amogus.org",
isSaved: true,
isRead: false,
createdOnTime: DateTime.now());
final request = api
.request()
.withItems()
.withGroups()
.withFeeds()
.withFavicons()
.withIds([1, 2])
.sinceId(69)
.maxId(420)
.markItem(item, ItemMarkType.read);
expect(request.args, [
"items",
"groups",
"feeds",
"favicons",
"with_ids=1,2",
"since_id=69",
"max_id=420",
"mark=item",
"as=read",
"id=44",
]);
expect(
request.generateUrl(),
Uri.parse("https://deez.org?api&items&groups&feeds&favicons&with_ids=1,2&since_id=69&max_id=420&mark=item&as=read&id=44"));
});
// TODO: Test item/feed/group/etc constructors
});
}