Skip to content

Commit 34801be

Browse files
committedDec 2, 2024·
add test workflow
1 parent bc905fb commit 34801be

File tree

6 files changed

+232
-2
lines changed

6 files changed

+232
-2
lines changed
 

‎.github/.example/.example.csproj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>_example</RootNamespace>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Reference Include="TalonOne">
10+
<HintPath>../../src/TalonOne/bin/Debug/netstandard2.0/TalonOne.dll</HintPath>
11+
</Reference>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
15+
<PackageReference Include="RestSharp" Version="106.15.0" />
16+
</ItemGroup>
17+
</Project>

‎.github/.example/Program.cs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
using TalonOne.Api;
4+
using TalonOne.Client;
5+
using TalonOne.Model;
6+
7+
namespace _example
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
// Configure BasePath & API key authorization: api_key_v1
14+
var integrationConfig = new Configuration {
15+
BasePath = "http://localhost:9000",
16+
ApiKey = new Dictionary<string, string> {
17+
{ "Authorization", System.Environment.GetEnvironmentVariable("TALON_API_KEY") }
18+
},
19+
ApiKeyPrefix = new Dictionary<string, string> {
20+
{ "Authorization", "ApiKey-v1" }
21+
}
22+
};
23+
24+
// ************************************************
25+
// Integration API example to send a session update
26+
// ************************************************
27+
28+
// When using the default approach, the next initiation of `IntegrationApi`
29+
// could be using the empty constructor
30+
var integrationApi = new IntegrationApi(integrationConfig);
31+
var customerSessionId = "my_unique_session_integration_id_2"; // string | The custom identifier for this session, must be unique within the account.
32+
33+
// Preparing a NewCustomerSessionV2 object
34+
NewCustomerSessionV2 customerSession = new NewCustomerSessionV2 {
35+
ProfileId = "PROFILE_ID",
36+
CouponCodes = new List<string> {
37+
"Cool-Stuff-2020"
38+
},
39+
CartItems = new List<CartItem> {
40+
new CartItem(
41+
name: "Hummus Tahini",
42+
sku: "hum-t",
43+
quantity: 1,
44+
price: (decimal)5.5,
45+
category: "Food"
46+
),
47+
new CartItem(
48+
name: "Iced Mint Lemonade",
49+
sku: "ice-mn-lemon",
50+
quantity: 1,
51+
price: (decimal)3.5,
52+
category: "Beverages"
53+
)
54+
}
55+
};
56+
57+
// Instantiating an IntegrationRequest object
58+
IntegrationRequest body = new IntegrationRequest(
59+
customerSession
60+
// Optional list of requested information to be present on the response.
61+
// See src/TalonOne/Model/IntegrationRequest#ResponseContentEnum for full list of supported values
62+
// new List<IntegrationRequest.ResponseContentEnum> {
63+
// IntegrationRequest.ResponseContentEnum.CustomerSession,
64+
// IntegrationRequest.ResponseContentEnum.CustomerProfile
65+
// }
66+
);
67+
68+
// Create/update a customer session using `UpdateCustomerSessionV2` function
69+
IntegrationStateV2 response = integrationApi.UpdateCustomerSessionV2(customerSessionId, body);
70+
Debug.WriteLine(response);
71+
72+
// 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
73+
foreach (Effect effect in response.Effects) {
74+
switch(effect.EffectType) {
75+
case "setDiscount":
76+
// Initiating right props instance according to the effect type
77+
SetDiscountEffectProps setDiscountEffectProps = (SetDiscountEffectProps) Newtonsoft.Json.JsonConvert.DeserializeObject(effect.Props.ToString(), typeof(SetDiscountEffectProps));
78+
79+
// Access the specific effect's properties
80+
Debug.WriteLine("Set a discount '{0}' of {1:00.000}", setDiscountEffectProps.Name, setDiscountEffectProps.Value);
81+
break;
82+
// case "acceptCoupon":
83+
// AcceptCouponEffectProps acceptCouponEffectProps = (AcceptCouponEffectProps) Newtonsoft.Json.JsonConvert.DeserializeObject(effect.Props.ToString(), typeof(AcceptCouponEffectProps));
84+
85+
// Work with AcceptCouponEffectProps' properties
86+
// ...
87+
// break;
88+
default:
89+
Debug.WriteLine("Encounter unknown effect type: {0}", effect.EffectType);
90+
break;
91+
}
92+
}
93+
}
94+
}
95+
}

