From cbdb14b1ce31fbcc8ab84d61468b2805915701b2 Mon Sep 17 00:00:00 2001 From: Lea Date: Mon, 6 Feb 2023 09:13:27 +0100 Subject: [PATCH] Add basic unit tests --- test/api_test.dart | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/api_test.dart diff --git a/test/api_test.dart b/test/api_test.dart new file mode 100644 index 0000000..7e8f1a1 --- /dev/null +++ b/test/api_test.dart @@ -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: "

deez

", + 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 + }); +}