Skip to content

Commit abe0c5e

Browse files
committed
test: add test for listObjects context
1 parent 7d46fa8 commit abe0c5e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,30 @@ public void listObjects_500() throws Exception {
19751975
"{\"code\":\"internal_error\",\"message\":\"Internal Server Error\"}", exception.getResponseData());
19761976
}
19771977

1978+
@Test
1979+
public void listObjectsWithContextTest() throws Exception {
1980+
// Given
1981+
String postPath = String.format("https://localhost/stores/%s/list-objects", DEFAULT_STORE_ID);
1982+
String expectedBody = String.format(
1983+
"{\"authorization_model_id\":\"%s\",\"type\":null,\"relation\":\"%s\",\"user\":\"%s\",\"contextual_tuples\":null,\"context\":{\"some\":\"context\"}}",
1984+
DEFAULT_AUTH_MODEL_ID, DEFAULT_RELATION, DEFAULT_USER);
1985+
mockHttpClient
1986+
.onPost(postPath)
1987+
.withBody(is(expectedBody))
1988+
.doReturn(200, String.format("{\"objects\":[\"%s\"]}", DEFAULT_OBJECT));
1989+
ClientListObjectsRequest request = new ClientListObjectsRequest()
1990+
.relation(DEFAULT_RELATION)
1991+
.user(DEFAULT_USER)
1992+
.context(Map.of("some", "context"));
1993+
1994+
// When
1995+
ClientListObjectsResponse response = fga.listObjects(request).get();
1996+
1997+
// Then
1998+
mockHttpClient.verify().post(postPath).withBody(is(expectedBody)).called(1);
1999+
assertEquals(List.of(DEFAULT_OBJECT), response.getObjects());
2000+
}
2001+
19782002
/**
19792003
* Check whether a user is authorized to access an object.
19802004
*/

0 commit comments

Comments
 (0)