diff --git a/packages/nextcloud/test/cookbook_test.dart b/packages/nextcloud/test/cookbook_test.dart index 1a87b435f38..2d58dcb8e93 100644 --- a/packages/nextcloud/test/cookbook_test.dart +++ b/packages/nextcloud/test/cookbook_test.dart @@ -45,10 +45,21 @@ void main() { }); test('renameCategory', () async { + final recipe = cookbook.RecipeBuilder() + ..name = 'My super cool recipe' + ..dateCreated = DateTime.utc(2023).toIso8601String() + ..recipeCategory = 'Test'; + final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build()); + addTearDown(() async { + closeFixture(); + await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString()); + }); + expect(createResponse.body, isNotNull); + final request = cookbook.RenameCategoryRequestApplicationJsonBuilder()..name = 'Delicious Soup'; final response = await client.cookbook.categories.renameCategory( - category: 'Soup', + category: 'Test', $body: request.build(), ); @@ -57,21 +68,23 @@ void main() { }); group('misc', () { + final expectedConfig = cookbook.ConfigBuilder() + ..folder = '/Recipes' + ..updateInterval = 5 + ..printImage = true + ..visibleInfoBlocks.update( + (b) => b + ..preparationTime = true + ..cookingTime = true + ..totalTime = true + ..nutritionInformation = true + ..tools = true, + ); + test('getConfig', () async { final response = await client.cookbook.misc.getConfig(); - final visibleInfoBlocks = cookbook.VisibleInfoBlocksBuilder() - ..preparationTime = true - ..cookingTime = true - ..totalTime = true - ..nutritionInformation = true - ..tools = true; - final expected = cookbook.ConfigBuilder() - ..folder = '/Recipes' - ..updateInterval = 5 - ..printImage = true - ..visibleInfoBlocks = visibleInfoBlocks; - expect(response.body, equalsBuilt(expected.build())); + expect(response.body, equalsBuilt(expectedConfig.build())); }); test('reindex', () async { @@ -81,6 +94,11 @@ void main() { }); test('setConfig', () async { + addTearDown(() async { + closeFixture(); + await client.cookbook.misc.setConfig($body: expectedConfig.build()); + }); + final config = cookbook.ConfigBuilder()..folder = '/'; final response = await client.cookbook.misc.setConfig($body: config.build()); @@ -100,17 +118,14 @@ void main() { test('callImport', () async { final url = cookbook.UrlBuilder()..url = 'http://localhost/static/recipe.html'; final response = await client.cookbook.recipes.$import($body: url.build()); + addTearDown(() async { + closeFixture(); + await client.cookbook.recipes.deleteRecipe(id: response.body.id!); + }); expect(response.body, isA()); }); - test('deleteRecipe', () async { - const id = '0'; - final response = await client.cookbook.recipes.deleteRecipe(id: id); - - expect(response.body, equals('Recipe $id deleted successfully')); - }); - test('getImage', () async { final recipes = await client.cookbook.recipes.listRecipes(); final recipeWithoutImage = recipes.body.firstWhere((stub) => stub.name == 'Recipe Without an image'); @@ -135,13 +150,15 @@ void main() { expect(response.body, hasLength(19)); }); - test('newRecipe', () async { + test('newRecipe and deleteRecipe', () async { final recipe = cookbook.RecipeBuilder() ..name = 'My super cool recipe' ..dateCreated = DateTime.utc(2023).toIso8601String(); - final response = await client.cookbook.recipes.newRecipe($body: recipe.build()); + final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build()); + expect(createResponse.body, isNotNull); - expect(response.body, isNotNull); + final deleteResponse = await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString()); + expect(deleteResponse.body, equals('Recipe ${createResponse.body} deleted successfully')); }); test('recipeDetails', () async { @@ -166,9 +183,19 @@ void main() { final recipe = cookbook.RecipeBuilder() ..name = 'My super cool recipe' ..dateCreated = DateTime.utc(2023).toIso8601String(); - final response = await client.cookbook.recipes.updateRecipe(id: '0', $body: recipe.build()); - - expect(response.body, isNotNull); + final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build()); + addTearDown(() async { + closeFixture(); + await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString()); + }); + expect(createResponse.body, isNotNull); + + recipe + ..id = createResponse.body.toString() + ..name = 'My updated super cool recipe'; + final updateResponse = + await client.cookbook.recipes.updateRecipe(id: createResponse.body.toString(), $body: recipe.build()); + expect(updateResponse.body, isNotNull); }); }); diff --git a/packages/nextcloud/test/fixtures/cookbook/categories/renamecategory.regexp b/packages/nextcloud/test/fixtures/cookbook/categories/renamecategory.regexp index b6cc835da22..b529635f9a8 100644 --- a/packages/nextcloud/test/fixtures/cookbook/categories/renamecategory.regexp +++ b/packages/nextcloud/test/fixtures/cookbook/categories/renamecategory.regexp @@ -1,4 +1,9 @@ -PUT http://localhost/index\.php/apps/cookbook/api/v1/category/Soup +POST http://localhost/index\.php/apps/cookbook/api/v1/recipes +accept: application/json +authorization: Basic mock +content-type: application/json; charset=utf-8 +\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"Test","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":""\} +PUT http://localhost/index\.php/apps/cookbook/api/v1/category/Test accept: application/json authorization: Basic mock content-type: application/json; charset=utf-8 diff --git a/packages/nextcloud/test/fixtures/cookbook/recipes/deleterecipe.regexp b/packages/nextcloud/test/fixtures/cookbook/recipes/deleterecipe.regexp deleted file mode 100644 index a198deb5489..00000000000 --- a/packages/nextcloud/test/fixtures/cookbook/recipes/deleterecipe.regexp +++ /dev/null @@ -1,3 +0,0 @@ -DELETE http://localhost/index\.php/apps/cookbook/api/v1/recipes/0 -accept: application/json -authorization: Basic mock \ No newline at end of file diff --git a/packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe.regexp b/packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe_and_deleterecipe.regexp similarity index 78% rename from packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe.regexp rename to packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe_and_deleterecipe.regexp index acba3ce5e68..7df412db2cd 100644 --- a/packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe.regexp +++ b/packages/nextcloud/test/fixtures/cookbook/recipes/newrecipe_and_deleterecipe.regexp @@ -2,4 +2,7 @@ POST http://localhost/index\.php/apps/cookbook/api/v1/recipes accept: application/json authorization: Basic mock content-type: application/json; charset=utf-8 -\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":""\} \ No newline at end of file +\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":""\} +DELETE http://localhost/index\.php/apps/cookbook/api/v1/recipes/[0-9]+ +accept: application/json +authorization: Basic mock \ No newline at end of file diff --git a/packages/nextcloud/test/fixtures/cookbook/recipes/updaterecipe.regexp b/packages/nextcloud/test/fixtures/cookbook/recipes/updaterecipe.regexp index 544ebbf5fba..548dc1c006a 100644 --- a/packages/nextcloud/test/fixtures/cookbook/recipes/updaterecipe.regexp +++ b/packages/nextcloud/test/fixtures/cookbook/recipes/updaterecipe.regexp @@ -1,5 +1,10 @@ -PUT http://localhost/index\.php/apps/cookbook/api/v1/recipes/0 +POST http://localhost/index\.php/apps/cookbook/api/v1/recipes accept: application/json authorization: Basic mock content-type: application/json; charset=utf-8 -\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":""\} \ No newline at end of file +\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":""\} +PUT http://localhost/index\.php/apps/cookbook/api/v1/recipes/[0-9]+ +accept: application/json +authorization: Basic mock +content-type: application/json; charset=utf-8 +\{"@type":"Recipe","description":"","url":"","image":"","recipeYield":1,"recipeCategory":"","tool":\[\],"recipeIngredient":\[\],"recipeInstructions":\[\],"nutrition":\{"@type":"NutritionInformation"\},"name":"My updated super cool recipe","keywords":"","dateCreated":"2023-01-01T00:00:00\.000Z","imageUrl":"","imagePlaceholderUrl":"","id":"[0-9]+"\} \ No newline at end of file