Skip to content

Commit 15d273f

Browse files
authored
add test workflow (#57)
1 parent 65c1e38 commit 15d273f

File tree

4 files changed

+212
-1
lines changed

4 files changed

+212
-1
lines changed

.github/workflows/test.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: run tests
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: 'read'
10+
id-token: 'write'
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Authenticate to Google Cloud
15+
id: auth
16+
uses: google-github-actions/auth@v1
17+
with:
18+
token_format: access_token
19+
workload_identity_provider: projects/949875736540/locations/global/workloadIdentityPools/external-pool/providers/github-provider
20+
service_account: [email protected]
21+
- name: Login to GAR
22+
uses: docker/login-action@v3
23+
with:
24+
registry: europe-west3-docker.pkg.dev
25+
username: oauth2accesstoken
26+
password: ${{ steps.auth.outputs.access_token }}
27+
- uses: hoverkraft-tech/[email protected]
28+
- name: Set up Java
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: 'temurin'
32+
java-version: '21'
33+
cache: 'gradle'
34+
- name: Install dependencies
35+
run: |
36+
sudo apt-get install jq curl
37+
- name: Run example
38+
run: |
39+
echo "running example";
40+
sleep 5;
41+
docker compose logs;
42+
curl --location "http://localhost:9000/v1/users"
43+
44+
ACCOUNT_RESPONSE=$(curl -s --location "http://localhost:9000/v1/accounts" \
45+
--header "Content-Type: application/json" \
46+
--data-raw '{
47+
"companyName": "demo",
48+
"email": "[email protected]",
49+
"password": "Password1234!"
50+
}');
51+
export TALON_USER_ID=$(echo $ACCOUNT_RESPONSE | jq ".userId");
52+
export TALON_USER_TOKEN=$(echo $ACCOUNT_RESPONSE | jq ".token" | tr -d '"');
53+
USER_RESPONSE=$(curl -s --location "http://localhost:9000/v1/users/$TALON_USER_ID" \
54+
--header "Authorization: Bearer $TALON_USER_TOKEN");
55+
export TALON_ACCOUNT_ID=$(echo $USER_RESPONSE | jq ".accountId");
56+
echo "User with ID $TALON_USER_ID and Token $TALON_USER_TOKEN was created for application $TALON_ACCOUNT_ID";
57+
APPLICATION_RESPONSE=$(curl -s --location "http://localhost:9000/v1/applications" \
58+
--header "Content-Type: application/json" \
59+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
60+
--data-raw '{
61+
"name": "demo",
62+
"currency": "EUR",
63+
"timezone": "Europe/Berlin",
64+
"enableFlattenedCartItems": false
65+
}');
66+
export TALON_APPLICATION_ID=$(echo $USER_RESPONSE | jq ".id");
67+
echo "Application with ID $TALON_APPLICATION_ID was created"
68+
API_KEY_RESPONSE=$(curl -s -v --location "http://localhost:9000/v1/applications/$TALON_APPLICATION_ID/apikeys" \
69+
--header "Content-Type: application/json" \
70+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
71+
--data-raw '{
72+
"title": "Application HIT KEY",
73+
"expires": "2099-01-01T0:00:00Z"
74+
}');
75+
echo "Api-Key-Response: $API_KEY_RESPONSE";
76+
export TALON_API_KEY=$(echo $API_KEY_RESPONSE | jq ".key" | tr -d '"');
77+
echo "Api-Key $TALON_API_KEY created";
78+
79+
echo "maven install";
80+
mvn clean install;
81+
export CLASSPATH=.:./target/lib/gson-2.8.9.jar:./target/talon-one-client-9.1.0.jar:./target/lib/okio-1.17.2.jar:./target/lib/okhttp-3.14.7.jar:./target/lib/threetenbp-1.4.3.jar:./target/lib/gson-fire-1.8.4.jar;
82+
83+
echo "java compile";
84+
javac -d . Example.java;
85+
86+
echo "java execute";
87+
java com.example.consumer.Example;

Example.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.example.consumer;
2+
3+
import com.google.gson.Gson;
4+
5+
import one.talon.ApiClient;
6+
import one.talon.api.IntegrationApi;
7+
import one.talon.api.ManagementApi;
8+
import one.talon.model.*;
9+
10+
import java.util.*;
11+
12+
public class Example {
13+
public static void main(String[] args) throws Exception {
14+
Gson gson = new Gson();
15+
IntegrationApi iApi = new IntegrationApi(new ApiClient("api_key_v1"));
16+
17+
// Setup: basePath
18+
iApi.getApiClient().setBasePath("http://localhost:9000");
19+
// Setup: when using 'api_key_v1', set apiKey & apiKeyPrefix must be provided
20+
iApi.getApiClient().setApiKeyPrefix("ApiKey-v1");
21+
iApi.getApiClient().setApiKey(System.getenv("TALON_API_KEY"));
22+
23+
// Creating a cart item object
24+
CartItem cartItem = new CartItem();
25+
cartItem.setName("Hawaiian Pizza");
26+
cartItem.setSku("pizza-x");
27+
cartItem.setQuantity(1);
28+
cartItem.setPrice(new java.math.BigDecimal("5.5"));
29+
30+
// Creating a customer session of V2
31+
NewCustomerSessionV2 customerSession = new NewCustomerSessionV2();
32+
customerSession.setProfileId("Cool_Dude");
33+
customerSession.addCouponCodesItem("Cool-Summer!");
34+
customerSession.addCartItemsItem(cartItem);
35+
36+
// Initiating integration request wrapping the customer session update
37+
IntegrationRequest request = new IntegrationRequest()
38+
.customerSession(customerSession)
39+
// Optional parameter of requested information to be present on the response related to the customer session update
40+
.responseContent(Arrays.asList(
41+
IntegrationRequest.ResponseContentEnum.CUSTOMERSESSION,
42+
IntegrationRequest.ResponseContentEnum.CUSTOMERPROFILE
43+
));
44+
45+
// Flag to communicate whether the request is a "dry run"
46+
Boolean dryRun = false;
47+
48+
// Create/update a customer session using `updateCustomerSessionV2` function
49+
IntegrationStateV2 is = iApi.updateCustomerSessionV2("deetdoot", request, dryRun, null);
50+
System.out.println(is.toString());
51+
52+
// Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties
53+
for (Effect eff : is.getEffects()) {
54+
if (eff.getEffectType().equals("addLoyaltyPoints")) {
55+
// Typecasting according to the specific effect type
56+
AddLoyaltyPointsEffectProps props = gson.fromJson(
57+
gson.toJson(eff.getProps()),
58+
AddLoyaltyPointsEffectProps.class
59+
);
60+
// Access the specific effect's properties
61+
System.out.println(props.getName());
62+
System.out.println(props.getProgramId());
63+
System.out.println(props.getValue());
64+
}
65+
if (eff.getEffectType().equals("acceptCoupon")) {
66+
// Typecasting according to the specific effect type
67+
AcceptCouponEffectProps props = gson.fromJson(
68+
gson.toJson(eff.getProps()),
69+
AcceptCouponEffectProps.class
70+
);
71+
// work with AcceptCouponEffectProps' properties
72+
// ...
73+
}
74+
}
75+
}
76+
}

docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
services:
2+
api-service:
3+
image: europe-west3-docker.pkg.dev/talon-artifacts/talon-images/talon-service:master
4+
depends_on:
5+
- database-service
6+
ports:
7+
- "9000:9000"
8+
environment:
9+
- TALON_DB_NAME=talon
10+
- TALON_DB_USER=talon
11+
- TALON_DB_PASSWORD=talon.one.9000
12+
- TALON_DB_HOST=database-service
13+
- TALON_DB_PORT=5432
14+
- TALON_ENABLE_WEBHOOK_WORKER_POOL=false
15+
- TZ=UTC
16+
- RELEASE_STAGE=ci
17+
- TALON_CH_ENABLED=false
18+
- TALON_DISABLE_PROFILER=true
19+
- USE_REPLICA_DB=false
20+
command:
21+
- /talon/talon
22+
healthcheck:
23+
test: ["CMD", "curl", "-f", "http://localhost:9000/v1/status/health"]
24+
interval: 10s
25+
timeout: 5s
26+
retries: 10
27+
restart: "on-failure:10"
28+
29+
database-service:
30+
image: docker.io/bitnami/postgresql:15
31+
volumes:
32+
- 'postgresql_master_data:/bitnami/postgresql'
33+
ports:
34+
- "5433:5432"
35+
environment:
36+
- POSTGRESQL_DATABASE=talon
37+
- POSTGRESQL_USERNAME=talon
38+
- POSTGRESQL_PASSWORD=talon.one.9000
39+
healthcheck:
40+
test: ["CMD-SHELL", "pg_isready -U talon -d talon"]
41+
interval: 10s
42+
timeout: 5s
43+
retries: 5
44+
restart: "on-failure:10"
45+
46+
volumes:
47+
postgresql_master_data:
48+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@
280280
</dependency>
281281
</dependencies>
282282
<properties>
283-
<java.version>1.7</java.version>
283+
<java.version>21</java.version>
284284
<maven.compiler.source>${java.version}</maven.compiler.source>
285285
<maven.compiler.target>${java.version}</maven.compiler.target>
286286
<gson-fire-version>1.8.4</gson-fire-version>

0 commit comments

Comments
 (0)