From 8ee10a342449821de115d693a4325ef798f8ea82 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 3 Jun 2022 21:14:39 +1000 Subject: [PATCH] Adds more unit tests for the part model --- test/models_test.dart | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/models_test.dart b/test/models_test.dart index 3cd6bec5..91aac97c 100644 --- a/test/models_test.dart +++ b/test/models_test.dart @@ -27,6 +27,10 @@ void main() { group("Part Tests:", () { + test("Basics", () async { + assert(InvenTreePart().URL == "part/"); + }); + test("List Parts", () async { List results; @@ -49,6 +53,64 @@ void main() { assert(results.length == 2); }); + test("Part Detail", () async { + final result = await InvenTreePart().get(1); + + assert(result != null); + assert(result is InvenTreePart); + + if (result != null) { + InvenTreePart part = result as InvenTreePart; + + // Check some basic properties of the part + assert(part.name == "M2x4 LPHS"); + assert(part.fullname == "M2x4 LPHS"); + assert(part.description == "M2x4 low profile head screw"); + assert(part.categoryId == 8); + assert(part.categoryName == "Fasteners"); + assert(part.image == part.thumbnail); + assert(part.thumbnail == "/static/img/blank_image.thumbnail.png"); + + // Stock information + assert(part.unallocatedStockString == "9000"); + assert(part.inStockString == "9000"); + } + + }); + + test("Part Adjust", () async { + // Test that we can update part data + final result = await InvenTreePart().get(1); + + assert(result != null); + assert(result is InvenTreePart); + + if (result != null) { + InvenTreePart part = result as InvenTreePart; + assert(part.name == "M2x4 LPHS"); + + // Change the name to something else + assert(await part.update( + values: { + "name": "Woogle", + } + )); + + assert(await part.reload()); + assert(part.name == "Woogle"); + + // And change it back again + assert(await part.update( + values: { + "name": "M2x4 LPHS" + } + )); + + assert(await part.reload()); + assert(part.name == "M2x4 LPHS"); + } + }); + }); } \ No newline at end of file