Skip to content

Commit

Permalink
test: Add test for OpenFgaClient list stores with option
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Sep 26, 2023
1 parent 8faca25 commit 34c00b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ Get a paginated list of stores.
[API Documentation](https://openfga.dev/api/service/docs/api#/Stores/ListStores)

```java
var options = new ListStoresOptions()
.pageSize(10)
.continuationToken("...");
var stores = fgaClient.listStores(options);

// stores = [{ "id": "01FQH7V8BEG3GPQW93KTRFR8JB", "name": "FGA Demo Store", "created_at": "2022-01-01T00:00:00.000Z", "updated_at": "2022-01-01T00:00:00.000Z" }]
```

##### Create Store
Expand Down Expand Up @@ -292,6 +298,24 @@ Update the assertions for a particular authorization model.

### API Endpoints

| Method | HTTP request | Description |
| ------------- | ------------- | ------------- |
| [**check**](docs/OpenFgaApi.md#check) | **POST** /stores/{store_id}/check | Check whether a user is authorized to access an object |
| [**createStore**](docs/OpenFgaApi.md#createstore) | **POST** /stores | Create a store |
| [**deleteStore**](docs/OpenFgaApi.md#deletestore) | **DELETE** /stores/{store_id} | Delete a store |
| [**expand**](docs/OpenFgaApi.md#expand) | **POST** /stores/{store_id}/expand | Expand all relationships in userset tree format, and following userset rewrite rules. Useful to reason about and debug a certain relationship |
| [**getStore**](docs/OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store |
| [**listObjects**](docs/OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with |
| [**listStores**](docs/OpenFgaApi.md#liststores) | **GET** /stores | List all stores |
| [**read**](docs/OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules |
| [**readAssertions**](docs/OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID |
| [**readAuthorizationModel**](docs/OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model |
| [**readAuthorizationModels**](docs/OpenFgaApi.md#readauthorizationmodels) | **GET** /stores/{store_id}/authorization-models | Return all the authorization models for a particular store |
| [**readChanges**](docs/OpenFgaApi.md#readchanges) | **GET** /stores/{store_id}/changes | Return a list of all the tuple changes |
| [**write**](docs/OpenFgaApi.md#write) | **POST** /stores/{store_id}/write | Add or delete tuples from the store |
| [**writeAssertions**](docs/OpenFgaApi.md#writeassertions) | **PUT** /stores/{store_id}/assertions/{authorization_model_id} | Upsert assertions for an authorization model ID |
| [**writeAuthorizationModel**](docs/OpenFgaApi.md#writeauthorizationmodel) | **POST** /stores/{store_id}/authorization-models | Create a new authorization model |



### Models
Expand Down
23 changes: 23 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 @@ -171,6 +171,29 @@ public void listStoresTest() throws Exception {
assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName());
}

@Test
public void listStoresTest_withOptions() throws Exception {
// Given
String responseBody =
String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
int pageSize = 10;
String continuationToken = "continuationToken";
String getUrl = String.format(
"https://localhost/stores?page_size=%d&continuation_token=%s", pageSize, continuationToken);
mockHttpClient.onGet(getUrl).doReturn(200, responseBody);
ListStoresOptions options = new ListStoresOptions().pageSize(pageSize).continuationToken(continuationToken);

// When
ListStoresResponse response = fga.listStores(options).get();

// Then
mockHttpClient.verify().get(getUrl).called(1);
assertNotNull(response.getStores());
assertEquals(1, response.getStores().size());
assertEquals(DEFAULT_STORE_ID, response.getStores().get(0).getId());
assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName());
}

/**
* Create a store.
*/
Expand Down

0 comments on commit 34c00b3

Please sign in to comment.