From 8aab3bd71676e95d20ca1f9c38e1f352793743e4 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Fri, 15 Nov 2024 15:23:05 -0800 Subject: [PATCH 01/28] Install fauna-shell. --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78db6f3..c2043c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,9 @@ jobs: with: java-version: '17' distribution: corretto + - name: Install fauna-shell + run: + npm install fauna-shell - name: Run sample app run: ./gradlew build From f4807dbb7adb12cf394caa7826c8212027494e3d Mon Sep 17 00:00:00 2001 From: David Griffin Date: Fri, 15 Nov 2024 15:25:24 -0800 Subject: [PATCH 02/28] Fix indentation. --- .github/workflows/test.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2043c6..14e2bed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,25 +4,25 @@ on: pull_request: jobs: - build: + validate: runs-on: ubuntu-latest - services: - fauna: - image: fauna/faunadb - ports: - - 8443:8443 - steps: - - name: Check out repository - uses: actions/checkout@v4 + services: + fauna: + image: fauna/faunadb + ports: + - 8443:8443 + steps: + - name: Check out repository + uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: corretto - - name: Install fauna-shell - run: - npm install fauna-shell + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: corretto + - name: Install fauna-shell + run: + npm install fauna-shell - - name: Run sample app - run: ./gradlew build + - name: Run sample app + run: ./gradlew build From 376c76c8a6491e75914a10bcc70ec834e7eb9f1d Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 15:31:25 -0800 Subject: [PATCH 03/28] Setup Fauna project in GitHub Actions. --- .github/workflows/test.yml | 2 ++ test/local-project | 3 +++ test/setup.sh | 10 ++++++++++ test/validate.sh | 7 +++++++ 4 files changed, 22 insertions(+) create mode 100644 test/local-project create mode 100644 test/setup.sh create mode 100644 test/validate.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14e2bed..6ea83cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,8 @@ jobs: - name: Install fauna-shell run: npm install fauna-shell + - name: Setup Test Database + run: ./setup.sh - name: Run sample app run: ./gradlew build diff --git a/test/local-project b/test/local-project new file mode 100644 index 0000000..6b1bc3e --- /dev/null +++ b/test/local-project @@ -0,0 +1,3 @@ +schema_directory=schema +default=local + diff --git a/test/setup.sh b/test/setup.sh new file mode 100644 index 0000000..e1db209 --- /dev/null +++ b/test/setup.sh @@ -0,0 +1,10 @@ +DB_NAME="ECommerceJava" +LOCAL_ENDPOINT="http://localhost:8443/" +SECRET="secret" + +cp ./test/local-project .fauna-project + +fauna endpoint add local --url "$LOCAL_ENDPOINT" --secret "$SECRET" +fauna endpoint select local + +fauna create-database "$DB_NAME" diff --git a/test/validate.sh b/test/validate.sh new file mode 100644 index 0000000..b999b72 --- /dev/null +++ b/test/validate.sh @@ -0,0 +1,7 @@ +#! /bin/sh + +ENDPOINT="http://localhost:8080" + +curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer secret" "$ENDPOINT/products?pageSize=1" + + From 90ab868af7809b7863642d106f93ae66de8484ec Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 15:44:01 -0800 Subject: [PATCH 04/28] Setup script fixes. --- test/setup.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/setup.sh b/test/setup.sh index e1db209..efad9a8 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -1,10 +1,16 @@ +#! /bin/sh + DB_NAME="ECommerceJava" LOCAL_ENDPOINT="http://localhost:8443/" SECRET="secret" cp ./test/local-project .fauna-project +echo "Copied .fauna-project" + fauna endpoint add local --url "$LOCAL_ENDPOINT" --secret "$SECRET" +echo "Added local endpoint" fauna endpoint select local +echo "Selected local endpoint" fauna create-database "$DB_NAME" From 12caf470ec36fe4d5ba06d92781eae734d16d9f3 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 15:47:34 -0800 Subject: [PATCH 05/28] Call correct script. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ea83cf..931831e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: run: npm install fauna-shell - name: Setup Test Database - run: ./setup.sh + run: ./test/setup.sh - name: Run sample app run: ./gradlew build From 498619ebd95dc8aed2d9db61476801fd30265ebd Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 15:50:56 -0800 Subject: [PATCH 06/28] Make test/setup.sh executable. --- test/setup.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/setup.sh diff --git a/test/setup.sh b/test/setup.sh old mode 100644 new mode 100755 From cde3f15053445842cd0f9bce79e19100191aa230 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 16:17:53 -0800 Subject: [PATCH 07/28] Use full path to fauna. --- test/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/setup.sh b/test/setup.sh index efad9a8..5dd7192 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -8,9 +8,9 @@ cp ./test/local-project .fauna-project echo "Copied .fauna-project" -fauna endpoint add local --url "$LOCAL_ENDPOINT" --secret "$SECRET" +/usr/local/bin/fauna endpoint add local --url "$LOCAL_ENDPOINT" --secret "$SECRET" echo "Added local endpoint" -fauna endpoint select local +/usr/local/bin/fauna endpoint select local echo "Selected local endpoint" -fauna create-database "$DB_NAME" +/usr/local/bin/fauna create-database "$DB_NAME" From 70ce2b8158b2d3d161de88633b8a194fd8179bef Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 16:22:15 -0800 Subject: [PATCH 08/28] Add -g flag to npm install. --- .github/workflows/test.yml | 2 +- test/setup.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 931831e..833ed62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: distribution: corretto - name: Install fauna-shell run: - npm install fauna-shell + npm install -g fauna-shell - name: Setup Test Database run: ./test/setup.sh diff --git a/test/setup.sh b/test/setup.sh index 5dd7192..4816462 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -13,4 +13,6 @@ echo "Added local endpoint" /usr/local/bin/fauna endpoint select local echo "Selected local endpoint" -/usr/local/bin/fauna create-database "$DB_NAME" +fauna create-database "$DB_NAME" + +echo "Created database" From 39d780a3e4228d660089f441bad57230a79e072e Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 19 Nov 2024 16:24:19 -0800 Subject: [PATCH 09/28] Remove default local env. --- test/local-project | 1 - 1 file changed, 1 deletion(-) diff --git a/test/local-project b/test/local-project index 6b1bc3e..2b5eb0d 100644 --- a/test/local-project +++ b/test/local-project @@ -1,3 +1,2 @@ schema_directory=schema -default=local From 4f45e5f8f1542fcf3e90571a2849572450802163 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 11:57:45 -0800 Subject: [PATCH 10/28] Disable interactivity for fauna command. --- test/setup.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/setup.sh b/test/setup.sh index 4816462..5307ce8 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -8,10 +8,8 @@ cp ./test/local-project .fauna-project echo "Copied .fauna-project" -/usr/local/bin/fauna endpoint add local --url "$LOCAL_ENDPOINT" --secret "$SECRET" +/usr/local/bin/fauna endpoint add local --non-interactive --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" echo "Added local endpoint" -/usr/local/bin/fauna endpoint select local -echo "Selected local endpoint" fauna create-database "$DB_NAME" From 4026008f359868f896a5166719763ffde00b251b Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 12:12:08 -0800 Subject: [PATCH 11/28] Use new fauna-shell syntax. --- test/http-client.env.json | 5 + test/requests.http | 423 ++++++++++++++++++++++++++++++++++++++ test/setup.sh | 2 +- 3 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 test/http-client.env.json create mode 100644 test/requests.http diff --git a/test/http-client.env.json b/test/http-client.env.json new file mode 100644 index 0000000..f81a90c --- /dev/null +++ b/test/http-client.env.json @@ -0,0 +1,5 @@ +{ + "dev": { + "host": "http://localhost:8080" + } +} \ No newline at end of file diff --git a/test/requests.http b/test/requests.http new file mode 100644 index 0000000..ed84c8b --- /dev/null +++ b/test/requests.http @@ -0,0 +1,423 @@ +### List Products +GET {{host}}/products?pageSize=1 +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response contains products", function() { + let jsonData = response.body; + client.assert(jsonData["data"][0]["name"] != "", "Must have a name"); + client.assert(jsonData["data"][0]["description"] != "", "Must have a description"); + client.global.set("productId", jsonData["data"][0]["id"]); + client.global.set("afterToken", encodeURIComponent(jsonData["after"])); + }); +%} + +### Paginate Products +GET {{host}}/products?pageSize=1&afterToken={{afterToken}} +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response contains products", function() { + let jsonData = response.body; + client.assert(jsonData["data"][0]["name"] != "", "Must have a name"); + client.assert(jsonData["data"][0]["description"] != "", "Must have a description"); + client.global.set("afterToken", encodeURIComponent(jsonData["after"])); + }); +%} + +### List Product Categories +GET {{host}}/products/categories +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response contains products", function() { + let jsonData = response.body; + let count = jsonData.length; + client.assert(count == 3, "Expected 3 categories, got " + count); + }); +%} + +### Search Products +GET {{host}}/products/search?minPrice=1000&maxPrice=10000 +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response contains products", function() { + let jsonData = response.body; + client.assert(jsonData != null, "Must have a product"); + client.assert(jsonData["data"][0]["name"] != "", "Must have a name"); + client.assert(jsonData["data"][0]["description"] != "", "Must have a description"); + }); +%} + +### Create Product +POST {{host}}/products +Accept: application/json +Content-Type: application/json + +{ + "name": "Coolest toy", + "description": "All the cool kids have one.", + "category": "electronics", + "price": 9999, + "quantity": 99 +} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a product", function() { + let jsonData = response.body; + client.assert(jsonData["name"] != "", "Must have a name"); + client.assert(jsonData["description"] != "", "Must have a description"); + client.global.set("productId", jsonData["id"]); + }); +%} + +### Update Product +POST {{host}}/products/{{productId}} +Accept: application/json +Content-Type: application/json + +{ + "name": "Coolest toy", + "description": "All the cool kids have one.", + "category": "electronics", + "price": 9999, + "quantity": 1 +} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a product", function() { + let jsonData = response.body; + client.assert(jsonData["name"] != "", "Must have a name"); + client.assert(jsonData["description"] != "", "Must have a description"); + }); +%} + +### Delete Product +DELETE {{host}}/products/{{productId}} +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 204", function() { + client.assert(response.status === 204, "Response status is not 200"); + }); +%} + +### Create Customer +POST {{host}}/customers +Accept: application/json +Content-Type: application/json + +{ + "name": "Natasha Romanoff", + "email": "natasha.romanoff@avengers.com", + "address": { + "street": "Avengers Tower", + "city": "New York", + "state": "NY", + "postalCode": "10001", + "country": "USA" + } +} + +> {% + client.test("Response status is 201", function() { + client.assert(response.status === 201, "Response status is not 201"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a Customer", function() { + let jsonData = response.body; + client.assert(jsonData["name"] != "", "Must have a name"); + client.assert(jsonData["email"] != "", "Must have an email"); + client.global.set("customerId", jsonData["id"]); + }); +%} + +### Get Customer +GET {{host}}/customers/{{customerId}} +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a Customer", function() { + let jsonData = response.body; + client.assert(jsonData["name"] != "", "Must have a name"); + client.assert(jsonData["email"] != "", "Must have an email"); + }); +%} + +### Update Customer + +POST {{host}}/customers/{{customerId}} +Accept: application/json +Content-Type: application/json + +{ + "name": "Natasha Romanoff", + "email": "natasha.romanoff@avengers.com", + "address": { + "street": "Avengers Compound", + "city": "Schroon Lake", + "state": "NY", + "postalCode": "12866", + "country": "USA" + } +} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200, got " + response.status); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a Customer", function() { + let jsonData = response.body; + client.assert(jsonData["name"] != "", "Must have a name"); + client.assert(jsonData["email"] != "", "Must have an email"); + client.global.set("customerId", jsonData["id"]); + }); +%} + +### Get Customer Orders +GET {{host}}/customers/{{customerId}}/orders +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + // client.test("Response contains orders", function() { + // let jsonData = response.body; + // client.assert(jsonData.length > 0, "Must have an order"); + // }); +%} + +### Create Cart for Customer +POST {{host}}/customers/{{customerId}}/cart +Accept: application/json +Content-Type: application/json + +{} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is a Cart", function() { + let jsonData = response.body; + client.assert(jsonData["customerId"] != "", "Must have a customerId"); + client.global.set("cartId", jsonData["id"]); + }); +%} + + +### Get Order +GET {{host}}/orders/{{cartId}} +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is an Order", function() { + let jsonData = response.body; + client.assert(jsonData["customerId"] != "", "Must have a customerId"); + }) +%} + +### Add Item to Cart +POST {{host}}/customers/{{customerId}}/cart/item +Accept: application/json +Content-Type: application/json + +{ + "productName": "Raspberry Pi", + "quantity": 1 +} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is an Order", function() { + let jsonData = response.body; + client.assert(jsonData["customerId"] != "", "Must have a customerId"); + }) +%} + + +### Get Cart +GET {{host}}/customers/{{customerId}}/cart +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + client.assert(response.contentType.mimeType == "application/json", "Response is not JSON"); + }); + + client.test("Response is an Order", function() { + let jsonData = response.body; + client.assert(jsonData["items"].length == 1, "Must have an item in the cart"); + }) +%} + +### Update Order +POST {{host}}/orders/{{cartId}} +Accept: application/json +Content-Type: application/json + +{ + "status": "processing", + "payment": { + "type": "card", + "number": "4111111111111111", + "expMonth": "12", + "expYear": "2025", + "cvc": "123" + } +} + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + }); + + client.test("Response is an Order", function() { + let jsonData = response.body; + client.assert(jsonData["customerId"] != "", "Must have a customerId"); + }); +%} + +### List Orders +GET {{host}}/orders/list +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 200", function() { + client.assert(response.status === 200, "Response status is not 200"); + }); + + client.test("Response is JSON", function() { + }); +%} + +### Delete Customer +DELETE {{host}}/customers/{{customerId}} +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 204", function() { + client.assert(response.status === 204, "Response status is not 204"); + }); +%} + +### Reset +POST {{host}}/reset +Accept: application/json +Content-Type: application/json + +> {% + client.test("Response status is 204", function() { + client.assert(response.status === 204, "Response status is not 204"); + }); +%} \ No newline at end of file diff --git a/test/setup.sh b/test/setup.sh index 5307ce8..9fb5cab 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -8,7 +8,7 @@ cp ./test/local-project .fauna-project echo "Copied .fauna-project" -/usr/local/bin/fauna endpoint add local --non-interactive --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" +/usr/local/bin/fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" echo "Added local endpoint" fauna create-database "$DB_NAME" From 8634c0462601c372b27b212c602b1d1ef47f6c5f Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 12:12:41 -0800 Subject: [PATCH 12/28] Add localClient bean. --- src/main/java/fauna/sample/AppConfig.java | 8 ++++++++ .../sample/controllers/products/ProductsController.java | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/fauna/sample/AppConfig.java b/src/main/java/fauna/sample/AppConfig.java index 0f86f33..cc2ea53 100644 --- a/src/main/java/fauna/sample/AppConfig.java +++ b/src/main/java/fauna/sample/AppConfig.java @@ -4,11 +4,13 @@ import com.fauna.client.FaunaClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; @Configuration class AppConfig { @Bean + @Profile("!local") FaunaClient faunaClient() { // Creates a `FaunaClient` with its default configuration. Note that by // default it looks for `FAUNA_ENDPOINT` and `FAUNA_SECRET` environment @@ -16,4 +18,10 @@ FaunaClient faunaClient() { // the endpoint is not set, it uses `https://db.fauna.com`. return Fauna.client(); } + + @Bean + @Profile("local") + FaunaClient localClient() { + return Fauna.local(); + } } \ No newline at end of file diff --git a/src/main/java/fauna/sample/controllers/products/ProductsController.java b/src/main/java/fauna/sample/controllers/products/ProductsController.java index 23ae2f4..de3715f 100644 --- a/src/main/java/fauna/sample/controllers/products/ProductsController.java +++ b/src/main/java/fauna/sample/controllers/products/ProductsController.java @@ -1,6 +1,7 @@ package fauna.sample.controllers.products; import com.fauna.client.FaunaClient; +import com.fauna.query.QueryOptions; import com.fauna.query.builder.Query; import com.fauna.response.QuerySuccess; import com.fauna.types.Page; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.time.Duration; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; @@ -90,7 +92,8 @@ Future> paginate( // as a parameter as well as an optional return type. In this case, we are // using the Product.class to specify that the query will return a single // item representing a Product. - return CompletableFuture.completedFuture(client.paginate(query, Product.class).next()); + return CompletableFuture.completedFuture(client.paginate(query, Product.class, + QueryOptions.builder().timeout(Duration.ofSeconds(30)).build()).next()); } @Async From 8229e8214029da134c8826164e202b8e9cb452c6 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 12:18:41 -0800 Subject: [PATCH 13/28] Run validate script! --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 833ed62..398f02f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,5 +26,7 @@ jobs: - name: Setup Test Database run: ./test/setup.sh - - name: Run sample app - run: ./gradlew build + - name: Test sample app + run: | + ./gradlew bootRun & + ./test/validate.sh \ No newline at end of file From 72a8252fbbc271a6b30b6cb0264079accafcea53 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 13:17:29 -0800 Subject: [PATCH 14/28] Add executable bit to validate.sh, and update .gitignore. --- .gitignore | 11 ++++++----- test/validate.sh | 0 2 files changed, 6 insertions(+), 5 deletions(-) mode change 100644 => 100755 test/validate.sh diff --git a/.gitignore b/.gitignore index ac4068c..2b86299 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,7 @@ build/ .env ### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ +.idea/* *.iws *.iml *.ipr @@ -40,4 +37,8 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +### Fauna ### +.fauna* + diff --git a/test/validate.sh b/test/validate.sh old mode 100644 new mode 100755 From 6c29a6eeb4a400699bca7922cc5031056fe397e9 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 13:52:36 -0800 Subject: [PATCH 15/28] Add retries to furst curl command, to allow for bootRun to finish. --- test/validate.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/validate.sh b/test/validate.sh index b999b72..4663a3b 100755 --- a/test/validate.sh +++ b/test/validate.sh @@ -2,6 +2,8 @@ ENDPOINT="http://localhost:8080" -curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer secret" "$ENDPOINT/products?pageSize=1" +curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer secret" \ + --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 --retry-max-time 60 \ + --retry-all-errors "$ENDPOINT/products?pageSize=1" From 4ff7a1421b262dba26fe1ba108545946c53cfc64 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 15:23:52 -0800 Subject: [PATCH 16/28] Create server key for ECommerceJava. --- .github/workflows/test.yml | 2 +- test/setup.sh | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 398f02f..dba1633 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,5 +28,5 @@ jobs: - name: Test sample app run: | - ./gradlew bootRun & + FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun & ./test/validate.sh \ No newline at end of file diff --git a/test/setup.sh b/test/setup.sh index 9fb5cab..466e106 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -8,9 +8,22 @@ cp ./test/local-project .fauna-project echo "Copied .fauna-project" -/usr/local/bin/fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" +fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" + echo "Added local endpoint" fauna create-database "$DB_NAME" -echo "Created database" +fauna environment add --name local --endpoint local --database $DB_NAME -y +fauna environment select local +fauna create-key --environment='' ECommerceJava server | grep "secret: " | sed 's/secret: //' | xargs > .fauna_key + +fauna schema push -y + +OUTPUT=""; +while [ `echo $OUTPUT | grep -c "Staged Status: ready"` = 0 ]; do + OUTPUT=`fauna schema status`; +done + +fauna schema commit -y + From c7f3771b8649d06a6486e0128934fe7ef1b3805e Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 15:36:30 -0800 Subject: [PATCH 17/28] Use eval to create key. --- test/setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/setup.sh b/test/setup.sh index 466e106..080e539 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -16,8 +16,9 @@ fauna create-database "$DB_NAME" fauna environment add --name local --endpoint local --database $DB_NAME -y fauna environment select local -fauna create-key --environment='' ECommerceJava server | grep "secret: " | sed 's/secret: //' | xargs > .fauna_key +fauna eval "Key.create({ role: 'server' }).secret" | xargs > .fauna_key +echo "Created key" fauna schema push -y OUTPUT=""; From 0aaecd4fc9380b5c484f673e8fb51b1058a85a91 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 15:41:44 -0800 Subject: [PATCH 18/28] Silly typo! --- test/setup.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/setup.sh b/test/setup.sh index 080e539..8113cf4 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -4,8 +4,6 @@ DB_NAME="ECommerceJava" LOCAL_ENDPOINT="http://localhost:8443/" SECRET="secret" -cp ./test/local-project .fauna-project - echo "Copied .fauna-project" fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" @@ -18,11 +16,10 @@ fauna environment add --name local --endpoint local --database $DB_NAME -y fauna environment select local fauna eval "Key.create({ role: 'server' }).secret" | xargs > .fauna_key -echo "Created key" fauna schema push -y OUTPUT=""; -while [ `echo $OUTPUT | grep -c "Staged Status: ready"` = 0 ]; do +while [ `echo $OUTPUT | grep -c "Staged status: ready"` = 0 ]; do OUTPUT=`fauna schema status`; done From 47d18051a0224a431cabe872e72648015a99db59 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 15:47:13 -0800 Subject: [PATCH 19/28] Add back fauna-project. --- test/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/setup.sh b/test/setup.sh index 8113cf4..ed11a13 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -4,13 +4,14 @@ DB_NAME="ECommerceJava" LOCAL_ENDPOINT="http://localhost:8443/" SECRET="secret" +cp ./test/local-project .fauna-project echo "Copied .fauna-project" fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" - echo "Added local endpoint" fauna create-database "$DB_NAME" +echo "Created database $DB_NAME" fauna environment add --name local --endpoint local --database $DB_NAME -y fauna environment select local @@ -23,5 +24,4 @@ while [ `echo $OUTPUT | grep -c "Staged status: ready"` = 0 ]; do OUTPUT=`fauna schema status`; done -fauna schema commit -y - +fauna schema commit -y \ No newline at end of file From ede9cda40b521535769081a6ca94d75b8eecdacb Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 15:55:50 -0800 Subject: [PATCH 20/28] Add logs for bootRun. --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dba1633..061fc91 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,5 +28,6 @@ jobs: - name: Test sample app run: | - FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun & - ./test/validate.sh \ No newline at end of file + FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun 2>&1 > bootrun.log & + ./test/validate.sh + cat bootrun.log \ No newline at end of file From ec24db9231920c2634dc1df6c18ee1b65151005b Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 20 Nov 2024 16:01:04 -0800 Subject: [PATCH 21/28] Increase retry delay. --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 061fc91..64d1d25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,7 @@ jobs: - name: Test sample app run: | - FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun 2>&1 > bootrun.log & + ./gradlew build + FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun > bootrun.log 2>&1 & ./test/validate.sh cat bootrun.log \ No newline at end of file From 2087bf57bc37f975663698ec2b9d0d329baf442e Mon Sep 17 00:00:00 2001 From: David Griffin Date: Thu, 21 Nov 2024 11:51:19 -0800 Subject: [PATCH 22/28] Use import and eval to hydrate collections. --- seed/categories.json | 17 +++++++++++++++++ seed/customers.json | 13 +++++++++++++ seed/orders.fql | 39 ++++++++++++++++----------------------- seed/products.fql | 30 +++++++++++++++--------------- test/setup.sh | 7 ++++++- test/validate.sh | 2 +- 6 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 seed/categories.json create mode 100644 seed/customers.json diff --git a/seed/categories.json b/seed/categories.json new file mode 100644 index 0000000..9adeee8 --- /dev/null +++ b/seed/categories.json @@ -0,0 +1,17 @@ +[ + { + "id": 1, + "name": "electronics", + "description": "bargain electronics" + }, + { + "id": 2, + "name": "books", + "description": "bargain books" + }, + { + "id": 3, + "name": "movies", + "description": "bargain movies" + } +] diff --git a/seed/customers.json b/seed/customers.json new file mode 100644 index 0000000..0c70300 --- /dev/null +++ b/seed/customers.json @@ -0,0 +1,13 @@ +[ + { + "name": "Valued Customer", + "email": "fake@fauna.com", + "address": { + "street": "Herengracht", + "city": "Amsterdam", + "state": "North Holland", + "postalCode": "1015BT", + "country": "Netherlands" + } + } +] diff --git a/seed/orders.fql b/seed/orders.fql index 0b1fd0f..3a4bab8 100644 --- a/seed/orders.fql +++ b/seed/orders.fql @@ -1,23 +1,16 @@ -{ - "query": " - let customer = Customer.byEmail('fake@fauna.com').first()!\n - let orders = ['cart', 'processing', 'shipped', 'delivered'].map(status => {\n - let order: Any = Order.byCustomer(customer).firstWhere(o => o.status == status)\n - if (order == null) {\n - let newOrder: Any = Order.create({\n - customer: customer,\n - status: status,\n - createdAt: Time.now(),\n - payment: {}\n - })\n - let product: Any = Product.byName('Drone').first()!\n - let orderItem: Any = OrderItem.create({ order: newOrder, product: product, quantity: 1 })\n - orderItem\n - newOrder\n - } else {\n - order\n - }\n - })\n - orders - " -} +let customer = Customer.byEmail('fake@fauna.com').first()! +['cart', 'processing', 'shipped', 'delivered'].map(status => { + let order: Any = Order.byCustomer(customer).firstWhere(o => o.status == status) + if (order == null) { + let newOrder: Any = Order.create({ + customer: customer, + status: status, + createdAt: Time.now(), payment: {} + }) + + let product: Any = Product.byName('Drone').first()! + let orderItem: Any = OrderItem.create( {order: newOrder, product: product, quantity: 1 }) + orderItem + newOrder + } else { order } +}) diff --git a/seed/products.fql b/seed/products.fql index d177df3..1014949 100644 --- a/seed/products.fql +++ b/seed/products.fql @@ -1,4 +1,4 @@ -{"query":"[ +[ { 'name': 'iPhone', 'price': 10000, @@ -62,17 +62,17 @@ 'stock': 10, 'category': 'movies' } -].map(p => {\n - let existing: Any = Product.byName(p.name).first()\n - if (existing != null) {\n - existing!.update({ stock: p.stock })\n - } else {\n - Product.create({\n - name: p.name,\n - price: p.price,\n - description: p.description,\n - stock: p.stock,\n - category: Category.byName(p.category).first()!\n - })\n - }\n -}\n)"} +].map(p => { + let existing: Any = Product.byName(p.name).first() + if (existing != null) { + existing!.update({ stock: p.stock }) + } else { + Product.create({ + name: p.name, + price: p.price, + description: p.description, + stock: p.stock, + category: Category.byName(p.category).first()! + }) + } +}) diff --git a/test/setup.sh b/test/setup.sh index ed11a13..7cece7b 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -24,4 +24,9 @@ while [ `echo $OUTPUT | grep -c "Staged status: ready"` = 0 ]; do OUTPUT=`fauna schema status`; done -fauna schema commit -y \ No newline at end of file +fauna schema commit -y + +fauna import --collection Category --path seed/categories.json +fauna import --collection Customer --path seed/customers.json +fauna eval --file seed/products.fql +fauna eval --file seed/orders.fql diff --git a/test/validate.sh b/test/validate.sh index 4663a3b..79b4011 100755 --- a/test/validate.sh +++ b/test/validate.sh @@ -3,7 +3,7 @@ ENDPOINT="http://localhost:8080" curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer secret" \ - --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 --retry-max-time 60 \ + --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 10 --retry-max-time 60 \ --retry-all-errors "$ENDPOINT/products?pageSize=1" From 732152921b24c41d823c7446998556de08b93a16 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Thu, 21 Nov 2024 11:53:56 -0800 Subject: [PATCH 23/28] Let fauna set Category IDs. --- seed/categories.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/seed/categories.json b/seed/categories.json index 9adeee8..68c8183 100644 --- a/seed/categories.json +++ b/seed/categories.json @@ -1,16 +1,13 @@ [ { - "id": 1, "name": "electronics", "description": "bargain electronics" }, { - "id": 2, "name": "books", "description": "bargain books" }, { - "id": 3, "name": "movies", "description": "bargain movies" } From 8e79c9df21f7dd73fcb208ca547841e8d865f772 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Thu, 21 Nov 2024 15:10:24 -0800 Subject: [PATCH 24/28] Add some more requests to validate script. --- test/validate.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/validate.sh b/test/validate.sh index 79b4011..f0c2b43 100755 --- a/test/validate.sh +++ b/test/validate.sh @@ -1,9 +1,27 @@ #! /bin/sh ENDPOINT="http://localhost:8080" +ACCEPT="Accept: application/json" +CONTENT="Content-Type: application/json" -curl -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer secret" \ +curl --silent -H "$ACCEPT" -H "$CONTENT" --retry-all-errors \ --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 10 --retry-max-time 60 \ - --retry-all-errors "$ENDPOINT/products?pageSize=1" + "$ENDPOINT/products?pageSize=1" > page_one.json +cat one.json +AFTER=`jq '.after | .token' page_one.json | xargs` + +curl --silent -H "$ACCEPT" -H "$CONTENT" --silent \ + "$ENDPOINT/products?pageSize=1&afterToken=$AFTER" > page_two.json + +jq '.data | .[] | .name' page_two.json + +curl --silent -H "$ACCEPT" -H "$CONTENT" "$ENDPOINT/products/search?minPrice=1000&maxPrice=10000" > search.json + +jq '.data | .[] | .name' search.json + +NEW_PRODUCT="{ \"name\": \"Coolest toy\", \"description\": \"All the cool kids have one.\", + \"category\": \"electronics\", \"price\": 9999, \"stock\": 99 }" + +# curl --silent -H "$ACCEPT" -H "$CONTENT" -X POST "$ENDPOINT/products" -d "$NEW_PRODUCT" From 21a262352605d526e9ff20bef347c8cae8b46050 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 3 Dec 2024 09:17:28 -0800 Subject: [PATCH 25/28] Update .gitignore to ignore.idea folder. Co-authored-by: Darren Cunningham --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2b86299..82058ba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ build/ .env ### IntelliJ IDEA ### -.idea/* +.idea/ *.iws *.iml *.ipr From 107c06cc1edc13d710184366a91e8f48f43f3e0e Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 3 Dec 2024 14:11:34 -0800 Subject: [PATCH 26/28] Simplify script by using --active flag. --- test/setup.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/setup.sh b/test/setup.sh index 7cece7b..814d5f3 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -17,14 +17,7 @@ fauna environment add --name local --endpoint local --database $DB_NAME -y fauna environment select local fauna eval "Key.create({ role: 'server' }).secret" | xargs > .fauna_key -fauna schema push -y - -OUTPUT=""; -while [ `echo $OUTPUT | grep -c "Staged status: ready"` = 0 ]; do - OUTPUT=`fauna schema status`; -done - -fauna schema commit -y +fauna schema push -y --active fauna import --collection Category --path seed/categories.json fauna import --collection Customer --path seed/customers.json From ace19197d5a0443b07f6ed545a0b827cc63af19c Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 3 Dec 2024 14:13:39 -0800 Subject: [PATCH 27/28] Remove setup.sh. --- setup.sh | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100755 setup.sh diff --git a/setup.sh b/setup.sh deleted file mode 100755 index 81c0021..0000000 --- a/setup.sh +++ /dev/null @@ -1,10 +0,0 @@ - -EP="${FAUNA_ENDPOINT:-https://db.fauna.com}" - -cat seed/categories.fql | curl -X POST -u "$FAUNA_SECRET": "$EP/query/1" -H 'Content-Type: application/json' -d@- -echo -e "\n\n" -cat seed/customers.fql | curl -X POST -u "$FAUNA_SECRET": "$EP/query/1" -H 'Content-Type: application/json' -d@- -echo -e "\n\n" -cat seed/products.fql | curl -X POST -u "$FAUNA_SECRET": "$EP/query/1" -H 'Content-Type: application/json' -d@- -echo -e "\n\n" -cat seed/orders.fql | curl -X POST -u "$FAUNA_SECRET": "$EP/query/1" -H 'Content-Type: application/json' -d@- From aa09dee64219e6cd56e8531c06709f7625e35dc4 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Tue, 3 Dec 2024 14:38:05 -0800 Subject: [PATCH 28/28] Replace directory in fauna-project file with --dir flag. --- test/local-project | 2 -- test/setup.sh | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 test/local-project diff --git a/test/local-project b/test/local-project deleted file mode 100644 index 2b5eb0d..0000000 --- a/test/local-project +++ /dev/null @@ -1,2 +0,0 @@ -schema_directory=schema - diff --git a/test/setup.sh b/test/setup.sh index 814d5f3..bfd81de 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -4,8 +4,7 @@ DB_NAME="ECommerceJava" LOCAL_ENDPOINT="http://localhost:8443/" SECRET="secret" -cp ./test/local-project .fauna-project -echo "Copied .fauna-project" +touch .fauna-project fauna endpoint add local -y --set-default --url "$LOCAL_ENDPOINT" --secret "$SECRET" echo "Added local endpoint" @@ -17,7 +16,7 @@ fauna environment add --name local --endpoint local --database $DB_NAME -y fauna environment select local fauna eval "Key.create({ role: 'server' }).secret" | xargs > .fauna_key -fauna schema push -y --active +fauna schema push -y --active --dir=schema fauna import --collection Category --path seed/categories.json fauna import --collection Customer --path seed/customers.json