Skip to content

Commit

Permalink
chore: run consent test in tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Oct 25, 2023
1 parent 6f5ae95 commit d9b0bcd
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 145 deletions.
120 changes: 0 additions & 120 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tilt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Tilt CI
run: nix develop -c bash -c "cd dev && tilt ci"
run: nix develop -c bash -c "cd dev && tilt ci -- -test consent | tee tilt.log | grep test"
17 changes: 17 additions & 0 deletions apps/consent/BUCK
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
load("@toolchains//workspace-pnpm:macros.bzl",
"dev_pnpm_task_binary",
"dev_pnpm_task_test",
"build_node_modules",
"next_build",
"next_build_bin",
"eslint"
)

dev_pnpm_task_binary(
name = "dev",
command = "dev",
)

dev_pnpm_task_binary(
name = "open-cypress",
command = "cypress:open",
)

dev_pnpm_task_test(
name = "cypress",
command = "cypress:run",
)

export_file(
name = "package.json",
visibility = ["PUBLIC"],
Expand Down
8 changes: 3 additions & 5 deletions apps/consent/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { defineConfig } from "cypress"
import dotenv from "dotenv"
dotenv.config()
dotenv.config({ path: ".env.test" })
dotenv.config({ path: "../../dev/.envs/consent.env" })

export default defineConfig({
e2e: {
baseUrl: "http://127.0.0.1:3000",
// setupNodeEvents(on, config) {},
baseUrl: "http://localhost:3000",
},
defaultCommandTimeout: 60000,
env: {
...process.env,
AUTHORIZATION_URL: process.env.AUTHORIZATION_URL,
},
component: {
devServer: {
Expand Down
2 changes: 1 addition & 1 deletion apps/consent/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare namespace Cypress {
}

Cypress.Commands.add("getOTP", (email) => {
const query = `docker exec -i api-kratos-pg-1 psql -U dbuser -d default -t -c "SELECT body FROM courier_messages WHERE recipient='${email}' ORDER BY created_at DESC LIMIT 1;"`
const query = `docker exec -i galoy-dev-kratos-pg-1 psql -U dbuser -d default -t -c "SELECT body FROM courier_messages WHERE recipient='${email}' ORDER BY created_at DESC LIMIT 1;"`
cy.exec(query).then((result) => {
const rawMessage = result.stdout
const otpMatch = rawMessage.match(/(\d{6})/)
Expand Down
4 changes: 2 additions & 2 deletions apps/consent/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { z } from "zod"
export const env = createEnv({
server: {
HYDRA_ADMIN_URL: z.string().default("http://localhost:4445"),
CORE_AUTH_URL: z.string().default("http://localhost:4002/auth"),
CORE_AUTH_URL: z.string().default("http://localhost:4455/auth"),
},
shared: {
GRAPHQL_ENDPOINT: z.string().default("http://localhost:4002/graphql"),
GRAPHQL_ENDPOINT: z.string().default("http://localhost:4455/graphql"),
},
runtimeEnv: {
CORE_AUTH_URL: process.env.CORE_AUTH_URL,
Expand Down
Empty file removed dev/.env
Empty file.
80 changes: 70 additions & 10 deletions dev/Tiltfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
is_ci=sys.argv[1] == "ci"

config.define_string_list("test")
cfg = config.parse()

groups = {
"auth": [
"oathkeeper",
Expand Down Expand Up @@ -25,6 +30,57 @@ groups = {
],
}

consent_test_target = "//apps/consent:cypress"
local_resource(
"consent-test",
labels = ["test"],
auto_init = is_ci and "consent" in cfg.get("test", []),
cmd = "buck2 test {}".format(consent_test_target),
resource_deps = [
"consent",
"init-test-user",
"hydra-consent"
],
)

local_resource(
name='init-test-user',
labels = ['test'],
cmd='bin/init-user.sh',
resource_deps = [
"oathkeeper",
"kratos",
"api",
]
)

consent_target = "//apps/consent:dev"
if is_ci:
consent_target = '//apps/consent:consent'
local_resource(
"consent",
labels = ["auth"],
cmd = "buck2 build {}".format(consent_target),
serve_cmd = "buck2 run {}".format(consent_target),
resource_deps = [
"apollo-router",
"hydra",
"api",
],
links = [
link("http://localhost:3000", "consent"),
],
)

local_resource(
name='hydra-consent',
labels = ['auth'],
cmd=['bin/setup-hydra-client.sh', 'consent', 'http://localhost:3000'],
resource_deps = [
"hydra",
]
)

api_target = "//core/api:api"
local_resource(
"api",
Expand All @@ -51,6 +107,10 @@ local_resource(
"REDIS_0_DNS": "localhost",
"REDIS_0_PORT": "6379",
"REDIS_TYPE": "standalone",
"UNSECURE_IP_FROM_REQUEST_OBJECT": "true",
"UNSECURE_DEFAULT_LOGIN_CODE": "000000",
"GEETEST_ID": "geetest_id",
"GEETEST_KEY": "geetest_key"
},
allow_parallel = True,
readiness_probe = probe(
Expand All @@ -66,6 +126,16 @@ local_resource(
]
)

local_resource(
name='init-onchain',
labels = ['bitcoin'],
cmd='bin/init-onchain.sh',
resource_deps = [
"bitcoind",
"bria",
]
)

docker_compose("./docker-compose.deps.yml", project_name = "galoy-dev")

for service in groups["bitcoin"]:
Expand All @@ -76,13 +146,3 @@ for service in groups["core"]:
dc_resource(service, labels = ["core"])
for service in groups["auth"]:
dc_resource(service, labels = ["auth"])

local_resource(
name='init-onchain',
labels = ['bitcoin'],
cmd='bin/init-onchain.sh',
resource_deps = [
"bitcoind",
"bria",
]
)
4 changes: 2 additions & 2 deletions dev/bin/init-onchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${DIR}/helpers.sh"
DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/cli.sh"

echo "Seeding some regtest blocks..."

Expand Down
16 changes: 16 additions & 0 deletions dev/bin/init-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

set -x

DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/auth.sh"
source "${DEV_DIR}/helpers/gql.sh"

user_phone="+16505554350"
email="test@galoy.com"

auth_token="$(login_user "${user_phone}")"

register_email_to_user "${auth_token}" "${email}"
34 changes: 34 additions & 0 deletions dev/bin/setup-hydra-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -e

DEV_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
source "${DEV_DIR}/helpers/cli.sh"

hydra_client_name="${1}"
redirect_uri="${2}"

HYDRA_CLIENT_JSON="${DEV_DIR}/../.${hydra_client_name}-hydra-client.json"
HYDRA_CLIENT_ENV="${DEV_DIR}/../.${hydra_client_name}-hydra-client.env"
HYDRA_ADMIN_API="http://localhost:4445"
HYDRA_PUBLIC_API="http://localhost:4444"

hydra_cli create client \
--endpoint "${HYDRA_ADMIN_API}" \
--grant-type authorization_code,refresh_token \
--response-type code,id_token \
--format json \
--scope offline --scope transactions:read --scope payments:send \
--redirect-uri "$redirect_uri" > "${HYDRA_CLIENT_JSON}"

CLIENT_ID=$(jq -r '.client_id' < "${HYDRA_CLIENT_JSON}")
CLIENT_SECRET=$(jq -r '.client_secret' < "${HYDRA_CLIENT_JSON}")

AUTHORIZATION_URL="${HYDRA_PUBLIC_API}/oauth2/auth?client_id=$CLIENT_ID&scope=offline%20transactions:read&response_type=code&redirect_uri=$redirect_uri&state=kfISr3GhH0rqheByU6A6hqIG_f14pCGkZLSCUTHnvlI"

echo "export CLIENT_ID=$CLIENT_ID" > "${HYDRA_CLIENT_ENV}"
echo "export CLIENT_SECRET=$CLIENT_SECRET" >> "${HYDRA_CLIENT_ENV}"
echo "export AUTHORIZATION_URL=$AUTHORIZATION_URL" >> "${HYDRA_CLIENT_ENV}"

mkdir -p "${DEV_DIR}/.envs"
cp "${HYDRA_CLIENT_ENV}" "${DEV_DIR}/.envs/${hydra_client_name}.env"
8 changes: 4 additions & 4 deletions dev/config/ory/hydra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ serve:

urls:
self:
issuer: http://127.0.0.1:4444
consent: http://127.0.0.1:3000/consent
login: http://127.0.0.1:3000/login
logout: http://127.0.0.1:3000/logout
issuer: http://localhost:4444
consent: http://localhost:3000/consent
login: http://localhost:3000/login
logout: http://localhost:3000/logout

secrets:
system:
Expand Down
2 changes: 2 additions & 0 deletions dev/docker-compose.deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ services:
image: ghcr.io/apollographql/router:v1.25.0
ports:
- 4004:4004
extra_hosts:
- "bats-tests:host-gateway"
environment:
- APOLLO_ROUTER_SUPERGRAPH_PATH=/repo/dev/apollo-federation/supergraph.graphql
- APOLLO_ROUTER_CONFIG_PATH=/repo/dev/apollo-federation/router.yaml
Expand Down
Loading

0 comments on commit d9b0bcd

Please sign in to comment.