‎.github/workflows/test.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on: [push]
2+
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
permissions:
7+
contents: 'read'
8+
id-token: 'write'
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Authenticate to Google Cloud
13+
id: auth
14+
uses: google-github-actions/auth@v1
15+
with:
16+
token_format: access_token
17+
workload_identity_provider: projects/949875736540/locations/global/workloadIdentityPools/external-pool/providers/github-provider
18+
service_account: artifact-pusher@talon-artifacts.iam.gserviceaccount.com
19+
- name: Login to GAR
20+
uses: docker/login-action@v3
21+
with:
22+
registry: europe-west3-docker.pkg.dev
23+
username: oauth2accesstoken
24+
password: ${{ steps.auth.outputs.access_token }}
25+
- uses: hoverkraft-tech/compose-action@v2.0.2
26+
- uses: actions/setup-dotnet@v4
27+
with:
28+
dotnet-version: '8.0'
29+
- name: Build DLL
30+
run: dotnet build TalonOne.sln
31+
- name: Install dependencies
32+
run: |
33+
sudo apt-get install jq curl
34+
- name: Run example
35+
working-directory: .github/.example
36+
run: |
37+
ACCOUNT_RESPONSE=$(curl -s --location "http://localhost:9000/v1/accounts" \
38+
--header "Content-Type: application/json" \
39+
--data-raw '{
40+
"companyName": "demo",
41+
"email": "integrationtest@talon.one",
42+
"password": "Password1234!"
43+
}');
44+
export TALON_USER_ID=$(echo $ACCOUNT_RESPONSE | jq ".userId");
45+
export TALON_USER_TOKEN=$(echo $ACCOUNT_RESPONSE | jq ".token" | tr -d '"');
46+
USER_RESPONSE=$(curl -s --location "http://localhost:9000/v1/users/$TALON_USER_ID" \
47+
--header "Authorization: Bearer $TALON_USER_TOKEN");
48+
export TALON_ACCOUNT_ID=$(echo $USER_RESPONSE | jq ".accountId");
49+
echo "User with ID $TALON_USER_ID and Token $TALON_USER_TOKEN was created for application $TALON_ACCOUNT_ID";
50+
APPLICATION_RESPONSE=$(curl -s --location "http://localhost:9000/v1/applications" \
51+
--header "Content-Type: application/json" \
52+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
53+
--data-raw '{
54+
"name": "demo",
55+
"currency": "EUR",
56+
"timezone": "Europe/Berlin",
57+
"enableFlattenedCartItems": false
58+
}');
59+
export TALON_APPLICATION_ID=$(echo $USER_RESPONSE | jq ".id");
60+
echo "Application with ID $TALON_APPLICATION_ID was created"
61+
API_KEY_RESPONSE=$(curl -s -v --location "http://localhost:9000/v1/applications/$TALON_APPLICATION_ID/apikeys" \
62+
--header "Content-Type: application/json" \
63+
--header "Authorization: Bearer $TALON_USER_TOKEN" \
64+
--data-raw '{
65+
"title": "Application HIT KEY",
66+
"expires": "2099-01-01T0:00:00Z"
67+
}');
68+
echo "Api-Key-Response: $API_KEY_RESPONSE";
69+
export TALON_API_KEY=$(echo $API_KEY_RESPONSE | jq ".key" | tr -d '"');
70+
echo "Api-Key $TALON_API_KEY created"
71+
dotnet run;

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BUILD_DIR:=src/TalonOne
22
VERSION:=$(shell grep -om1 -E '^\[assembly: AssemblyVersion\("[0-9\.]+"\)\]$$' $(PWD)/$(BUILD_DIR)/Properties/AssemblyInfo.cs | sed 's/\[assembly: AssemblyVersion("\(.*\)")\]/\1/')
3-
DOCKER_TAG_ARCH:=$(shell [[ $(shell uname -m) == "arm64" ]] && echo "3.1-focal-arm64v8" || echo "sdk:3.1-focal")
3+
DOCKER_TAG_ARCH:=$(shell [[ $(shell uname -m) == "arm64" ]] && echo "8.0-focal-arm64v8" || echo "sdk:8.0-focal")
44

55
default: testenv
66

‎docker-compose.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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:

‎src/TalonOne.Test/TalonOne.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Contact: devs@talon.one
1313
<AppDesignerFolder>Properties</AppDesignerFolder>
1414
<RootNamespace>TalonOne.Test</RootNamespace>
1515
<AssemblyName>TalonOne.Test</AssemblyName>
16-
<TargetFramework>netcoreapp3.1</TargetFramework>
16+
<TargetFramework>net8.0</TargetFramework>
1717
<IsPackable>false</IsPackable>
1818
<FileAlignment>512</FileAlignment>
1919
</PropertyGroup>

0 commit comments

Comments
 (0)
Please sign in to comment.