Skip to content

Commit

Permalink
Merge pull request #2325 from nextcloud/refactor/nextcloud_test/unifi…
Browse files Browse the repository at this point in the history
…ed_test_instance_handling

refactor(nextcloud_test): unify test instance handling
  • Loading branch information
Leptopoda authored Jul 28, 2024
2 parents 9b5679a + 9cffb7d commit d8af245
Show file tree
Hide file tree
Showing 26 changed files with 581 additions and 633 deletions.
1 change: 1 addition & 0 deletions .cspell/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ libflutter
libgtk
libsqlite
mipmap
Multimap
ndebug
nodoc
noopenapi
Expand Down
78 changes: 32 additions & 46 deletions packages/nextcloud/test/cookbook_test.dart
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
import 'package:built_value/json_object.dart';
import 'package:built_value_test/matcher.dart';
import 'package:nextcloud/cookbook.dart' as cookbook;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:test/test.dart';

void main() {
final targetFactory = TestTargetFactory.create();

presets(
targetFactory,
'cookbook',
'cookbook',
(preset) {
late TestTargetInstance target;
late NextcloudClient client;
setUpAll(() async {
target = await targetFactory.spawn(preset);
client = await target.createClient();
});
tearDownAll(() async {
await target.destroy();
});

(tester) {
group('CookbookVersionCheck', () {
test('Is supported', () async {
final response = await client.cookbook.getVersionCheck();
final response = await tester.client.cookbook.getVersionCheck();

expect(response.isSupported, isTrue);
});
});

group('categories', () {
test('listCategories', () async {
final response = await client.cookbook.categories.listCategories();
final response = await tester.client.cookbook.categories.listCategories();

expect(response.body, hasLength(7));
});

test('recipesInCategory', () async {
final response = await client.cookbook.categories.recipesInCategory(category: 'Soup');
final response = await tester.client.cookbook.categories.recipesInCategory(category: 'Soup');

expect(response.body, hasLength(2));
});
Expand All @@ -49,16 +35,16 @@ void main() {
..name = 'My super cool recipe'
..dateCreated = DateTime.utc(2023).toIso8601String()
..recipeCategory = 'Test';
final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build());
final createResponse = await tester.client.cookbook.recipes.newRecipe($body: recipe.build());
addTearDown(() async {
closeFixture();
await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString());
await tester.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(
final response = await tester.client.cookbook.categories.renameCategory(
category: 'Test',
$body: request.build(),
);
Expand All @@ -82,61 +68,61 @@ void main() {
);

test('getConfig', () async {
final response = await client.cookbook.misc.getConfig();
final response = await tester.client.cookbook.misc.getConfig();

expect(response.body, equalsBuilt(expectedConfig.build()));
});

test('reindex', () async {
final response = await client.cookbook.misc.reindex();
final response = await tester.client.cookbook.misc.reindex();

expect(response.body, 'Search index rebuilt successfully');
});

test('setConfig', () async {
addTearDown(() async {
closeFixture();
await client.cookbook.misc.setConfig($body: expectedConfig.build());
await tester.client.cookbook.misc.setConfig($body: expectedConfig.build());
});

final config = cookbook.ConfigBuilder()..folder = '/';
final response = await client.cookbook.misc.setConfig($body: config.build());
final response = await tester.client.cookbook.misc.setConfig($body: config.build());

expect(response.body, 'OK');
});

test('version', () async {
final response = await client.cookbook.misc.version();
final response = await tester.client.cookbook.misc.version();

final cookbookVersion = response.body.cookbookVersion!;
expect(cookbookVersion[0], JsonObject(preset.version.major));
expect(cookbookVersion[1], JsonObject(preset.version.minor));
expect(cookbookVersion[0], JsonObject(tester.version.major));
expect(cookbookVersion[1], JsonObject(tester.version.minor));
});
});

group('recipes', () {
test('callImport', () async {
final url = cookbook.UrlBuilder()..url = '${target.targetURL}/static/recipe.html';
final response = await client.cookbook.recipes.$import($body: url.build());
final url = cookbook.UrlBuilder()..url = '${tester.targetURL}/static/recipe.html';
final response = await tester.client.cookbook.recipes.$import($body: url.build());
addTearDown(() async {
closeFixture();
await client.cookbook.recipes.deleteRecipe(id: response.body.id!);
await tester.client.cookbook.recipes.deleteRecipe(id: response.body.id!);
});

expect(response.body, isA<cookbook.Recipe>());
});

test('getImage', () async {
final recipes = await client.cookbook.recipes.listRecipes();
final recipes = await tester.client.cookbook.recipes.listRecipes();
final recipeWithoutImage = recipes.body.firstWhere((stub) => stub.name == 'Recipe Without an image');
final response = await client.cookbook.recipes.getImage(
final response = await tester.client.cookbook.recipes.getImage(
id: recipeWithoutImage.id,
);

expect(response.body, isNotNull);

final recipeWithImage = recipes.body.firstWhere((stub) => stub.name == "Chef John's Gazpacho");
final response2 = await client.cookbook.recipes.getImage(
final response2 = await tester.client.cookbook.recipes.getImage(
id: recipeWithImage.id,
size: cookbook.GetImageSize.full,
);
Expand All @@ -145,7 +131,7 @@ void main() {
});

test('listRecipes', () async {
final response = await client.cookbook.recipes.listRecipes();
final response = await tester.client.cookbook.recipes.listRecipes();

expect(response.body, hasLength(19));
});
Expand All @@ -154,18 +140,18 @@ void main() {
final recipe = cookbook.RecipeBuilder()
..name = 'My super cool recipe'
..dateCreated = DateTime.utc(2023).toIso8601String();
final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build());
final createResponse = await tester.client.cookbook.recipes.newRecipe($body: recipe.build());
expect(createResponse.body, isNotNull);

final deleteResponse = await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString());
final deleteResponse = await tester.client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString());
expect(deleteResponse.body, equals('Recipe ${createResponse.body} deleted successfully'));
});

test('recipeDetails', () async {
final recipes = await client.cookbook.recipes.listRecipes();
final recipes = await tester.client.cookbook.recipes.listRecipes();

for (final recipe in recipes.body) {
final response = await client.cookbook.recipes.recipeDetails(
final response = await tester.client.cookbook.recipes.recipeDetails(
id: recipe.id,
);

Expand All @@ -174,7 +160,7 @@ void main() {
});

test('search', () async {
final response = await client.cookbook.recipes.search(query: 'Vegan');
final response = await tester.client.cookbook.recipes.search(query: 'Vegan');

expect(response.body, hasLength(2));
});
Expand All @@ -183,31 +169,31 @@ void main() {
final recipe = cookbook.RecipeBuilder()
..name = 'My super cool recipe'
..dateCreated = DateTime.utc(2023).toIso8601String();
final createResponse = await client.cookbook.recipes.newRecipe($body: recipe.build());
final createResponse = await tester.client.cookbook.recipes.newRecipe($body: recipe.build());
addTearDown(() async {
closeFixture();
await client.cookbook.recipes.deleteRecipe(id: createResponse.body.toString());
await tester.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());
final updateResponse = await tester.client.cookbook.recipes
.updateRecipe(id: createResponse.body.toString(), $body: recipe.build());
expect(updateResponse.body, isNotNull);
});
});

group('tags', () {
test('listKeywords', () async {
final response = await client.cookbook.tags.listKeywords();
final response = await tester.client.cookbook.tags.listKeywords();

expect(response.body, hasLength(16));
});

test('recipesWithKeyword', () async {
final response = await client.cookbook.tags.recipesWithKeyword(keywords: 'Desserts');
final response = await tester.client.cookbook.tags.recipesWithKeyword(keywords: 'Desserts');

expect(response.body, hasLength(0));
});
Expand Down
Loading

0 comments on commit d8af245

Please sign in to comment.