Skip to content

Commit 32b6a5d

Browse files
committed
test(todo-items): write failing test for like operator
1 parent b247d15 commit 32b6a5d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,36 @@ public async Task Can_Filter_TodoItems()
124124
Assert.Equal(todoItem.Ordinal, todoItemResult.Ordinal);
125125
}
126126

127+
[Fact]
128+
public async Task Can_Filter_TodoItems_Using_Like_Operator()
129+
{
130+
// Arrange
131+
var todoItem = _todoItemFaker.Generate();
132+
todoItem.Ordinal = 999999;
133+
_context.TodoItems.Add(todoItem);
134+
_context.SaveChanges();
135+
var substring = todoItem.Description.Substring(1, todoItem.Description.Length - 2);
136+
137+
var httpMethod = new HttpMethod("GET");
138+
var route = $"/api/v1/todo-items?filter[description]=like:{substring}";
139+
140+
var description = new RequestProperties("Filter TodoItems Where Attribute Like", new Dictionary<string, string> {
141+
{ "?filter[...]=", "Filter on attribute" }
142+
});
143+
144+
// Act
145+
var response = await _fixture.MakeRequest<TodoItem>(description, httpMethod, route);
146+
var body = await response.Content.ReadAsStringAsync();
147+
var deserializedBody = JsonApiDeSerializer.DeserializeList<TodoItem>(body, _jsonApiContext);
148+
149+
// Assert
150+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
151+
Assert.NotEmpty(deserializedBody);
152+
153+
foreach (var todoItemResult in deserializedBody)
154+
Assert.Contains(substring, todoItem.Description);
155+
}
156+
127157
[Fact]
128158
public async Task Can_Sort_TodoItems_By_Ordinal_Ascending()
129159
{

0 commit comments

Comments
 (0)