Skip to content

Commit

Permalink
Delete category test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Jan 6, 2024
1 parent bc225f1 commit 3c5865e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CategoriesApiContext : BaseContext
private IReadOnlyList<CategoryAutocompleteItemDto>? _categoriesListForAutocomplete;
private HttpResponseMessage _createCategoryResponse = null!;
private HttpResponseMessage _updateCategoryResponse = null!;
private HttpResponseMessage _deleteCategoryResponse = null!;

public CategoriesApiContext(FoodDiaryWebApplicationFactory factory) : base(factory)
{
Expand All @@ -42,6 +43,11 @@ public async Task When_user_renames_category(Category category, string newName)
var request = new CategoryCreateEditRequest { Name = newName };
_updateCategoryResponse = await ApiClient.PutAsJsonAsync($"/api/v1/categories/{category.Id}", request);
}

public async Task When_user_deletes_category(Category category)
{
_deleteCategoryResponse = await ApiClient.DeleteAsync($"/api/v1/categories/{category.Id}");
}

public async Task When_user_searches_categories_for_autocomplete()
{
Expand All @@ -60,6 +66,12 @@ public Task Then_categories_list_contains_items(params Category[] items)
return Task.CompletedTask;
}

public Task Then_categories_list_is_empty()
{
_categoriesList?.Should().BeEmpty();
return Task.CompletedTask;
}

public Task Then_category_is_successfully_created()
{
_createCategoryResponse.StatusCode.Should().Be(HttpStatusCode.OK);
Expand All @@ -71,6 +83,12 @@ public Task Then_category_is_successfully_updated()
_updateCategoryResponse.StatusCode.Should().Be(HttpStatusCode.OK);
return Task.CompletedTask;
}

public Task Then_category_is_successfully_deleted()
{
_deleteCategoryResponse.StatusCode.Should().Be(HttpStatusCode.OK);
return Task.CompletedTask;
}

public Task Then_categories_list_for_autocomplete_contains_items(params Category[] items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public Task I_can_update_category()
c => c.When_user_retrieves_categories_list(),
c => c.Then_categories_list_contains_items(frozenProducts));
}

[Scenario]
public Task I_can_delete_category()
{
var frozenFoods = Create.Category("Frozen foods").Please();

return Run(
c => c.Given_authenticated_user(),
c => c.Given_categories(frozenFoods),
c => c.When_user_deletes_category(frozenFoods),
c => c.Then_category_is_successfully_deleted(),
c => c.When_user_retrieves_categories_list(),
c => c.Then_categories_list_is_empty());
}

[Scenario]
public Task I_can_search_categories_for_autocomplete()
Expand Down

0 comments on commit 3c5865e

Please sign in to comment.