Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(nextcloud): Reuse container for cookbook tests #2292

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions packages/nextcloud/test/cookbook_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);

Expand All @@ -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 {
Expand All @@ -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());

Expand All @@ -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<Recipe>());
});

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');
Expand All @@ -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 {
Expand All @@ -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);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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":""\}
\{"@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
Original file line number Diff line number Diff line change
@@ -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":""\}
\{"@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]+"\}