Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tests as GitHub workflow #23

Merged
merged 28 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ 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: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: corretto
- name: Install fauna-shell
run:
npm install -g fauna-shell
- name: Setup Test Database
run: ./test/setup.sh

- name: Run sample app
run: ./gradlew build
- name: Test sample app
run: |
./gradlew build
FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun > bootrun.log 2>&1 &
./test/validate.sh
cat bootrun.log
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ build/
.env

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/*
findgriffin marked this conversation as resolved.
Show resolved Hide resolved
*.iws
*.iml
*.ipr
Expand Down Expand Up @@ -40,4 +37,8 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

### Fauna ###
.fauna*

Comment on lines +41 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check with the Fauna shell team to be sure no files are intended to be checked in when working on a team.

14 changes: 14 additions & 0 deletions seed/categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "electronics",
"description": "bargain electronics"
},
{
"name": "books",
"description": "bargain books"
},
{
"name": "movies",
"description": "bargain movies"
}
]
13 changes: 13 additions & 0 deletions seed/customers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"name": "Valued Customer",
"email": "fake@fauna.com",
"address": {
"street": "Herengracht",
"city": "Amsterdam",
"state": "North Holland",
"postalCode": "1015BT",
"country": "Netherlands"
}
}
]
39 changes: 16 additions & 23 deletions seed/orders.fql
Original file line number Diff line number Diff line change
@@ -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 }
})
30 changes: 15 additions & 15 deletions seed/products.fql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"query":"[
[
{
'name': 'iPhone',
'price': 10000,
Expand Down Expand Up @@ -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()!
})
}
})
8 changes: 8 additions & 0 deletions src/main/java/fauna/sample/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
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
// variables in oder to determine which endpoint and secret ot use. If
// the endpoint is not set, it uses `https://db.fauna.com`.
return Fauna.client();
}

@Bean
@Profile("local")
FaunaClient localClient() {
return Fauna.local();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -90,7 +92,8 @@ Future<Page<Product>> 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
Expand Down
5 changes: 5 additions & 0 deletions test/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dev": {
"host": "http://localhost:8080"
}
}
2 changes: 2 additions & 0 deletions test/local-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema_directory=schema

Loading