Skip to content

Commit

Permalink
test: add test for listObjects context
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Apr 8, 2024
1 parent 7d46fa8 commit abe0c5e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,30 @@ public void listObjects_500() throws Exception {
"{\"code\":\"internal_error\",\"message\":\"Internal Server Error\"}", exception.getResponseData());
}

@Test
public void listObjectsWithContextTest() throws Exception {
// Given
String postPath = String.format("https://localhost/stores/%s/list-objects", DEFAULT_STORE_ID);
String expectedBody = String.format(
"{\"authorization_model_id\":\"%s\",\"type\":null,\"relation\":\"%s\",\"user\":\"%s\",\"contextual_tuples\":null,\"context\":{\"some\":\"context\"}}",
DEFAULT_AUTH_MODEL_ID, DEFAULT_RELATION, DEFAULT_USER);
mockHttpClient
.onPost(postPath)
.withBody(is(expectedBody))
.doReturn(200, String.format("{\"objects\":[\"%s\"]}", DEFAULT_OBJECT));
ClientListObjectsRequest request = new ClientListObjectsRequest()
.relation(DEFAULT_RELATION)
.user(DEFAULT_USER)
.context(Map.of("some", "context"));

// When
ClientListObjectsResponse response = fga.listObjects(request).get();

// Then
mockHttpClient.verify().post(postPath).withBody(is(expectedBody)).called(1);
assertEquals(List.of(DEFAULT_OBJECT), response.getObjects());
}

/**
* Check whether a user is authorized to access an object.
*/
Expand Down

0 comments on commit abe0c5e

Please sign in to comment.